def test_headers_access_gets_a_value(): headers = BaseHeaders(b"Foo: Bar") expected = b"Bar" actual = headers[b'Foo'] assert actual == expected
def test_headers_dont_unicodify_cookie(): headers = BaseHeaders(b"Cookie: somecookiedata") expected = b"somecookiedata" actual = headers[b'Cookie'] assert actual == expected
def test_baseheaders_loads_cookies_as_str(): headers = BaseHeaders(b"Cookie: key=value") assert headers.cookie[str('key')].value == str('value')
def test_headers_access_gets_last_value(): headers = BaseHeaders([(b"Foo", b"Bar"), (b"Foo", b"Baz")]) expected = b"Baz" actual = headers[b'Foo'] assert actual == expected
def test_headers_access_is_case_insensitive(): headers = BaseHeaders(b"Foo: Bar") expected = b"Bar" actual = headers[b'foo'] assert actual == expected
def test_headers_reject_CR_injection_from_add(): with raises(CRLFInjection): BaseHeaders().add(b'foo', b'\rbar')
def test_headers_reject_LF_injection(): with raises(CRLFInjection): BaseHeaders()[b'foo'] = b'\nbar'
def test_headers_can_be_raw_when_non_ascii(): headers = BaseHeaders({b'Foo': b'b\xc3\xabar', b'Oh': b'Yeah!'}) assert headers.raw == b'Foo: b\xc3\xabar\r\nOh: Yeah!'
def test_headers_reject_CR_injection(): with raises(CRLFInjection): BaseHeaders(b'')[b'foo'] = b'\rbar'
def test_headers_can_be_raw_when_non_ascii(): headers = BaseHeaders(b'Foo: b\xc3\xabar\r\nOh: Yeah!') assert headers.raw == b'Foo: b\xc3\xabar\r\nOh: Yeah!'