ranger/orm/tests/unit/common/test_security_headers_hook.py
Nicholas Jones 20aa6dcdba Move all common tests to top level folder
Moves all tests under orm/common to the top level tests folder
and makes minimal necessary changes to get them working.

Change-Id: Ib813d130ac5a2b3e2205c3a0d9cbeff46359ced1
2017-08-15 08:21:09 -05:00

33 lines
1.1 KiB
Python
Executable File

from unittest import TestCase
import mock
from orm.common.orm_common.hooks import security_headers_hook
class MyHeaders(object):
def __init__(self):
self.headers = {}
def add(self, key, value):
self.headers[key] = value
class TestSecurityHeadersHook(TestCase):
def test_after(self):
s = security_headers_hook.SecurityHeadersHook()
test_headers = MyHeaders()
state = mock.MagicMock()
state.response.headers = test_headers
s.after(state)
security_headers = {'X-Frame-Options': 'DENY',
'X-Content-Type-Options': 'nosniff',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'Content-Security-Policy': 'default-src \'self\'',
'X-Permitted-Cross-Domain-Policies': 'none',
'X-XSS-Protection': '1; mode=block'}
for header in security_headers:
self.assertEqual(security_headers[header],
test_headers.headers[header])