Пример #1
0
def test_cookies4():
    """Test to make sure cookies are saved when user-specified cookie is added"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org","cookie":"XYZ=123"})
    http_ua.send_request(x)
    assert('XYZ' in http_ua.request_object.headers["cookie"])
Пример #2
0
def test_cookies3():
    """Test to make sure we retain cookies when user specified values are provided"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org","cookie":"TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa; XYZ=123"})
    http_ua.send_request(x)
    assert(set([chunk.split('=')[0].strip() for chunk in http_ua.request_object.headers["cookie"].split(';')]) == set(['XYZ', 'TS01293935']))
Пример #3
0
def test_cookies2():
    """Test to make sure that we don't override user specified cookies"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",headers={"Host":"ieee.org","cookie":"TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa"})    
    http_ua.send_request(x)
    assert('TS01293935=012f3506234413e6c5cb14e8c0d5bf890fdd02481614b01cd6cd30911c6733e3e6f79e72aa' in http_ua.request_object.headers["cookie"])
Пример #4
0
def test_input():
    input_1 = ruleset.Input()
    assert (input_1.uri == '/')
    headers = {'Host': 'domain.com', 'User-Agent': 'Zack'}
    dictionary = {}
    dictionary['headers'] = headers
    input_2 = ruleset.Input(**dictionary)
    assert (len(input_2.headers.keys()) == 2)
    dictionary_2 = {'random_key': 'bar'}
    with pytest.raises(TypeError) as excinfo:
        input_3 = ruleset.Input(**dictionary_2)
Пример #5
0
def test_cookies1():
    """Tests accessing a site that sets a cookie and then wants to resend the cookie"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org", headers={"Host": "ieee.org"})
    http_ua.send_request(x)
    with pytest.raises(KeyError):
        print http_ua.request_object.headers["cookie"]
    x = ruleset.Input(dest_addr="ieee.org", headers={"Host": "ieee.org"})
    http_ua.send_request(x)
    assert (
        http_ua.request_object.headers["cookie"].split('=')[0] == "TS01293935")
Пример #6
0
def test_cookies1():
    """Tests accessing a site that sets a cookie and then wants to resend the cookie"""
    http_ua = http.HttpUA()
    x = ruleset.Input(protocol="https",port=443,dest_addr="www.ieee.org",headers={"Host":"www.ieee.org"})
    http_ua.send_request(x)
    with pytest.raises(KeyError):
        print(http_ua.request_object.headers["cookie"])
    assert("set-cookie" in http_ua.response_object.headers.keys())
    cookie_data = http_ua.response_object.headers["set-cookie"]
    cookie_var = cookie_data.split("=")[0]
    x = ruleset.Input(protocol="https",port=443,dest_addr="www.ieee.org",headers={"Host":"www.ieee.org"})
    http_ua.send_request(x)
    assert(http_ua.request_object.headers["cookie"].split('=')[0] == cookie_var)
Пример #7
0
def test_cookies4():
    """Test to make sure cookies are saved when user-specified cookie is added"""
    http_ua = http.HttpUA()
    x = ruleset.Input(dest_addr="ieee.org", headers={"Host": "ieee.org"})
    http_ua.send_request(x)
    x = ruleset.Input(dest_addr="ieee.org",
                      headers={
                          "Host": "ieee.org",
                          "cookie": "XYZ=123"
                      })
    http_ua.send_request(x)
    assert ([
        chunk.split('=')[0].strip()
        for chunk in http_ua.request_object.headers["cookie"].split(';')
    ] == ['XYZ', 'TS01293935'])
