graphcore-kernel 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- graphcore/__init__.py +5 -0
- graphcore/agent_frontend/__init__.py +8 -0
- graphcore/agent_frontend/api.py +69 -0
- graphcore/agent_frontend/base/__init__.py +11 -0
- graphcore/agent_frontend/base/views.py +167 -0
- graphcore/agent_frontend/client.py +31 -0
- graphcore/agent_frontend/context.py +157 -0
- graphcore/agent_frontend/errors.py +12 -0
- graphcore/agent_frontend/loading.py +54 -0
- graphcore/agent_frontend/registry.py +42 -0
- graphcore/agent_frontend/render.py +207 -0
- graphcore/agent_frontend/server.py +103 -0
- graphcore/agent_frontend/signatures.py +35 -0
- graphcore/agent_frontend/testing.py +45 -0
- graphcore/agent_frontend/tests/__init__.py +0 -0
- graphcore/agent_frontend/tests/fakes.py +114 -0
- graphcore/agent_frontend/tests/test_frontend.py +447 -0
- graphcore/agent_frontend/tests/test_loading.py +83 -0
- graphcore/agent_frontend/tests/test_server.py +109 -0
- graphcore/agent_frontend/tools.py +137 -0
- graphcore/api/__init__.py +4 -0
- graphcore/api/graph_api.py +378 -0
- graphcore/api/predicate_codec.py +81 -0
- graphcore/api/tests/__init__.py +0 -0
- graphcore/api/tests/test_changed_entities.py +109 -0
- graphcore/api/tests/test_graph_api.py +290 -0
- graphcore/api/tests/test_graph_api_access.py +94 -0
- graphcore/api/tests/test_graph_api_grants.py +90 -0
- graphcore/api/tests/test_predicate_codec.py +83 -0
- graphcore/api/tests/test_subtree_query.py +79 -0
- graphcore/apps.py +71 -0
- graphcore/auth/__init__.py +1 -0
- graphcore/auth/authn/README.md +178 -0
- graphcore/auth/authn/__init__.py +3 -0
- graphcore/auth/authn/authenticator.py +120 -0
- graphcore/auth/authn/onboarding.py +105 -0
- graphcore/auth/authn/principals.py +20 -0
- graphcore/auth/authn/resource_metadata.py +43 -0
- graphcore/auth/authn/service_accounts.py +96 -0
- graphcore/auth/authn/testing.py +96 -0
- graphcore/auth/authn/tests/__init__.py +0 -0
- graphcore/auth/authn/tests/test_authenticator.py +145 -0
- graphcore/auth/authn/tests/test_onboarding.py +145 -0
- graphcore/auth/authn/tests/test_service_accounts.py +180 -0
- graphcore/auth/authn/users.py +59 -0
- graphcore/auth/authz/__init__.py +0 -0
- graphcore/auth/authz/access_port.py +120 -0
- graphcore/auth/authz/adapter/__init__.py +0 -0
- graphcore/auth/authz/adapter/default_access_adapter.py +556 -0
- graphcore/auth/authz/adapter/tests/__init__.py +0 -0
- graphcore/auth/authz/adapter/tests/test_default_adapter.py +543 -0
- graphcore/auth/authz/adapter/tests/test_entity_write_hooks.py +207 -0
- graphcore/auth/authz/adapter/tests/test_group_types.py +70 -0
- graphcore/auth/authz/adapter/tests/test_sync_support.py +209 -0
- graphcore/auth/authz/defaults.py +26 -0
- graphcore/auth/authz/kernel_policy.py +191 -0
- graphcore/auth/authz/kernel_writes.py +31 -0
- graphcore/auth/authz/lookups.py +25 -0
- graphcore/auth/authz/policy.py +403 -0
- graphcore/auth/authz/tests/__init__.py +0 -0
- graphcore/auth/authz/tests/test_can_contain.py +150 -0
- graphcore/auth/authz/tests/test_contained_by.py +167 -0
- graphcore/auth/authz/tests/test_creation.py +391 -0
- graphcore/auth/authz/tests/test_delete_permission.py +82 -0
- graphcore/auth/authz/tests/test_granted_to_me.py +160 -0
- graphcore/auth/authz/tests/test_integration.py +637 -0
- graphcore/auth/authz/tests/test_invites.py +184 -0
- graphcore/auth/authz/tests/test_kernel_policy.py +140 -0
- graphcore/auth/authz/tests/test_lockout.py +132 -0
- graphcore/auth/authz/tests/test_policy.py +329 -0
- graphcore/auth/authz/tests/test_primitives.py +73 -0
- graphcore/auth/authz/tests/test_principal_creation.py +62 -0
- graphcore/bootstrap/__init__.py +0 -0
- graphcore/bootstrap/deployment.py +67 -0
- graphcore/bootstrap/signals.py +16 -0
- graphcore/bootstrap/tests/__init__.py +0 -0
- graphcore/bootstrap/tests/test_deployment_seed.py +154 -0
- graphcore/broadcast/__init__.py +4 -0
- graphcore/broadcast/broadcaster.py +201 -0
- graphcore/broadcast/channels.py +56 -0
- graphcore/broadcast/tests/__init__.py +0 -0
- graphcore/broadcast/tests/test_broadcaster.py +444 -0
- graphcore/celery.py +14 -0
- graphcore/docs/AGENT_FRONTEND_TDD.md +389 -0
- graphcore/docs/ARCHITECTURE_PRINCIPLES.md +152 -0
- graphcore/docs/AUTHORIZATION_TECHNICAL_TDD.md +1379 -0
- graphcore/docs/ENTITY_REFERENCE_TDD.md +561 -0
- graphcore/docs/GRAPHAPI_FRONT_DOOR.md +173 -0
- graphcore/docs/RUNTIME.md +90 -0
- graphcore/docs/SCHEDULING_TDD.md +244 -0
- graphcore/docs/STRATEGY_EXECUTION_TDD.md +1043 -0
- graphcore/docs/VIEW_ENTITY_TDD.md +522 -0
- graphcore/docs/VIEW_SYSTEM_TDD.md +307 -0
- graphcore/docs/__init__.py +0 -0
- graphcore/docs/doc_topics.py +97 -0
- graphcore/docs/docs_discovery.py +64 -0
- graphcore/docs/public_api.py +56 -0
- graphcore/domain/__init__.py +0 -0
- graphcore/domain/entity/Entity.py +204 -0
- graphcore/domain/entity/__init__.py +0 -0
- graphcore/domain/entity/deployment/Deployment.py +25 -0
- graphcore/domain/entity/deployment/__init__.py +0 -0
- graphcore/domain/entity/grant/Grant.py +31 -0
- graphcore/domain/entity/grant/__init__.py +0 -0
- graphcore/domain/entity/group/Group.py +48 -0
- graphcore/domain/entity/group/README.md +88 -0
- graphcore/domain/entity/group/__init__.py +0 -0
- graphcore/domain/entity/invite/Invite.py +31 -0
- graphcore/domain/entity/invite/__init__.py +0 -0
- graphcore/domain/entity/request_template/RequestTemplate.py +48 -0
- graphcore/domain/entity/request_template/__init__.py +0 -0
- graphcore/domain/entity/request_template/tests/__init__.py +0 -0
- graphcore/domain/entity/request_template/tests/test_request_template.py +52 -0
- graphcore/domain/entity/service_account/ServiceAccount.py +41 -0
- graphcore/domain/entity/service_account/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/StrategyRequest.py +61 -0
- graphcore/domain/entity/strategy_request/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/tests/__init__.py +0 -0
- graphcore/domain/entity/strategy_request/tests/test_strategy_request_entity.py +35 -0
- graphcore/domain/entity/tests/__init__.py +0 -0
- graphcore/domain/entity/tests/test_entity.py +227 -0
- graphcore/domain/entity/tests/test_grant_group_entities.py +36 -0
- graphcore/domain/entity/tests/test_write_once_fields.py +98 -0
- graphcore/domain/entity/user/User.py +39 -0
- graphcore/domain/entity/user/__init__.py +0 -0
- graphcore/domain/entity/user/tests/__init__.py +0 -0
- graphcore/domain/entity/user/tests/test_user_entity.py +33 -0
- graphcore/domain/entity/view/View.py +37 -0
- graphcore/domain/entity/view/__init__.py +0 -0
- graphcore/domain/entity/view/position.py +78 -0
- graphcore/domain/entity/view/tests/__init__.py +0 -0
- graphcore/domain/entity/view/tests/test_position.py +71 -0
- graphcore/domain/entity/view/tests/test_view_entity.py +134 -0
- graphcore/domain/strategy/BaseStrategy.py +759 -0
- graphcore/domain/strategy/DeploymentStrategies.py +55 -0
- graphcore/domain/strategy/GrantStrategies.py +189 -0
- graphcore/domain/strategy/GroupStrategies.py +193 -0
- graphcore/domain/strategy/InviteStrategies.py +84 -0
- graphcore/domain/strategy/RequestTemplateStrategies.py +126 -0
- graphcore/domain/strategy/ViewStrategies.py +219 -0
- graphcore/domain/strategy/__init__.py +0 -0
- graphcore/domain/strategy/runner.py +84 -0
- graphcore/domain/strategy/session.py +56 -0
- graphcore/domain/strategy/tests/BaseStrategyTest.py +167 -0
- graphcore/domain/strategy/tests/__init__.py +0 -0
- graphcore/domain/strategy/tests/test_BaseStrategies.py +870 -0
- graphcore/domain/strategy/tests/test_grant_strategies.py +245 -0
- graphcore/domain/strategy/tests/test_group_strategies.py +99 -0
- graphcore/domain/strategy/tests/test_runner.py +220 -0
- graphcore/domain/strategy/tests/test_strategy_locks.py +446 -0
- graphcore/domain/strategy/tests/test_utils.py +95 -0
- graphcore/domain/strategy/tests/test_view_strategies.py +436 -0
- graphcore/errors.py +145 -0
- graphcore/execution/README.md +97 -0
- graphcore/execution/StrategyExecutorService.py +333 -0
- graphcore/execution/__init__.py +0 -0
- graphcore/execution/dispatcher.py +19 -0
- graphcore/execution/environments/__init__.py +0 -0
- graphcore/execution/environments/celery.py +59 -0
- graphcore/execution/environments/in_process.py +55 -0
- graphcore/execution/local_session.py +117 -0
- graphcore/execution/redis_run_events.py +74 -0
- graphcore/execution/requests.py +22 -0
- graphcore/execution/run_events.py +85 -0
- graphcore/execution/strategy_context.py +54 -0
- graphcore/execution/tasks.py +34 -0
- graphcore/execution/tests/__init__.py +5 -0
- graphcore/execution/tests/contract.py +171 -0
- graphcore/execution/tests/support.py +310 -0
- graphcore/execution/tests/test_dispatchers.py +76 -0
- graphcore/execution/tests/test_executor.py +368 -0
- graphcore/execution/tests/test_local_session.py +95 -0
- graphcore/execution/tests/test_reconcile_runs.py +134 -0
- graphcore/execution/tests/test_run_events.py +106 -0
- graphcore/execution/tests/test_strategy_context.py +62 -0
- graphcore/gateway/__init__.py +1 -0
- graphcore/gateway/remote.py +35 -0
- graphcore/gateway/tests/__init__.py +0 -0
- graphcore/gateway/tests/test_remote.py +30 -0
- graphcore/graph/EntityService.py +710 -0
- graphcore/graph/__init__.py +0 -0
- graphcore/graph/entity_cache.py +152 -0
- graphcore/graph/tests/__init__.py +4 -0
- graphcore/graph/tests/test_EntityService.py +908 -0
- graphcore/graph/tests/test_EntityService_list.py +170 -0
- graphcore/graph/tests/test_EntityService_model_resolution.py +339 -0
- graphcore/graph/tests/test_EntityService_referrers.py +236 -0
- graphcore/graph/tests/test_EntityService_routing.py +119 -0
- graphcore/graph/tests/test_dependent_on.py +141 -0
- graphcore/graph/tests/test_engine_is_type_agnostic.py +25 -0
- graphcore/graph/tests/test_engine_resolves_read_permission.py +93 -0
- graphcore/graph/tests/test_entity_cache.py +159 -0
- graphcore/graph/tests/test_null_entity_cache.py +12 -0
- graphcore/management/__init__.py +0 -0
- graphcore/management/commands/__init__.py +0 -0
- graphcore/management/commands/dev_reset.py +18 -0
- graphcore/management/commands/graphcore_createadmin.py +65 -0
- graphcore/management/commands/graphcore_policy.py +59 -0
- graphcore/management/commands/graphcore_status.py +98 -0
- graphcore/management/tests/__init__.py +0 -0
- graphcore/management/tests/test_createadmin.py +78 -0
- graphcore/management/tests/test_policy_command.py +46 -0
- graphcore/management/tests/test_status_command.py +85 -0
- graphcore/migrations/0001_initial.py +186 -0
- graphcore/migrations/0002_invite.py +26 -0
- graphcore/migrations/__init__.py +0 -0
- graphcore/models.py +11 -0
- graphcore/persistence/ENTITY_REPOSITORY_TECHNICAL_TDD.md +396 -0
- graphcore/persistence/__init__.py +6 -0
- graphcore/persistence/django/__init__.py +0 -0
- graphcore/persistence/django/backends.py +43 -0
- graphcore/persistence/django/bindings.py +28 -0
- graphcore/persistence/django/cache.py +38 -0
- graphcore/persistence/django/compiler.py +214 -0
- graphcore/persistence/django/identity.py +18 -0
- graphcore/persistence/django/models.py +252 -0
- graphcore/persistence/django/repository.py +525 -0
- graphcore/persistence/django/tests/__init__.py +0 -0
- graphcore/persistence/django/tests/test_backends.py +68 -0
- graphcore/persistence/django/tests/test_compiler.py +269 -0
- graphcore/persistence/django/tests/test_repository.py +472 -0
- graphcore/persistence/django/tests/test_shared_column.py +120 -0
- graphcore/persistence/django/tests/test_threads.py +50 -0
- graphcore/persistence/django/tests/test_update_shape.py +175 -0
- graphcore/persistence/django/threads.py +38 -0
- graphcore/persistence/repository.py +172 -0
- graphcore/persistence/tests/__init__.py +0 -0
- graphcore/persistence/tests/contract.py +688 -0
- graphcore/persistence/tests/evaluate.py +51 -0
- graphcore/persistence/tests/fixtures.py +32 -0
- graphcore/persistence/tests/memory.py +263 -0
- graphcore/persistence/tests/test_memory_repository.py +10 -0
- graphcore/persistence/tests/test_query_types.py +127 -0
- graphcore/public/__init__.py +9 -0
- graphcore/public/api.py +9 -0
- graphcore/public/apps.py +10 -0
- graphcore/public/auth/__init__.py +1 -0
- graphcore/public/auth/grants.py +7 -0
- graphcore/public/auth/onboarding.py +8 -0
- graphcore/public/auth/perms.py +7 -0
- graphcore/public/auth/policy.py +10 -0
- graphcore/public/auth/roles.py +8 -0
- graphcore/public/auth/subjects.py +7 -0
- graphcore/public/entities/__init__.py +32 -0
- graphcore/public/errors.py +19 -0
- graphcore/public/persistence/__init__.py +44 -0
- graphcore/public/persistence/django.py +24 -0
- graphcore/public/scheduling.py +23 -0
- graphcore/public/strategies/__init__.py +85 -0
- graphcore/public/test_settings.py +16 -0
- graphcore/public/testing.py +47 -0
- graphcore/registry/EntityDirectory.py +246 -0
- graphcore/registry/README.md +147 -0
- graphcore/registry/StrategyDirectory.py +308 -0
- graphcore/registry/TYPE_METADATA_PLACEMENT.md +66 -0
- graphcore/registry/__init__.py +0 -0
- graphcore/registry/app_discovery.py +108 -0
- graphcore/registry/decorators.py +77 -0
- graphcore/registry/discovery.py +111 -0
- graphcore/registry/registry.py +79 -0
- graphcore/registry/tests/__init__.py +0 -0
- graphcore/registry/tests/test_agent_frontend_discovery.py +56 -0
- graphcore/registry/tests/test_app_config.py +36 -0
- graphcore/registry/tests/test_discovery.py +147 -0
- graphcore/registry/tests/test_entity_directory_storage.py +73 -0
- graphcore/registry/tests/test_import_package.py +87 -0
- graphcore/registry/tests/test_principal_flag.py +67 -0
- graphcore/registry/tests/test_strategy_directory.py +29 -0
- graphcore/routes/__init__.py +116 -0
- graphcore/routes/tests/__init__.py +0 -0
- graphcore/routes/tests/test_routes.py +90 -0
- graphcore/runtime.py +243 -0
- graphcore/scheduling/__init__.py +0 -0
- graphcore/scheduling/beat_scheduler.py +164 -0
- graphcore/scheduling/beat_tasks.py +63 -0
- graphcore/scheduling/scheduler.py +37 -0
- graphcore/scheduling/tests/__init__.py +0 -0
- graphcore/scheduling/tests/contract.py +136 -0
- graphcore/scheduling/tests/memory.py +42 -0
- graphcore/scheduling/tests/test_beat_scheduler.py +87 -0
- graphcore/scheduling/tests/test_memory_scheduler.py +15 -0
- graphcore/scheduling/tests/test_ticks.py +143 -0
- graphcore/tasks.py +9 -0
- graphcore/test_settings.py +78 -0
- graphcore/testing/__init__.py +0 -0
- graphcore/testing/case.py +112 -0
- graphcore/testing/runner.py +32 -0
- graphcore/testing/settings.py +26 -0
- graphcore/testing/tests/__init__.py +0 -0
- graphcore/testing/tests/agent_view_fixture.py +19 -0
- graphcore/testing/tests/test_case_and_runner.py +219 -0
- graphcore/testing/tests/test_settings_for_apps.py +50 -0
- graphcore/tests/__init__.py +0 -0
- graphcore/tests/ids.py +14 -0
- graphcore/tests/public_api_manifest.py +102 -0
- graphcore/tests/runs.py +7 -0
- graphcore/tests/test_app_discovery.py +90 -0
- graphcore/tests/test_composition_boundaries.py +231 -0
- graphcore/tests/test_docs_discovery.py +108 -0
- graphcore/tests/test_no_print.py +70 -0
- graphcore/tests/test_packaging.py +64 -0
- graphcore/tests/test_public_api_boundaries.py +229 -0
- graphcore/tests/test_public_api_contract.py +62 -0
- graphcore/tests/test_public_api_docs.py +28 -0
- graphcore/tests/test_runtime.py +42 -0
- graphcore/tests/test_shared_type_boundaries.py +128 -0
- graphcore/tests/test_shared_types.py +144 -0
- graphcore/tests/test_test_settings.py +45 -0
- graphcore/transport/__init__.py +0 -0
- graphcore/transport/agent_asgi.py +68 -0
- graphcore/transport/agent_client.py +85 -0
- graphcore/transport/channel_layer.py +68 -0
- graphcore/transport/consumers.py +507 -0
- graphcore/transport/routing.py +6 -0
- graphcore/transport/tests/__init__.py +0 -0
- graphcore/transport/tests/test_agent_client.py +31 -0
- graphcore/transport/tests/test_api_views.py +733 -0
- graphcore/transport/tests/test_channel_layer.py +96 -0
- graphcore/transport/tests/test_consumers.py +963 -0
- graphcore/transport/tests/test_resource_metadata.py +67 -0
- graphcore/transport/urls.py +29 -0
- graphcore/transport/views.py +358 -0
- graphcore/types/__init__.py +4 -0
- graphcore/types/access.py +114 -0
- graphcore/types/api.py +76 -0
- graphcore/types/entities.py +100 -0
- graphcore/types/entity_id.py +85 -0
- graphcore/types/execution.py +41 -0
- graphcore/types/identity.py +20 -0
- graphcore/types/onboarding.py +20 -0
- graphcore/types/query.py +116 -0
- graphcore/types/schedules.py +91 -0
- graphcore/types/strategy.py +73 -0
- graphcore/types/tests/__init__.py +0 -0
- graphcore/types/tests/test_entity_id.py +50 -0
- graphcore/urls.py +5 -0
- graphcore_kernel-0.1.0.dist-info/METADATA +94 -0
- graphcore_kernel-0.1.0.dist-info/RECORD +343 -0
- graphcore_kernel-0.1.0.dist-info/WHEEL +5 -0
- graphcore_kernel-0.1.0.dist-info/entry_points.txt +2 -0
- graphcore_kernel-0.1.0.dist-info/licenses/LICENSE +202 -0
- graphcore_kernel-0.1.0.dist-info/licenses/NOTICE +2 -0
- graphcore_kernel-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""Invites: a link whose redemption becomes an ordinary grant. See
|
|
2
|
+
docs/AUTHORIZATION_TECHNICAL_TDD.md (Invites)."""
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from asgiref.sync import async_to_sync
|
|
8
|
+
from django.test import TransactionTestCase
|
|
9
|
+
|
|
10
|
+
from graphcore.domain.entity.Entity import Entity
|
|
11
|
+
from graphcore.domain.entity.invite.Invite import Invite
|
|
12
|
+
from graphcore.domain.entity.strategy_request.StrategyRequest import StrategyRequest
|
|
13
|
+
from graphcore.domain.entity.user.User import User
|
|
14
|
+
from graphcore.domain.strategy.BaseStrategy import DeleteEntity
|
|
15
|
+
from graphcore.domain.strategy.InviteStrategies import CreateInvite
|
|
16
|
+
from graphcore.errors import Forbidden, InvalidRequest, NotFound
|
|
17
|
+
from graphcore.execution.strategy_context import kernel_internal_context
|
|
18
|
+
from graphcore.persistence.django.models import EntityModel, StrategyRequestModel
|
|
19
|
+
from graphcore.registry.registry import DEFAULT_REGISTRY
|
|
20
|
+
from graphcore.runtime import django_runtime
|
|
21
|
+
from graphcore.types.entities import Tombstone
|
|
22
|
+
from graphcore.types.identity import Principal
|
|
23
|
+
|
|
24
|
+
TEST_REGISTRY = DEFAULT_REGISTRY.fork_open()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class _Wedding(Entity):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class _Note(Entity):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
TEST_REGISTRY.entities.register_entity(_Wedding, app_label='graphcore')
|
|
36
|
+
TEST_REGISTRY.policy.define(_Wedding, shareable=True)
|
|
37
|
+
TEST_REGISTRY.entities.register_entity(_Note, app_label='graphcore')
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class InviteTests(TransactionTestCase):
|
|
41
|
+
|
|
42
|
+
def setUp(self):
|
|
43
|
+
self.runtime = django_runtime(TEST_REGISTRY)
|
|
44
|
+
self.api = self.runtime.graph_api
|
|
45
|
+
self.service = self.runtime.entity_service
|
|
46
|
+
|
|
47
|
+
async def _user(self, username) -> Principal:
|
|
48
|
+
user = self.service.create(User, username=username)
|
|
49
|
+
with kernel_internal_context():
|
|
50
|
+
user = await self.service.save_entity(user, None)
|
|
51
|
+
return Principal(principal_entity_id=user.entity_id)
|
|
52
|
+
|
|
53
|
+
async def _owned(self, owner: Principal, entity_cls=_Wedding) -> str:
|
|
54
|
+
entity = self.service.create(entity_cls)
|
|
55
|
+
entity.owner = owner.principal_entity_id
|
|
56
|
+
with kernel_internal_context():
|
|
57
|
+
return (await self.service.save_entity(entity, owner)).entity_id
|
|
58
|
+
|
|
59
|
+
async def _setup(self, **options):
|
|
60
|
+
owner = await self._user('invite-owner')
|
|
61
|
+
wedding = await self._owned(owner)
|
|
62
|
+
invite_id, token = await self.api.create_invite(owner, wedding, 'editor', **options)
|
|
63
|
+
return owner, wedding, invite_id, token
|
|
64
|
+
|
|
65
|
+
async def _role_of(self, principal, resource_id):
|
|
66
|
+
grants = await self.service.access_adapter.list_grants(
|
|
67
|
+
Principal(principal_entity_id='nobody'), resource_id)
|
|
68
|
+
return next((g.role.name for g in grants
|
|
69
|
+
if g.subject_id == principal.principal_entity_id and g.provenance == 'direct'), None)
|
|
70
|
+
|
|
71
|
+
@async_to_sync
|
|
72
|
+
async def test_redeeming_grants_the_role_and_reveals_the_resource(self):
|
|
73
|
+
_, wedding, _, token = await self._setup()
|
|
74
|
+
fiancee = await self._user('invite-fiancee')
|
|
75
|
+
self.assertIsInstance(await self.api.get_entity(fiancee, wedding), Tombstone)
|
|
76
|
+
|
|
77
|
+
result = await self.api.redeem_invite(fiancee, token)
|
|
78
|
+
|
|
79
|
+
self.assertEqual(result['resource_id'], wedding)
|
|
80
|
+
self.assertEqual(await self._role_of(fiancee, wedding), 'editor')
|
|
81
|
+
self.assertNotIsInstance(await self.api.get_entity(fiancee, wedding), Tombstone)
|
|
82
|
+
|
|
83
|
+
@async_to_sync
|
|
84
|
+
async def test_only_the_hash_of_the_secret_is_stored(self):
|
|
85
|
+
_, _, invite_id, token = await self._setup()
|
|
86
|
+
secret = token.rpartition('.')[2]
|
|
87
|
+
invite = await self.service.repository.load(invite_id)
|
|
88
|
+
|
|
89
|
+
self.assertEqual(token.rpartition('.')[0], invite_id)
|
|
90
|
+
self.assertEqual(invite.token_hash, hashlib.sha256(secret.encode()).hexdigest())
|
|
91
|
+
rows = [row async for row in EntityModel.objects.values()]
|
|
92
|
+
self.assertTrue(any(row['entity_type_id'] == StrategyRequest.get_entity_type_id() for row in rows))
|
|
93
|
+
self.assertNotIn(secret, json.dumps(rows, default=str))
|
|
94
|
+
requests = [row async for row in StrategyRequestModel.objects.values()]
|
|
95
|
+
self.assertNotIn(secret, json.dumps(requests, default=str))
|
|
96
|
+
|
|
97
|
+
@async_to_sync
|
|
98
|
+
async def test_a_single_use_invite_admits_one_person_and_is_idempotent_for_them(self):
|
|
99
|
+
_, wedding, _, token = await self._setup()
|
|
100
|
+
fiancee = await self._user('invite-fiancee')
|
|
101
|
+
stranger = await self._user('invite-stranger')
|
|
102
|
+
|
|
103
|
+
await self.api.redeem_invite(fiancee, token)
|
|
104
|
+
await self.api.redeem_invite(fiancee, token)
|
|
105
|
+
with self.assertRaises(NotFound):
|
|
106
|
+
await self.api.redeem_invite(stranger, token)
|
|
107
|
+
self.assertIsNone(await self._role_of(stranger, wedding))
|
|
108
|
+
|
|
109
|
+
@async_to_sync
|
|
110
|
+
async def test_max_uses_admits_that_many_people(self):
|
|
111
|
+
_, wedding, _, token = await self._setup(max_uses=2)
|
|
112
|
+
first, second, third = [await self._user(f'invite-guest-{i}') for i in range(3)]
|
|
113
|
+
|
|
114
|
+
await self.api.redeem_invite(first, token)
|
|
115
|
+
await self.api.redeem_invite(second, token)
|
|
116
|
+
with self.assertRaises(NotFound):
|
|
117
|
+
await self.api.redeem_invite(third, token)
|
|
118
|
+
|
|
119
|
+
@async_to_sync
|
|
120
|
+
async def test_wrong_secret_malformed_token_and_expired_invite_are_refused_alike(self):
|
|
121
|
+
_, wedding, invite_id, token = await self._setup()
|
|
122
|
+
guest = await self._user('invite-guest')
|
|
123
|
+
|
|
124
|
+
for bad in (f'{invite_id}.wrong', 'garbage', '', f'{invite_id}.', wedding + '.x'):
|
|
125
|
+
with self.subTest(token=bad), self.assertRaises(NotFound):
|
|
126
|
+
await self.api.redeem_invite(guest, bad)
|
|
127
|
+
|
|
128
|
+
invite = await self.service.repository.load(invite_id)
|
|
129
|
+
invite.expires_at = time.time() - 1
|
|
130
|
+
with kernel_internal_context():
|
|
131
|
+
await self.service.save_entity(invite, None)
|
|
132
|
+
with self.assertRaises(NotFound):
|
|
133
|
+
await self.api.redeem_invite(guest, token)
|
|
134
|
+
self.assertIsNone(await self._role_of(guest, wedding))
|
|
135
|
+
|
|
136
|
+
@async_to_sync
|
|
137
|
+
async def test_redeeming_never_downgrades_and_uses_nothing_up(self):
|
|
138
|
+
owner, wedding, _, token = await self._setup()
|
|
139
|
+
admin = await self._user('invite-admin')
|
|
140
|
+
await self.api.grant(owner, wedding, admin.principal_entity_id, 'admin')
|
|
141
|
+
|
|
142
|
+
await self.api.redeem_invite(admin, token)
|
|
143
|
+
await self.api.redeem_invite(owner, token)
|
|
144
|
+
self.assertEqual(await self._role_of(admin, wedding), 'admin')
|
|
145
|
+
self.assertIsNone(await self._role_of(owner, wedding))
|
|
146
|
+
|
|
147
|
+
fiancee = await self._user('invite-fiancee')
|
|
148
|
+
await self.api.redeem_invite(fiancee, token)
|
|
149
|
+
self.assertEqual(await self._role_of(fiancee, wedding), 'editor')
|
|
150
|
+
|
|
151
|
+
@async_to_sync
|
|
152
|
+
async def test_a_revoked_invite_is_refused(self):
|
|
153
|
+
owner, _, invite_id, token = await self._setup()
|
|
154
|
+
await self.runtime.executor.submit(DeleteEntity.request_constructor(invite_id), owner)
|
|
155
|
+
|
|
156
|
+
with self.assertRaises(NotFound):
|
|
157
|
+
await self.api.redeem_invite(await self._user('invite-guest'), token)
|
|
158
|
+
|
|
159
|
+
@async_to_sync
|
|
160
|
+
async def test_only_access_managers_create_or_see_invites(self):
|
|
161
|
+
owner, wedding, invite_id, _ = await self._setup()
|
|
162
|
+
viewer = await self._user('invite-viewer')
|
|
163
|
+
await self.api.grant(owner, wedding, viewer.principal_entity_id, 'viewer')
|
|
164
|
+
|
|
165
|
+
with self.assertRaises(Forbidden):
|
|
166
|
+
await self.api.create_invite(viewer, wedding, 'admin')
|
|
167
|
+
self.assertIsInstance(await self.api.get_entity(viewer, invite_id), Tombstone)
|
|
168
|
+
self.assertIsInstance(await self.api.get_entity(owner, invite_id), Invite)
|
|
169
|
+
|
|
170
|
+
@async_to_sync
|
|
171
|
+
async def test_invites_need_a_shareable_resource_a_known_role_and_a_hash(self):
|
|
172
|
+
owner = await self._user('invite-owner')
|
|
173
|
+
note = await self._owned(owner, _Note)
|
|
174
|
+
wedding = await self._owned(owner)
|
|
175
|
+
|
|
176
|
+
with self.assertRaises(InvalidRequest):
|
|
177
|
+
await self.api.create_invite(owner, note, 'editor')
|
|
178
|
+
with self.assertRaises(InvalidRequest):
|
|
179
|
+
await self.api.create_invite(owner, wedding, 'no-such-role')
|
|
180
|
+
with self.assertRaises(InvalidRequest):
|
|
181
|
+
await self.runtime.executor.submit(
|
|
182
|
+
CreateInvite.request_constructor(wedding, 'editor', token_hash='plain-secret'), owner)
|
|
183
|
+
with self.assertRaises(InvalidRequest):
|
|
184
|
+
await self.api.create_invite(owner, wedding, 'editor', expires_in_seconds=0)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""kernel_policy.configure - the kernel types' declared policy."""
|
|
2
|
+
from django.test import SimpleTestCase, override_settings
|
|
3
|
+
|
|
4
|
+
from graphcore.auth.authz import kernel_policy
|
|
5
|
+
from graphcore.auth.authz.policy import AccessPolicy
|
|
6
|
+
from graphcore.types.access import Create, Delete, ManageAccess, Read, Write
|
|
7
|
+
from graphcore.domain.entity.deployment.Deployment import Deployment
|
|
8
|
+
from graphcore.domain.entity.grant.Grant import Grant
|
|
9
|
+
from graphcore.domain.entity.group.Group import Group
|
|
10
|
+
from graphcore.domain.entity.invite.Invite import Invite
|
|
11
|
+
from graphcore.domain.entity.request_template.RequestTemplate import RequestTemplate
|
|
12
|
+
from graphcore.domain.entity.strategy_request.StrategyRequest import StrategyRequest
|
|
13
|
+
from graphcore.domain.entity.user.User import User
|
|
14
|
+
from graphcore.domain.entity.view.View import View
|
|
15
|
+
from graphcore.domain.strategy.BaseStrategy import (
|
|
16
|
+
CreateEntity, DeleteEntity, SetAttributes,
|
|
17
|
+
)
|
|
18
|
+
from graphcore.domain.strategy.DeploymentStrategies import SetNewUserDefaults
|
|
19
|
+
from graphcore.domain.strategy.GrantStrategies import (
|
|
20
|
+
ChangeGrantRole, CreateGrant, RevokeGrant,
|
|
21
|
+
)
|
|
22
|
+
from graphcore.domain.strategy.GroupStrategies import (
|
|
23
|
+
AddMember, CreateGroup, ModifyGroup, RemoveMember,
|
|
24
|
+
)
|
|
25
|
+
from graphcore.domain.strategy.InviteStrategies import CreateInvite
|
|
26
|
+
from graphcore.domain.strategy.RequestTemplateStrategies import (
|
|
27
|
+
CreateRequestTemplate, ManageRequestTemplate,
|
|
28
|
+
)
|
|
29
|
+
from graphcore.domain.strategy.ViewStrategies import CreateView, SetViewState
|
|
30
|
+
from graphcore.registry.StrategyDirectory import StrategyDirectoryClass
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _configure() -> AccessPolicy:
|
|
34
|
+
policy = AccessPolicy(StrategyDirectoryClass())
|
|
35
|
+
kernel_policy.configure(policy)
|
|
36
|
+
return policy
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class UserPublicReadDefaultTests(SimpleTestCase):
|
|
40
|
+
def test_defaults_to_public_read_when_unset(self):
|
|
41
|
+
self.assertEqual(_configure().type_public_perms(User), frozenset({Read()}))
|
|
42
|
+
|
|
43
|
+
@override_settings(GRAPHCORE_PUBLIC_USER_READ=True)
|
|
44
|
+
def test_public_read_when_setting_true(self):
|
|
45
|
+
self.assertEqual(_configure().type_public_perms(User), frozenset({Read()}))
|
|
46
|
+
|
|
47
|
+
@override_settings(GRAPHCORE_PUBLIC_USER_READ=False)
|
|
48
|
+
def test_no_public_read_when_setting_false(self):
|
|
49
|
+
self.assertEqual(_configure().type_public_perms(User), frozenset())
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class KernelStrategyPermissionTests(SimpleTestCase):
|
|
53
|
+
def test_kernel_policy_is_unchanged_by_explicit_permissions(self):
|
|
54
|
+
policy = _configure()
|
|
55
|
+
expected = {
|
|
56
|
+
Deployment: {
|
|
57
|
+
CreateEntity: Create(),
|
|
58
|
+
CreateGroup: Create(),
|
|
59
|
+
CreateView: Create(),
|
|
60
|
+
SetViewState: Create(),
|
|
61
|
+
SetNewUserDefaults: ManageAccess(),
|
|
62
|
+
CreateGrant: ManageAccess(),
|
|
63
|
+
CreateInvite: ManageAccess(),
|
|
64
|
+
CreateRequestTemplate: Create(),
|
|
65
|
+
},
|
|
66
|
+
Grant: {
|
|
67
|
+
CreateEntity: Create(),
|
|
68
|
+
CreateGroup: Create(),
|
|
69
|
+
CreateView: Create(),
|
|
70
|
+
CreateGrant: ManageAccess(),
|
|
71
|
+
CreateInvite: ManageAccess(),
|
|
72
|
+
ChangeGrantRole: ManageAccess(),
|
|
73
|
+
RevokeGrant: ManageAccess(),
|
|
74
|
+
},
|
|
75
|
+
Group: {
|
|
76
|
+
CreateEntity: Create(),
|
|
77
|
+
CreateGrant: ManageAccess(),
|
|
78
|
+
CreateInvite: ManageAccess(),
|
|
79
|
+
ChangeGrantRole: Write(),
|
|
80
|
+
RevokeGrant: Write(),
|
|
81
|
+
AddMember: ManageAccess(),
|
|
82
|
+
RemoveMember: ManageAccess(),
|
|
83
|
+
ModifyGroup: Write(),
|
|
84
|
+
CreateGroup: Create(),
|
|
85
|
+
CreateView: Create(),
|
|
86
|
+
SetAttributes: Write(),
|
|
87
|
+
DeleteEntity: Write(),
|
|
88
|
+
},
|
|
89
|
+
View: {
|
|
90
|
+
CreateEntity: Create(),
|
|
91
|
+
CreateGroup: Create(),
|
|
92
|
+
SetViewState: Write(),
|
|
93
|
+
CreateView: Create(),
|
|
94
|
+
DeleteEntity: Delete(),
|
|
95
|
+
CreateGrant: ManageAccess(),
|
|
96
|
+
CreateInvite: ManageAccess(),
|
|
97
|
+
},
|
|
98
|
+
}
|
|
99
|
+
for entity_type, strategies in expected.items():
|
|
100
|
+
with self.subTest(entity_type=entity_type.__name__):
|
|
101
|
+
self.assertEqual(dict(policy.describe(entity_type).strategies), strategies)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
class RequestPolicyTests(SimpleTestCase):
|
|
105
|
+
def test_no_strategy_writes_a_request(self):
|
|
106
|
+
policy = _configure()
|
|
107
|
+
self.assertEqual(policy.allowed_strategies(StrategyRequest), frozenset())
|
|
108
|
+
self.assertFalse(policy.is_creatable(StrategyRequest))
|
|
109
|
+
|
|
110
|
+
def test_only_the_template_strategies_and_delete_write_a_template(self):
|
|
111
|
+
self.assertEqual(
|
|
112
|
+
_configure().allowed_strategies(RequestTemplate),
|
|
113
|
+
frozenset({CreateRequestTemplate, ManageRequestTemplate, DeleteEntity}),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
def test_a_group_key_is_set_only_by_a_deployment_administrator(self):
|
|
117
|
+
self.assertEqual(dict(_configure().deployment_fields(Group)), {'key': ManageAccess()})
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class ViewPolicyTests(SimpleTestCase):
|
|
121
|
+
def test_only_listed_strategies_reach_a_view(self):
|
|
122
|
+
policy = _configure()
|
|
123
|
+
allowed = policy.allowed_strategies(View)
|
|
124
|
+
self.assertIn(SetViewState, allowed)
|
|
125
|
+
self.assertNotIn(CreateEntity, allowed)
|
|
126
|
+
self.assertNotIn(SetAttributes, allowed)
|
|
127
|
+
|
|
128
|
+
def test_a_view_holds_views_grants_and_invites(self):
|
|
129
|
+
self.assertEqual(set(_configure().describe(View).can_contain), {View, Grant, Invite})
|
|
130
|
+
|
|
131
|
+
def test_a_user_contains_nothing(self):
|
|
132
|
+
self.assertEqual(_configure().describe(User).can_contain, ())
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class GrantPolicyTests(SimpleTestCase):
|
|
136
|
+
def test_reading_and_deleting_a_grant_need_manage_access(self):
|
|
137
|
+
described = _configure().describe(Grant)
|
|
138
|
+
self.assertEqual(described.read, ManageAccess())
|
|
139
|
+
self.assertEqual(described.delete, ManageAccess())
|
|
140
|
+
self.assertEqual(described.can_contain, ())
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"""The lockout rule: no change may leave an entity with nobody who can
|
|
2
|
+
manage access to it - see docs/AUTHORIZATION_TECHNICAL_TDD.md (Enforcement,
|
|
3
|
+
The lockout rule)."""
|
|
4
|
+
from asgiref.sync import async_to_sync
|
|
5
|
+
from django.test import TransactionTestCase
|
|
6
|
+
|
|
7
|
+
from graphcore.auth.authz.lookups import find_grant, find_group_by_key
|
|
8
|
+
from graphcore.bootstrap.deployment import ensure_deployment
|
|
9
|
+
from graphcore.domain.entity.Entity import Entity
|
|
10
|
+
from graphcore.domain.entity.user.User import User
|
|
11
|
+
from graphcore.domain.strategy.BaseStrategy import CreateEntity, DeleteEntity
|
|
12
|
+
from graphcore.domain.strategy.GrantStrategies import ChangeGrantRole, RevokeGrant
|
|
13
|
+
from graphcore.domain.strategy.GroupStrategies import AddMember, RemoveMember
|
|
14
|
+
from graphcore.errors import Forbidden
|
|
15
|
+
from graphcore.execution.strategy_context import kernel_internal_context
|
|
16
|
+
from graphcore.registry.registry import DEFAULT_REGISTRY
|
|
17
|
+
from graphcore.runtime import django_runtime
|
|
18
|
+
from graphcore.auth.authz.defaults import ADMINS_GROUP_KEY
|
|
19
|
+
from graphcore.types.identity import PUBLIC
|
|
20
|
+
from graphcore.types.identity import Principal
|
|
21
|
+
from graphcore.tests.runs import run
|
|
22
|
+
|
|
23
|
+
TEST_REGISTRY = DEFAULT_REGISTRY.fork_open()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _Workspace(Entity):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
TEST_REGISTRY.entities.register_entity(_Workspace, app_label='graphcore')
|
|
31
|
+
TEST_REGISTRY.policy.define(_Workspace, shareable=True)
|
|
32
|
+
|
|
33
|
+
LOCKOUT = 'nobody could manage access'
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class LockoutTests(TransactionTestCase):
|
|
37
|
+
def setUp(self):
|
|
38
|
+
self.runtime = django_runtime(TEST_REGISTRY)
|
|
39
|
+
self.service = self.runtime.entity_service
|
|
40
|
+
self.executor = self.runtime.executor
|
|
41
|
+
self.api = self.runtime.graph_api
|
|
42
|
+
self.deployment_id = self.runtime.deployment_entity_id
|
|
43
|
+
|
|
44
|
+
async def _user(self, username):
|
|
45
|
+
user = self.service.create(User, username=username)
|
|
46
|
+
with kernel_internal_context():
|
|
47
|
+
await self.service.save_entity(user, Principal(principal_entity_id=user.entity_id))
|
|
48
|
+
return Principal(principal_entity_id=user.entity_id)
|
|
49
|
+
|
|
50
|
+
async def _seed(self):
|
|
51
|
+
await ensure_deployment(self.service, TEST_REGISTRY)
|
|
52
|
+
self.admin = await self._user('lockout-admin')
|
|
53
|
+
self.admins = await find_group_by_key(self.service, ADMINS_GROUP_KEY)
|
|
54
|
+
self.admins.add_member(self.admin.principal_entity_id)
|
|
55
|
+
with kernel_internal_context():
|
|
56
|
+
self.admins = await self.service.save_entity(self.admins, None)
|
|
57
|
+
|
|
58
|
+
async def _run(self, request, principal=None):
|
|
59
|
+
return await run(self.executor, request, principal=principal or self.admin)
|
|
60
|
+
|
|
61
|
+
async def _admins_grant(self, resource_id):
|
|
62
|
+
return await find_grant(self.service, resource_id, self.admins.entity_id)
|
|
63
|
+
|
|
64
|
+
@async_to_sync
|
|
65
|
+
async def test_the_admins_grants_cannot_be_demoted_or_revoked(self):
|
|
66
|
+
await self._seed()
|
|
67
|
+
for resource_id, lesser_role in ((self.deployment_id, 'member'), (self.admins.entity_id, 'editor')):
|
|
68
|
+
grant = await self._admins_grant(resource_id)
|
|
69
|
+
with self.subTest(resource=resource_id):
|
|
70
|
+
with self.assertRaisesMessage(Forbidden, LOCKOUT):
|
|
71
|
+
await self._run(ChangeGrantRole.request_constructor(grant.entity_id, lesser_role))
|
|
72
|
+
with self.assertRaisesMessage(Forbidden, LOCKOUT):
|
|
73
|
+
await self._run(RevokeGrant.request_constructor(grant.entity_id))
|
|
74
|
+
self.assertEqual((await self._admins_grant(resource_id)).role_name, 'admin')
|
|
75
|
+
|
|
76
|
+
@async_to_sync
|
|
77
|
+
async def test_regranting_replaces_nothing_it_would_lock_out(self):
|
|
78
|
+
await self._seed()
|
|
79
|
+
with self.assertRaisesMessage(Forbidden, LOCKOUT):
|
|
80
|
+
await self.api.grant(self.admin, self.deployment_id, self.admins.entity_id, 'member')
|
|
81
|
+
|
|
82
|
+
@async_to_sync
|
|
83
|
+
async def test_the_last_admin_cannot_leave_and_the_group_cannot_be_deleted(self):
|
|
84
|
+
await self._seed()
|
|
85
|
+
with self.assertRaisesMessage(Forbidden, LOCKOUT):
|
|
86
|
+
await self._run(RemoveMember.request_constructor(
|
|
87
|
+
self.admins.entity_id, self.admin.principal_entity_id,
|
|
88
|
+
))
|
|
89
|
+
with self.assertRaisesMessage(Forbidden, LOCKOUT):
|
|
90
|
+
await self._run(DeleteEntity.request_constructor(target_entity_id=self.admins.entity_id))
|
|
91
|
+
self.assertIsNotNone(await self.service.repository.load(self.admins.entity_id))
|
|
92
|
+
|
|
93
|
+
@async_to_sync
|
|
94
|
+
async def test_changes_are_allowed_while_someone_else_can_still_manage(self):
|
|
95
|
+
await self._seed()
|
|
96
|
+
second = await self._user('second-admin')
|
|
97
|
+
await self._run(AddMember.request_constructor(self.admins.entity_id, second.principal_entity_id))
|
|
98
|
+
await self._run(RemoveMember.request_constructor(self.admins.entity_id, self.admin.principal_entity_id))
|
|
99
|
+
|
|
100
|
+
await self.api.grant(second, self.deployment_id, second.principal_entity_id, 'admin')
|
|
101
|
+
grant = await self._admins_grant(self.deployment_id)
|
|
102
|
+
await self._run(ChangeGrantRole.request_constructor(grant.entity_id, 'member'), principal=second)
|
|
103
|
+
self.assertEqual((await self._admins_grant(self.deployment_id)).role_name, 'member')
|
|
104
|
+
|
|
105
|
+
@async_to_sync
|
|
106
|
+
async def test_public_holding_admin_counts_as_a_manager(self):
|
|
107
|
+
await self._seed()
|
|
108
|
+
await self.api.grant(self.admin, self.deployment_id, PUBLIC, 'admin')
|
|
109
|
+
grant = await self._admins_grant(self.deployment_id)
|
|
110
|
+
await self._run(RevokeGrant.request_constructor(grant.entity_id))
|
|
111
|
+
self.assertIsNone(await self._admins_grant(self.deployment_id))
|
|
112
|
+
|
|
113
|
+
@async_to_sync
|
|
114
|
+
async def test_an_owned_entity_never_trips_the_rule(self):
|
|
115
|
+
await self._seed()
|
|
116
|
+
request, _ = await self._run(CreateEntity.request_constructor(
|
|
117
|
+
target_entity_id=None,
|
|
118
|
+
entity_type_id=TEST_REGISTRY.entities.get_entity_type_id(_Workspace),
|
|
119
|
+
))
|
|
120
|
+
workspace_id = request.ret_val['child_entity']
|
|
121
|
+
collaborator = await self._user('collaborator')
|
|
122
|
+
await self.api.grant(self.admin, workspace_id, collaborator.principal_entity_id, 'admin')
|
|
123
|
+
await self.api.revoke(self.admin, workspace_id, collaborator.principal_entity_id)
|
|
124
|
+
self.assertIsNone(await find_grant(self.service, workspace_id, collaborator.principal_entity_id))
|
|
125
|
+
|
|
126
|
+
@async_to_sync
|
|
127
|
+
async def test_kernel_internal_writes_are_exempt(self):
|
|
128
|
+
await self._seed()
|
|
129
|
+
grant = await self._admins_grant(self.deployment_id)
|
|
130
|
+
with kernel_internal_context():
|
|
131
|
+
await self.service.delete_entity_tree(grant.entity_id, self.admin)
|
|
132
|
+
self.assertIsNone(await self._admins_grant(self.deployment_id))
|