diff --git a/pyproject.toml b/pyproject.toml index e502f913..54cfcf15 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,9 +43,12 @@ mkdocs-material = "^9.5.29" [tool.poetry.group.tests.dependencies] pytest = "^8.3.1" -pytest-asyncio = "^0.23.8" +pytest-asyncio = "^0.24.0" pytest-md-report = "^0.6.2" +[tool.pytest] +asyncio_mode = "auto" + [tool.isort] profile = "black" diff --git a/tests/auth/__init__.py b/tests/auth/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/auth/test_permissions.py b/tests/auth/test_permissions.py new file mode 100644 index 00000000..fac70fcb --- /dev/null +++ b/tests/auth/test_permissions.py @@ -0,0 +1,51 @@ +from goosebit.auth import compare_permission, compare_permissions + + +def test_compare_single_permission(): + assert compare_permission("home.read", "home.read") + + +def test_compare_inverted_single_permission(): + assert not compare_permission("home.read", "!home.read") + + +def test_compare_wildcard_sub_permission(): + assert compare_permission("home.read", "home.*") + + +def test_compare_inverted_wildcard_sub_permission(): + assert not compare_permission("home.read", "!home.*") + + +def test_compare_root_permission(): + assert compare_permission("home.read", "home") + + +def test_compare_inverted_root_permission(): + assert not compare_permission("home.read", "!home") + + +def test_compare_root_wildcard_permission(): + assert compare_permission("home.read", "*") + + +def test_compare_inverted_root_wildcard_permission(): + assert not compare_permission("home.read", "!*") + + +def test_compare_multiple_single_permissions(): + assert compare_permissions(["home.read", "device.write"], ["home.read", "device.write"]) + + +def test_compare_invalid_multiple_single_permissions(): + assert not compare_permissions(["home.read", "device.write"], ["home.read", "device.read"]) + + +def test_compare_inverted_multiple_permissions(): + assert not compare_permissions(["home.read", "device.write"], ["home.read", "device", "!device.write"]) + + +def test_compare_multiple_root_wildcard_permissions(): + assert compare_permissions( + ["home.read", "device.write", "device.read", "software.read"], ["*.read", "device.write"] + )