Пример #8
0
def test_search3():
    runner = testrunner.TestRunner()
    x = ruleset.Input(dest_addr="example.com", headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    runner.test_response(http_ua.response_object,
                         re.compile('established to be used for'))
Пример #9
0
def test_search2():
    runner = testrunner.TestRunner()
    x = ruleset.Input(dest_addr="example.com", headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    with pytest.raises(AssertionError):
        runner.test_response(http_ua.response_object, re.compile('dog'))
Пример #10
0
def test_raw1():
    """Test to make sure a raw request will work with \r\n replacement"""
    x = ruleset.Input(
        dest_addr="example.com",
        raw_request="""GET / HTTP/1.1\r\nHost: example.com\r\n\r\n""")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #11
0
def test4():
    """Basic GET wit Host on 1.0 - Expect 200"""
    x = ruleset.Input(dest_addr="example.com",
                      version="HTTP/1.0",
                      headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #12
0
def test_error2():
    """Invalid request should cause timeout"""
    x = ruleset.Input(dest_addr="example.com",
                      port=123,
                      headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    with pytest.raises(errors.TestError):
        http_ua.send_request(x)
Пример #13
0
def test_error1():
    """Will return mail -- not header should cause error"""
    x = ruleset.Input(dest_addr="Smtp.aol.com",
                      port=25,
                      headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    with pytest.raises(errors.TestError):
        http_ua.send_request(x)
Пример #14
0
def test13():
    """Request https on port 80 (default)"""
    x = ruleset.Input(protocol="https",
                      dest_addr="example.com",
                      headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    with pytest.raises(errors.TestError):
        http_ua.send_request(x)
Пример #15
0
def test6():
    """Basic GET without Host with invalid version (request line) - Expect 505 not supported"""
    x = ruleset.Input(dest_addr="example.com",
                      version="HTTP/1.0 x",
                      headers={})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 505
Пример #16
0
def test11():
    """POST method no data - Expect 411"""
    x = ruleset.Input(method="POST",
                      dest_addr="example.com",
                      version="HTTP/1.0",
                      headers={})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 411
Пример #17
0
def test10():
    """HEAD method - Expect 200"""
    x = ruleset.Input(method="HEAD",
                      dest_addr="example.com",
                      version="HTTP/1.0",
                      headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #18
0
def test7():
    """TEST method which doesn't exist - Expect 501"""
    x = ruleset.Input(method="TEST",
                      dest_addr="example.com",
                      version="HTTP/1.0",
                      headers={})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 501
Пример #19
0
def test20():
    """Accept-Encoding deflate"""
    x = ruleset.Input(dest_addr="example.com", version="HTTP/1.0",
                      headers={"Host": "example.com",
                               "Accept-Encoding": "deflate"})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
    assert http_ua.response_object.headers["content-encoding"] == "deflate"
Пример #20
0
def test_encoded1():
    """Test to make sure a encode request works"""
    x = ruleset.Input(
        dest_addr="example.com",
        encoded_request=
        "R0VUIC8gSFRUUC8xLjFcclxuSG9zdDogZXhhbXBsZS5jb21cclxuXHJcbg==")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #21
0
def test8():
    """PROPFIND method which isn't allowed - Expect 405"""
    x = ruleset.Input(method="PROPFIND",
                      dest_addr="example.com",
                      version="HTTP/1.0",
                      headers={})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 405
Пример #22
0
def test_both1():
    """Test to make sure that if both encoded and raw are provided there is an error"""
    x = ruleset.Input(
        dest_addr="example.com",
        raw_request="""GET / HTTP/1.1\r\nHost: example.com\r\n\r\n""",
        encoded_request="abc123==")
    http_ua = http.HttpUA()
    with pytest.raises(errors.TestError):
        http_ua.send_request(x)
Пример #23
0
def test14():
    """Request https on port 443 should work"""
    x = ruleset.Input(protocol="https",
                      port=443,
                      dest_addr="example.com",
                      headers={"Host": "example.com"})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #24
0
def test_raw2():
    """Test to make sure a raw request will work with actual seperators"""
    x = ruleset.Input(dest_addr="example.com",raw_request="""GET / HTTP/1.1
Host: example.com
    

""")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200    
Пример #25
0
def test19():
    """Send a raw question mark and test it is encoded automagically"""
    x = ruleset.Input(method="POST",
                      protocol="http",
                      port=80,
                      uri="/",
                      dest_addr="example.com",
                      headers={"Host": "example.com"},
                      data="test=hello?x")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.request_object.data == "test=hello%3Fx"
Пример #26
0
def test18():
    """Send a request and check that the space is encoded automagically"""
    x = ruleset.Input(method="POST",
                      protocol="http",
                      port=80,
                      uri="/",
                      dest_addr="example.com",
                      headers={"Host": "example.com"},
                      data="test=hit f&test2=hello")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.request_object.data == "test=hit+f&test2=hello"
Пример #27
0
def test17():
    """Post request with no content-type AND no content-length"""
    x = ruleset.Input(method="POST",
                      protocol="http",
                      port=80,
                      uri="/",
                      dest_addr="example.com",
                      headers={"Host": "example.com"},
                      data="test=hi")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #28
0
def test12():
    """POST method no data with content length header - Expect 200"""
    x = ruleset.Input(method="POST",
                      dest_addr="example.com",
                      version="HTTP/1.0",
                      headers={
                          "Content-Length": "0",
                          "Host": "example.com"
                      },
                      data="")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #29
0
def test16():
    """Post request with content-type but not content-length"""
    x = ruleset.Input(method="POST",
                      protocol="http",
                      port=80,
                      dest_addr="example.com",
                      headers={
                          "Content-Type": "application/x-www-form-urlencoded",
                          "Host": "example.com"
                      },
                      data="test=hi")
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 200
Пример #30
0
def test5():
    """Basic GET without Host on 0.9 - Expect 505 version not supported"""
    x = ruleset.Input(dest_addr="example.com", version="HTTP/0.9", headers={})
    http_ua = http.HttpUA()
    http_ua.send_request(x)
    assert http_ua.response_object.status == 505