Skip to content

Commit

Permalink
constant values for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juerkkil committed Dec 26, 2024
1 parent 36290fc commit f7f4170
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
13 changes: 13 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Expected structure for parsed security headers when following headers are returned:
# X-XSS-Protection: 1;
# Server: nginx
EXAMPLE_HEADERS = {
'x-frame-options': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'strict-transport-security': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'content-security-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'x-content-type-options': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'x-xss-protection': {'defined': True, 'warn': True, 'contents': '1;', 'notes': []},
'referrer-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'permissions-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'server': {'defined': True, 'warn': False, 'contents': 'nginx', 'notes': []},
}
17 changes: 2 additions & 15 deletions tests/test_cmd_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import mock, TestCase
from secheaders import cmd_utils
from secheaders.constants import WARN_COLOR, OK_COLOR, END_COLOR
from .constants import EXAMPLE_HEADERS

from .mock_classes import MockHTTPSConnection

Expand All @@ -15,26 +16,12 @@ def test_get_eval_output(self) -> None:
assert cmd_utils.get_eval_output(False, False) == f"[ {OK_COLOR}OK{END_COLOR} ]"

def test_cmd_output(self) -> None:
example_headers = {
'server': 'nginx',
'x-xss-protection': '1;',
}
example_headers = {
'x-frame-options': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'strict-transport-security': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'content-security-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'x-content-type-options': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'x-xss-protection': {'defined': True, 'warn': True, 'contents': '1;', 'notes': []},
'referrer-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'permissions-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'server': {'defined': True, 'warn': False, 'contents': 'nginx', 'notes': []},
}
example_https = {
'supported': True,
'certvalid': True,
'redirect': False,
}
res = cmd_utils.output_text("example.com", example_headers, example_https, verbose=True, no_color=False)
res = cmd_utils.output_text("example.com", EXAMPLE_HEADERS, example_https, verbose=True, no_color=False)
assert "HTTPS supported" in res
assert "Scanning target example.com ..." in res
assert "Header 'x-frame-options' is missing" in res
Expand Down
14 changes: 2 additions & 12 deletions tests/test_securityheaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from urllib.parse import ParseResult

from secheaders.securityheaders import SecurityHeaders
from tests.constants import EXAMPLE_HEADERS

from .mock_classes import MockHTTPSConnection

Expand All @@ -25,17 +26,6 @@ def test_fetch_headers(self) -> None:

def test_eval_headers(self) -> None:
secheaders = SecurityHeaders("https://www.example.com", 0)
expected_value = {
'x-frame-options': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'strict-transport-security': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'content-security-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'x-content-type-options': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'x-xss-protection': {'defined': True, 'warn': True, 'contents': '1;', 'notes': []},
'referrer-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'permissions-policy': {'defined': False, 'warn': True, 'contents': None, 'notes': []},
'server': {'defined': True, 'warn': False, 'contents': 'nginx', 'notes': []},
}

secheaders.fetch_headers()
res = secheaders.check_headers()
assert res == expected_value
assert res == EXAMPLE_HEADERS

0 comments on commit f7f4170

Please sign in to comment.