blob: 4f263af12d6562cc672eaddd4865e5a52a19f0b0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import os
from twisted.trial import unittest
from twisted.internet import defer
from twisted.web.test.requesthelper import DummyRequest
from pixelated.resources.sandbox_resource import SandboxResource
from test.unit.resources import DummySite
class TestSandBoxResource(unittest.TestCase):
def setUp(self):
static_folder = os.path.dirname(os.path.abspath(__file__))
self.resource = SandboxResource(static_folder)
self.resource.isLeaf = True
self.web = DummySite(self.resource)
@defer.inlineCallbacks
def test_render_GET_should_set_sandbox_csp_header(self):
request = DummyRequest(['/sandbox'])
request.method = 'GET'
request.isSecure = lambda: True
request.redirect = lambda _: 'irrelevant'
expected_csp_headers = "sandbox allow-popups allow-scripts;" \
"default-src 'self';" \
"style-src *;" \
"script-src *;" \
"font-src *;" \
"img-src *;" \
"object-src 'none';" \
"connect-src 'none';"
yield self.web.get(request)
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])
|