async def test_on_request_successful_reject_request_if_hash_and_code_dont_match_and_content_type_is_not_set( self): expected_hash = hash_data(b"expected page", "sha256") expected_status_code = 200 response = StaticResponse(200, headers={"content-type": "text/html"}, content="page not found") arguments = { "expected_hash": expected_hash, "expected_status_code": expected_status_code, "hash_algo": "sha256" } entry = self.create_redirect("http://example.com/", final_response=response, arguments=arguments) await self.process_request(entry) with self.assertRaises(RejectRequest): await self.reject_response.on_request_successful(entry)
async def test_on_request_successful_accept_request_if_code_and_content_type_match_and_content_type_is_html( self): expected_hash = hash_data(b"expected page", "sha256") expected_status_code = 200 expected_mime_type = "text/html" response = StaticResponse(200, headers={"content-type": "text/html"}, content="page not found") arguments = { "expected_hash": expected_hash, "expected_mime_type": expected_mime_type, "expected_status_code": expected_status_code, "hash_algo": "sha256" } entry = Entry.create("http://example.com/", response=response, arguments=arguments) await self.process_request(entry) await self.reject_response.on_request_successful(entry)
async def test_on_request_successful_accept_request_if_response_hash_matches_expected_hash( self): content = "data" expected_hash = hash_data(content.encode(), "sha256") expected_status_code = 200 expected_mime_type = "text/html" response = StaticResponse( 200, headers={"content-type": "application/javascript"}, content=content) arguments = { "expected_hash": expected_hash, "expected_mime_type": expected_mime_type, "expected_status_code": expected_status_code, "hash_algo": "sha256" } entry = self.create_redirect("http://example.com/", final_response=response, arguments=arguments) await self.process_request(entry) await self.reject_response.on_request_successful(entry)
async def test_on_request_successful_accept_request_if_response_matches_all_of_the_expectations( self): content = "image data" expected_hash = hash_data(content.encode(), "sha256") expected_hash = {"123", "456", expected_hash} expected_status_code = 200 expected_mime_type = "image/png" response = StaticResponse(200, headers={"content-type": "image/png"}, content=content) arguments = { "expected_hash": expected_hash, "expected_mime_type": expected_mime_type, "expected_status_code": expected_status_code, "hash_algo": "sha256" } entry = Entry.create("http://example.com/", response=response, arguments=arguments) await self.process_request(entry) await self.reject_response.on_request_successful(entry)