Exemplo n.º 1
0
def test_short_read_icap_headers():
    input_bytes = b'REQMOD / ICAP/1.1\r\nHea'
    try:
        ICAPRequestParser.from_bytes(input_bytes)
    except MalformedRequestError:
        pass
    else:  # pragma: no cover
        assert False
Exemplo n.º 2
0
def test_icap_parsing_stupid(test_file, expected_values):
    '''Test for the stupidest combinations of Encapsulated headers that I can come up with.'''
    data = data_string(test_file)

    print(test_file)
    print('----')
    print(data)
    print('----')

    try:
        ICAPRequestParser.from_bytes(data)
    except ICAPAbort as e:
        assert e.status_code == 418
Exemplo n.º 3
0
def test_multiline_headers():
    s = (
        b'OPTIONS / ICAP/1.0\r\n'
        b'Great-header: foo \r\n'
        b'\t       bar\r\n'
        b'\r\n'
    )
    m = ICAPRequestParser.from_bytes(s)
    assert m.headers['great-header'] == 'foo bar'
Exemplo n.º 4
0
def test_encapsulated_header_requirement(input_bytes, expected_fail):
    try:
        m = ICAPRequestParser.from_bytes(input_bytes)
    except InvalidEncapsulatedHeadersError as e:
        if not expected_fail:
            raise e  # pragma: no cover
    else:
        if expected_fail:  # pragma: no cover
            assert False, "Did not raise an error"
Exemplo n.º 5
0
def test_icap_parsing_simple():
    expected = data_string('request_with_http_response_and_payload.request')

    m = ICAPRequestParser.from_bytes(expected)

    assert isinstance(m, ICAPRequest)

    print('-----')
    print(expected)
    print('-----')
    print('parent headers', m.headers)
    print('child headers', m.http.headers)
    assert_bodies_match(m, b'this is a payload')
Exemplo n.º 6
0
def test_icap_parsing_complex():
    'Tests req-hdr, res-hdr, res-body'

    expected = data_string('icap_request_with_two_header_sets.request')
    expected_headers = HeadersDict([
        ('Host', 'icap.example.org'),
        ('Encapsulated', 'req-hdr=0, res-hdr=137, res-body=296'),
    ])

    expected_child_request_headers = HeadersDict([
        ('Host', 'www.origin-server.com'),
        ('Accept', 'text/html, text/plain, image/gif'),
        ('Accept-Encoding', 'gzip, compress'),
    ])

    expected_child_headers = HeadersDict([
        ('Date', 'Mon, 10 Jan 2000 09:52:22 GMT'),
        ('Server', 'Apache/1.3.6 (Unix)'),
        ('ETag', '"63840-1ab7-378d415b"'),
        ('Content-Type', 'text/html'),
        ('Content-Length', '51'),
    ])

    m = ICAPRequestParser.from_bytes(expected)

    assert isinstance(m, ICAPRequest)

    child = m.http

    assert bytes(m.request_line) == b'RESPMOD icap://icap.example.org/respmod ICAP/1.0'
    assert bytes(child.request_line) == b'GET /origin-resource HTTP/1.1'
    assert bytes(child.status_line) == b'HTTP/1.1 200 OK'

    assert m.headers == expected_headers
    assert child.request_headers == expected_child_request_headers
    assert child.headers == expected_child_headers

    assert_bodies_match(m, b'This is data that was returned by an origin server.')