diff options
Diffstat (limited to 'service/test')
-rw-r--r-- | service/test/integration/test_retrieve_attachment.py | 10 | ||||
-rw-r--r-- | service/test/support/test_helper.py | 6 | ||||
-rw-r--r-- | service/test/unit/config/test_site.py | 21 | ||||
-rw-r--r-- | service/test/unit/resources/test_attachments_resource.py | 4 | ||||
-rw-r--r-- | service/test/unit/resources/test_root_resource.py | 4 | ||||
-rw-r--r-- | service/test/unit/resources/test_sandbox_resource.py | 6 |
6 files changed, 25 insertions, 26 deletions
diff --git a/service/test/integration/test_retrieve_attachment.py b/service/test/integration/test_retrieve_attachment.py index 31c8c5df..eaf1d36c 100644 --- a/service/test/integration/test_retrieve_attachment.py +++ b/service/test/integration/test_retrieve_attachment.py @@ -40,8 +40,8 @@ class RetrieveAttachmentTest(SoledadTestBase): self.assertEqual(200, req.code) self.assertEquals('pretend to be binary attachment data', attachment) - self.assertEquals(expected_content_disposition, req.outgoingHeaders['content-disposition']) - self.assertEquals(expected_content_type, req.outgoingHeaders['content-type']) + self.assertEquals(expected_content_disposition, req.responseHeaders.getRawHeaders('content-disposition')[0]) + self.assertEquals(expected_content_type, req.responseHeaders.getRawHeaders('content-type')[0]) @defer.inlineCallbacks def test_should_retrieve_attachment_even_if_xsrf_token_not_passed(self): @@ -57,8 +57,8 @@ class RetrieveAttachmentTest(SoledadTestBase): self.assertEqual(200, req.code) self.assertEquals('pretend to be binary attachment data', attachment) - self.assertEquals(expected_content_disposition, req.outgoingHeaders['content-disposition']) - self.assertEquals(expected_content_type, req.outgoingHeaders['content-type']) + self.assertEquals(expected_content_disposition, req.responseHeaders.getRawHeaders('content-disposition')[0]) + self.assertEquals(expected_content_type, req.responseHeaders.getRawHeaders('content-type')[0]) def _create_mail_with_attachment(self): input_mail = MIMEMultipart() @@ -89,7 +89,7 @@ class RetrieveAttachmentTest(SoledadTestBase): _, req = yield self.post_attachment(post_data, headers) self.assertEqual(201, req.code) - self.assertEqual('/attachment/B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A', req.headers['Location']) + self.assertEqual('/attachment/B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A', req.responseHeaders.getRawHeaders('location')[0]) response_json = {'ident': 'B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A', 'content-type': content_type, 'name': filename, diff --git a/service/test/support/test_helper.py b/service/test/support/test_helper.py index 640baf6f..ebe8a897 100644 --- a/service/test/support/test_helper.py +++ b/service/test/support/test_helper.py @@ -108,7 +108,7 @@ class PixRequestMock(DummyRequest): def request_mock(path='', method='GET', body='', headers={}, ajax=True, csrf='token'): dummy = PixRequestMock(path.split('/')) for name, val in headers.iteritems(): - dummy.headers[name.lower()] = val + dummy.requestHeaders.setRawHeaders(name.lower(), [val]) dummy.method = method if isinstance(body, str): dummy.content = io.BytesIO(body) @@ -116,8 +116,8 @@ def request_mock(path='', method='GET', body='', headers={}, ajax=True, csrf='to for key, val in body.items(): dummy.addArg(key, val) if ajax: - dummy.headers['x-requested-with'] = 'XMLHttpRequest' - dummy.headers['x-xsrf-token'] = csrf + dummy.requestHeaders.setRawHeaders('x-requested-with', ['XMLHttpRequest']) + dummy.requestHeaders.setRawHeaders('x-xsrf-token', [csrf]) dummy.addCookie('XSRF-TOKEN', csrf) return dummy diff --git a/service/test/unit/config/test_site.py b/service/test/unit/config/test_site.py index 7c381449..b8b23ef0 100644 --- a/service/test/unit/config/test_site.py +++ b/service/test/unit/config/test_site.py @@ -8,15 +8,15 @@ class TestPixelatedSite(unittest.TestCase): def test_add_security_headers(self): request = self.create_request() request.process() - headers = request.headers header_value = "default-src 'self'; style-src 'self' 'unsafe-inline'" - self.assertEqual(headers.get('Content-Security-Policy'), header_value) - self.assertEqual(headers.get('X-Content-Security-Policy'), header_value) - self.assertEqual(headers.get('X-Webkit-CSP'), header_value) - self.assertEqual(headers.get('X-Frame-Options'), 'SAMEORIGIN') - self.assertEqual(headers.get('X-XSS-Protection'), '1; mode=block') - self.assertEqual(headers.get('X-Content-Type-Options'), 'nosniff') + self.assertEquals(header_value, request.responseHeaders.getRawHeaders('X-Content-Security-Policy'.lower())[0]) + self.assertEquals(header_value, request.responseHeaders.getRawHeaders('Content-Security-Policy'.lower())[0]) + self.assertEquals(header_value, request.responseHeaders.getRawHeaders('X-Webkit-CSP'.lower())[0]) + + self.assertEqual('SAMEORIGIN', request.responseHeaders.getRawHeaders('X-Frame-Options'.lower())[0]) + self.assertEqual('1; mode=block', request.responseHeaders.getRawHeaders('X-XSS-Protection'.lower())[0]) + self.assertEqual('nosniff', request.responseHeaders.getRawHeaders('X-Content-Type-Options'.lower())[0]) def test_add_strict_transport_security_header_if_secure(self): request = self.create_request() @@ -24,16 +24,15 @@ class TestPixelatedSite(unittest.TestCase): request.process() - headers = request.headers - self.assertEqual('max-age=31536000; includeSubDomains', headers.get('Strict-Transport-Security')) + self.assertTrue(request.responseHeaders.hasHeader('Strict-Transport-Security'.lower())) + self.assertEqual('max-age=31536000; includeSubDomains', request.responseHeaders.getRawHeaders('Strict-Transport-Security'.lower())[0]) def test_does_not_add_strict_transport_security_header_if_plain_http(self): request = self.create_request() request.process() - headers = request.headers - self.assertFalse('Strict-Transport-Security' in headers) + self.assertFalse(request.responseHeaders.hasHeader('Strict-Transport-Security'.lower())) def create_request(self): channel = LineReceiver() diff --git a/service/test/unit/resources/test_attachments_resource.py b/service/test/unit/resources/test_attachments_resource.py index 2aeeb01e..0424c481 100644 --- a/service/test/unit/resources/test_attachments_resource.py +++ b/service/test/unit/resources/test_attachments_resource.py @@ -47,7 +47,7 @@ class AttachmentsResourceTest(unittest.TestCase): def assert_response(_): self.assertEqual(201, request.code) - self.assertEqual('/attachment/%s' % attachment_id, request.headers['Location']) + self.assertEqual('/attachment/%s' % attachment_id, request.responseHeaders.getRawHeaders("location")[0]) response_json = {'ident': attachment_id, 'content-type': 'some mocked type', 'name': 'filename.txt', 'size': 17, 'encoding': 'base64'} self.assertEqual(response_json, json.loads(request.written[0])) @@ -72,7 +72,7 @@ class AttachmentsResourceTest(unittest.TestCase): def assert_response(_): self.assertEqual(500, request.code) - self.assertFalse('Location' in request.headers) + self.assertFalse(request.responseHeaders.hasHeader('Location'.lower())) self.assertIn("message", json.loads(request.written[0])) verify(self.mail_service).save_attachment('some mocked value', 'some mocked type') diff --git a/service/test/unit/resources/test_root_resource.py b/service/test/unit/resources/test_root_resource.py index cc052d8b..f2d7a951 100644 --- a/service/test/unit/resources/test_root_resource.py +++ b/service/test/unit/resources/test_root_resource.py @@ -69,8 +69,8 @@ class TestRootResource(unittest.TestCase): self._test_should_renew_xsrf_cookie() def _mock_ajax_csrf(self, request, csrf_token): - request.headers['x-requested-with'] = 'XMLHttpRequest' - request.headers['x-xsrf-token'] = csrf_token + request.requestHeaders.setRawHeaders('x-requested-with', ['XMLHttpRequest']) + request.requestHeaders.setRawHeaders('x-xsrf-token', [csrf_token]) def test_should_unauthorize_child_resource_ajax_requests_when_csrf_mismatch(self): request = DummyRequest(['/child']) diff --git a/service/test/unit/resources/test_sandbox_resource.py b/service/test/unit/resources/test_sandbox_resource.py index 3db43e12..98b88b2d 100644 --- a/service/test/unit/resources/test_sandbox_resource.py +++ b/service/test/unit/resources/test_sandbox_resource.py @@ -33,6 +33,6 @@ class TestSandBoxResource(unittest.TestCase): yield self.web.get(request) - self.assertEquals(expected_csp_headers, request.outgoingHeaders.get('X-Content-Security-Policy'.lower())) - self.assertEquals(expected_csp_headers, request.outgoingHeaders.get('Content-Security-Policy'.lower())) - self.assertEquals(expected_csp_headers, request.outgoingHeaders.get('X-Webkit-CSP'.lower())) + self.assertEquals(expected_csp_headers, request.responseHeaders.getRawHeaders('X-Content-Security-Policy'.lower())[0]) + self.assertEquals(expected_csp_headers, request.responseHeaders.getRawHeaders('Content-Security-Policy'.lower())[0]) + self.assertEquals(expected_csp_headers, request.responseHeaders.getRawHeaders('X-Webkit-CSP'.lower())[0]) |