Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /mardiros_fastlife /tests /unittests /security /test_policy.py
| from typing import Any | |
| from uuid import UUID | |
| import pytest | |
| from fastapi import Request as FastApiRequest | |
| from fastlife import Allowed, Denied, HasPermission, Unauthenticated | |
| from tests.fastlife_app.config import I18nRequest, MyRequest | |
| from tests.fastlife_app.domain.model import AuthnToken | |
| from tests.fastlife_app.views.api.security import MyRegistry | |
| from tests.fastlife_app.views.app.admin.security import SecurityPolicy | |
| def dummy_request( | |
| session: dict[str, Any], dummy_registry: MyRegistry | |
| ) -> I18nRequest[Any, Any, Any]: | |
| scope: dict[str, Any] = { | |
| "type": "http", | |
| "headers": [("user-agent", "Mozilla/5.0"), ("accept", "text/html")], | |
| "query_string": b"", | |
| "scheme": "http", | |
| "server": ("testserver", 80), | |
| "path": "/", | |
| "session": session, | |
| } | |
| req = I18nRequest[Any, Any, Any](dummy_registry, FastApiRequest(scope)) | |
| return req | |
| def test_has_permission_as_bool(has_permission: HasPermission, expected: bool): | |
| assert bool(has_permission) is expected | |
| def test_has_permission_reason(has_permission: HasPermission, expected: str): | |
| assert repr(has_permission) == expected | |
| async def test_security_policy_anonymous(dummy_request: MyRequest): | |
| policy = SecurityPolicy(dummy_request) | |
| assert (await policy.claimed_identity()) is None | |
| assert (await policy.identity()) is None | |
| async def test_security_policy_claimed_identity(dummy_request: MyRequest): | |
| policy = SecurityPolicy(dummy_request) | |
| claimed = await policy.claimed_identity() | |
| assert claimed is not None | |
| assert claimed.username == "Bob" | |
| assert await policy.identity() is None | |
| async def test_security_policy_identity(dummy_request: MyRequest): | |
| await dummy_request.registry.uow.tokens.add( | |
| AuthnToken( | |
| authntoken_id=UUID(int=11), | |
| user_id=UUID(int=1), | |
| username="Bob", | |
| permissions=set(), | |
| ) | |
| ) | |
| policy = SecurityPolicy(dummy_request) | |
| ident = await policy.identity() | |
| assert ident is not None | |
| assert ident.username == "Bob" | |
| assert await policy.claimed_identity() is None | |
Xet Storage Details
- Size:
- 3.75 kB
- Xet hash:
- 9ce7ae206e2c28bce30d853ad5d916848eac080001c1862dd760b81f9e47d23f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.