Beispiel #1
0
def test_malformed_request_line(input_bytes):
    try:
        HTTPMessageParser.from_bytes(input_bytes)
    except MalformedRequestError:
        pass
    else:
        assert False, "Request is malformed, exception not raised."  # pragma: no cover
Beispiel #2
0
def test_short_read_http_headers():
    input_bytes = b'GET / HTTP/1.1\r\nHea'
    try:
        HTTPMessageParser.from_bytes(input_bytes)
    except MalformedRequestError:
        pass
    else:  # pragma: no cover
        assert False
def test_youtube_for_schools():
    request = HTTPMessageParser.from_bytes(b"GET http://youtube.com.com/?qq=foo HTTP/1.1\r\n\r\n")
    print(youtube_for_schools.YouTubeForSchools)
    youtube_for_schools.EDUCATION_ID = 'foo bar baz'
    youtube_for_schools.YouTubeForSchools().reqmod(request)
    print(bytes(request))
    assert b"X-YouTube-Edu-Filter: foo bar baz" in bytes(request)
Beispiel #4
0
def test_youtube_for_schools():
    request = HTTPMessageParser.from_bytes(
        b"GET http://youtube.com.com/?qq=foo HTTP/1.1\r\n\r\n")
    print(youtube_for_schools.YouTubeForSchools)
    youtube_for_schools.EDUCATION_ID = 'foo bar baz'
    youtube_for_schools.YouTubeForSchools().reqmod(request)
    print(bytes(request))
    assert b"X-YouTube-Edu-Filter: foo bar baz" in bytes(request)
Beispiel #5
0
def test_post_data_parsing_and_serialization():
    with open('data/http_request_with_post_data.request', 'rb') as f:
        data = f.read()

    request = HTTPMessageParser.from_bytes(data)

    request.post.clear()
    request.post['foo'] = ['bar']
    request.pre_serialization()

    assert b'foo=bar' in request.body_bytes
Beispiel #6
0
def test_sline_matching(input_bytes, expected_request):
    m = HTTPMessageParser.from_bytes(input_bytes)

    if expected_request:
        m.request_line
        assert m.is_request
        assert not m.is_response
        assert isinstance(m.request_line, RequestLine)
    else:
        m.status_line
        assert m.is_response
        assert not m.is_request
        assert isinstance(m.status_line, StatusLine)
Beispiel #7
0
def test_horrible_http_parsing(input_bytes, expected_headers, expected_sline):
    m = HTTPMessageParser.from_bytes(input_bytes)

    print(bytes(m.headers))
    print(bytes(expected_headers))
    assert m.headers == expected_headers

    if m.is_request:
        assert bytes(m.request_line) == expected_sline
    elif m.is_response:
        assert bytes(m.status_line) == expected_sline
    else:
        assert False, "Not a request or response!"
Beispiel #8
0
def test_withoutmypants_modified():
    request = HTTPMessageParser.from_bytes(
        b"GET http://google.com/?q=foo HTTP/1.1\r\n\r\n")
    withoutmypants.reqmod(request)
    print(bytes(request))
    assert b"?q=foo+without+my+pants" in bytes(request)
def test_withoutmypants_modified():
    request = HTTPMessageParser.from_bytes(b"GET http://google.com/?q=foo HTTP/1.1\r\n\r\n")
    withoutmypants.reqmod(request)
    print(bytes(request))
    assert b"?q=foo+without+my+pants" in bytes(request)
Beispiel #10
0
def test_chunked_messages(input_bytes, expected_body):
    m = HTTPMessageParser.from_bytes(input_bytes)

    assert_bodies_match(m, expected_body)