Skip to content

Commit 603e3af

Browse files
committed
chore: Create tests
1 parent f3efc94 commit 603e3af

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed

poetry.lock

Lines changed: 101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ readme = "README.md"
99
[tool.poetry.dependencies]
1010
python = ">3.9"
1111

12+
[tool.poetry.group.dev.dependencies]
13+
pytest = "^7.4.3"
14+
1215
[build-system]
1316
requires = ["poetry-core"]
1417
build-backend = "poetry.core.masonry.api"

test_csp.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pytest
2+
from http_csp.csp import CSP
3+
4+
5+
def test_csp_parsing_clean():
6+
policy = CSP("base-uri self; child-src self http://localhost;")
7+
assert policy.base_uri == ["self"]
8+
assert policy.child_src == ["self", "http://localhost"]
9+
10+
11+
def test_csp_parsing_unclean():
12+
policy = CSP(" base_uri self;child_src self http://localhost ; ")
13+
assert policy.base_uri == ["self"]
14+
assert policy.child_src == ["self", "http://localhost"]
15+
16+
17+
def test_csp_parsing_error():
18+
with pytest.raises(ValueError):
19+
CSP("non-valid option")
20+
21+
22+
def test_csp_generation():
23+
policy = CSP()
24+
policy.base_uri = ["self"]
25+
policy.child_src = ["self", "http://localhost"]
26+
generated_policy = policy.generate()
27+
assert generated_policy == "base-uri self; child-src self http://localhost;"

0 commit comments

Comments
 (0)