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,207 @@
|
|
|
1
|
+
from asgiref.sync import async_to_sync
|
|
2
|
+
from django.test import TestCase, TransactionTestCase
|
|
3
|
+
|
|
4
|
+
from graphcore.auth.authz.defaults import ADMIN, EDITOR, VIEWER
|
|
5
|
+
from graphcore.domain.entity.Entity import Entity
|
|
6
|
+
from graphcore.domain.entity.grant.Grant import Grant
|
|
7
|
+
from graphcore.domain.entity.group.Group import Group
|
|
8
|
+
from graphcore.execution.strategy_context import kernel_internal_context
|
|
9
|
+
from graphcore.persistence.tests.fixtures import make, persist
|
|
10
|
+
from graphcore.registry.registry import DEFAULT_REGISTRY
|
|
11
|
+
from graphcore.runtime import django_runtime
|
|
12
|
+
from graphcore.types.identity import Principal
|
|
13
|
+
from graphcore.broadcast.broadcaster import scope_channel
|
|
14
|
+
|
|
15
|
+
TEST_REGISTRY = DEFAULT_REGISTRY.fork_open()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class _HookScope(Entity):
|
|
19
|
+
"""Module-level (picklable) shareable type for the hook tests."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
TEST_REGISTRY.entities.register_entity(_HookScope, app_label='accesstest')
|
|
23
|
+
TEST_REGISTRY.policy.define(_HookScope, shareable=True)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class GroupRosterHookTests(TestCase):
|
|
27
|
+
"""`entity_saved` on a roster change busts the changed members' cached
|
|
28
|
+
subject sets, so `allows` reflects new membership on the very next call -
|
|
29
|
+
the TDD's invalidation worked example."""
|
|
30
|
+
|
|
31
|
+
def setUp(self):
|
|
32
|
+
rt = django_runtime(TEST_REGISTRY)
|
|
33
|
+
self.adapter = rt.access
|
|
34
|
+
self.entity_service = rt.entity_service
|
|
35
|
+
self.entity_service.channel_layer = None
|
|
36
|
+
self.owner = 'group-owner'
|
|
37
|
+
self.owner_principal = Principal(principal_entity_id=self.owner)
|
|
38
|
+
|
|
39
|
+
self.group = self.entity_service.create(Group)
|
|
40
|
+
self.group.add_member('bob')
|
|
41
|
+
persist(self.group, TEST_REGISTRY)
|
|
42
|
+
|
|
43
|
+
# Warm caches for both users so there is something to observe busted.
|
|
44
|
+
self.adapter.cache.set(self.adapter._subject_groups_cache_key('alice'), [], timeout=300)
|
|
45
|
+
self.adapter.cache.set(
|
|
46
|
+
self.adapter._subject_groups_cache_key('bob'),
|
|
47
|
+
[self.group.entity_id],
|
|
48
|
+
timeout=300,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def test_adding_a_member_busts_their_cached_subject_set(self):
|
|
52
|
+
self.group.add_member('alice')
|
|
53
|
+
with kernel_internal_context():
|
|
54
|
+
async_to_sync(self.entity_service.save_entity)(self.group, self.owner_principal)
|
|
55
|
+
|
|
56
|
+
self.assertIsNone(self.adapter.cache.get(self.adapter._subject_groups_cache_key('alice')))
|
|
57
|
+
|
|
58
|
+
def test_removing_a_member_busts_their_cached_subject_set(self):
|
|
59
|
+
self.group.member_ids = []
|
|
60
|
+
with kernel_internal_context():
|
|
61
|
+
async_to_sync(self.entity_service.save_entity)(self.group, self.owner_principal)
|
|
62
|
+
|
|
63
|
+
self.assertIsNone(self.adapter.cache.get(self.adapter._subject_groups_cache_key('bob')))
|
|
64
|
+
|
|
65
|
+
def test_unrelated_save_does_not_touch_untouched_members_cache(self):
|
|
66
|
+
self.adapter.cache.set(
|
|
67
|
+
self.adapter._subject_groups_cache_key('carol'), ['unrelated'], timeout=300
|
|
68
|
+
)
|
|
69
|
+
self.group.set_attribute('color', 'blue')
|
|
70
|
+
with kernel_internal_context():
|
|
71
|
+
async_to_sync(self.entity_service.save_entity)(self.group, self.owner_principal)
|
|
72
|
+
|
|
73
|
+
self.assertEqual(
|
|
74
|
+
self.adapter.cache.get(self.adapter._subject_groups_cache_key('carol')),
|
|
75
|
+
['unrelated'],
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class GrantAccessChangeHookTests(TestCase):
|
|
80
|
+
"""`entity_saved`/`entities_deleted` on a `Grant` return the
|
|
81
|
+
correctly-shaped `AccessChange` for a create/re-grant/revoke."""
|
|
82
|
+
|
|
83
|
+
def setUp(self):
|
|
84
|
+
self.adapter = django_runtime(TEST_REGISTRY).access
|
|
85
|
+
self.owner = 'grant-owner'
|
|
86
|
+
self.resource = make(_HookScope, TEST_REGISTRY)
|
|
87
|
+
self.resource.owner = self.owner
|
|
88
|
+
persist(self.resource, TEST_REGISTRY)
|
|
89
|
+
|
|
90
|
+
def _make_grant(self, subject_id='alice', role_name='viewer'):
|
|
91
|
+
grant = make(Grant, TEST_REGISTRY)
|
|
92
|
+
grant.subject_id = subject_id
|
|
93
|
+
grant.role_name = role_name
|
|
94
|
+
grant.parent_id = self.resource.entity_id
|
|
95
|
+
return grant
|
|
96
|
+
|
|
97
|
+
def test_create_produces_an_access_change_with_no_old_role(self):
|
|
98
|
+
grant = persist(self._make_grant(role_name='viewer'), TEST_REGISTRY)
|
|
99
|
+
|
|
100
|
+
change = async_to_sync(self.adapter.entity_saved)(grant, previous=None)
|
|
101
|
+
|
|
102
|
+
self.assertEqual(change.subject_id, 'alice')
|
|
103
|
+
self.assertIsNone(change.old_role)
|
|
104
|
+
self.assertEqual(change.new_role, VIEWER)
|
|
105
|
+
self.assertEqual(change.resource_type_id, self.resource.entity_type_id)
|
|
106
|
+
|
|
107
|
+
def test_regrant_produces_an_access_change_with_both_roles(self):
|
|
108
|
+
grant = persist(self._make_grant(role_name='viewer'), TEST_REGISTRY)
|
|
109
|
+
previous = async_to_sync(self.adapter.repository.load)(grant.entity_id)
|
|
110
|
+
|
|
111
|
+
grant.role_name = 'editor'
|
|
112
|
+
persist(grant, TEST_REGISTRY)
|
|
113
|
+
|
|
114
|
+
change = async_to_sync(self.adapter.entity_saved)(grant, previous=previous)
|
|
115
|
+
|
|
116
|
+
self.assertEqual(change.old_role, VIEWER)
|
|
117
|
+
self.assertEqual(change.new_role, EDITOR)
|
|
118
|
+
|
|
119
|
+
def test_revoke_via_delete_produces_an_access_change_with_no_new_role(self):
|
|
120
|
+
grant = persist(self._make_grant(role_name='admin'), TEST_REGISTRY)
|
|
121
|
+
|
|
122
|
+
plan = async_to_sync(self.adapter.prepare_delete)([grant.entity_id])
|
|
123
|
+
(change,) = async_to_sync(self.adapter.entities_deleted)(plan)
|
|
124
|
+
|
|
125
|
+
self.assertEqual(change.old_role, ADMIN)
|
|
126
|
+
self.assertIsNone(change.new_role)
|
|
127
|
+
|
|
128
|
+
def test_non_grant_non_group_save_returns_none(self):
|
|
129
|
+
entity = persist(make(_HookScope, TEST_REGISTRY), TEST_REGISTRY)
|
|
130
|
+
|
|
131
|
+
self.assertIsNone(async_to_sync(self.adapter.entity_saved)(entity, previous=None))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class DeleteEntitiesHookIntegrationTests(TestCase):
|
|
135
|
+
"""`EntityService.delete_entities` asks the port to `prepare_delete`
|
|
136
|
+
while the rows exist, then reports the committed delete."""
|
|
137
|
+
|
|
138
|
+
def setUp(self):
|
|
139
|
+
self.entity_service = django_runtime(TEST_REGISTRY).entity_service
|
|
140
|
+
self.entity_service.channel_layer = None
|
|
141
|
+
self.owner = 'delete-owner'
|
|
142
|
+
self.owner_principal = Principal(principal_entity_id=self.owner)
|
|
143
|
+
|
|
144
|
+
def test_deleting_a_grant_reports_it_deleted(self):
|
|
145
|
+
resource = make(_HookScope, TEST_REGISTRY)
|
|
146
|
+
resource.owner = self.owner
|
|
147
|
+
persist(resource, TEST_REGISTRY)
|
|
148
|
+
|
|
149
|
+
grant = make(Grant, TEST_REGISTRY)
|
|
150
|
+
grant.subject_id = 'alice'
|
|
151
|
+
grant.role_name = 'viewer'
|
|
152
|
+
grant.parent_id = resource.entity_id
|
|
153
|
+
persist(grant, TEST_REGISTRY)
|
|
154
|
+
|
|
155
|
+
deleted_ids = async_to_sync(self.entity_service.delete_entities)(
|
|
156
|
+
[grant.entity_id], self.owner_principal,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
self.assertEqual(deleted_ids, [grant.entity_id])
|
|
160
|
+
|
|
161
|
+
def test_deleting_a_group_busts_its_former_members_cache(self):
|
|
162
|
+
adapter = self.entity_service.access_adapter
|
|
163
|
+
group = self.entity_service.create(Group)
|
|
164
|
+
group.add_member('alice')
|
|
165
|
+
persist(group, TEST_REGISTRY)
|
|
166
|
+
|
|
167
|
+
adapter.cache.set(adapter._subject_groups_cache_key('alice'), [group.entity_id], timeout=300)
|
|
168
|
+
|
|
169
|
+
async_to_sync(self.entity_service.delete_entities)([group.entity_id], self.owner_principal)
|
|
170
|
+
|
|
171
|
+
self.assertIsNone(adapter.cache.get(adapter._subject_groups_cache_key('alice')))
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class GroupRemovalRevokeTests(TransactionTestCase):
|
|
175
|
+
"""A removed member gets one revoke per resource the group holds a grant
|
|
176
|
+
on; the broadcaster, not the adapter, skips one who still reads it."""
|
|
177
|
+
|
|
178
|
+
async def test_a_member_with_a_direct_grant_keeps_the_scope_channel(self):
|
|
179
|
+
rt = django_runtime(TEST_REGISTRY)
|
|
180
|
+
scope = make(_HookScope, TEST_REGISTRY)
|
|
181
|
+
scope.owner = 'removal-owner'
|
|
182
|
+
await rt.repository.save(scope)
|
|
183
|
+
group = rt.entity_service.create(Group)
|
|
184
|
+
group.add_member('bob')
|
|
185
|
+
await rt.repository.save(group)
|
|
186
|
+
for subject_id in (group.entity_id, 'bob'):
|
|
187
|
+
grant = make(Grant, TEST_REGISTRY)
|
|
188
|
+
grant.parent_id, grant.subject_id, grant.role_name = scope.entity_id, subject_id, 'viewer'
|
|
189
|
+
await rt.repository.save(grant)
|
|
190
|
+
|
|
191
|
+
previous = await rt.repository.load(group.entity_id)
|
|
192
|
+
group.remove_member('bob')
|
|
193
|
+
await rt.repository.save(group)
|
|
194
|
+
(change,) = await rt.access.entity_saved(group, previous)
|
|
195
|
+
|
|
196
|
+
self.assertEqual((change.resource_id, change.subject_id), (scope.entity_id, 'bob'))
|
|
197
|
+
self.assertIsNone(change.new_role)
|
|
198
|
+
self.assertEqual(change.resource_type_id, scope.entity_type_id)
|
|
199
|
+
|
|
200
|
+
layer = rt.broadcaster.channel_layer
|
|
201
|
+
channel_name = await layer.new_channel()
|
|
202
|
+
rt.broadcaster.register_connection('bob', channel_name)
|
|
203
|
+
await layer.group_add(scope_channel(scope.entity_id), channel_name)
|
|
204
|
+
await rt.broadcaster.publish_access_change(change)
|
|
205
|
+
|
|
206
|
+
await layer.group_send(scope_channel(scope.entity_id), {'type': 'entity_update', 'entities': {}})
|
|
207
|
+
self.assertEqual((await layer.receive(channel_name))['type'], 'entity_update')
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""A group is `Group` or a subclass of it - a subclass gets every
|
|
2
|
+
behavior the adapter gives groups. See domain/entity/group/README.md."""
|
|
3
|
+
import itertools
|
|
4
|
+
from asgiref.sync import async_to_sync
|
|
5
|
+
from django.test import TestCase
|
|
6
|
+
|
|
7
|
+
from graphcore.auth.authz.adapter.tests.test_default_adapter import (
|
|
8
|
+
TEST_DIRECTORY, _make_entity, _make_grant, _register,
|
|
9
|
+
)
|
|
10
|
+
from graphcore.domain.entity.group.Group import Group
|
|
11
|
+
from graphcore.errors import Forbidden
|
|
12
|
+
from graphcore.execution.strategy_context import kernel_internal_context
|
|
13
|
+
from graphcore.runtime import django_runtime
|
|
14
|
+
from graphcore.types.access import Read
|
|
15
|
+
from graphcore.types.identity import Principal
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class _Team(Group):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
TEST_DIRECTORY.entities.register_entity(_Team, app_label='accesstest')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
_SCOPE_IDS = itertools.count()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class GroupSubclassTests(TestCase):
|
|
29
|
+
def setUp(self):
|
|
30
|
+
self.runtime = django_runtime(TEST_DIRECTORY)
|
|
31
|
+
self.service = self.runtime.entity_service
|
|
32
|
+
self.adapter = self.runtime.access
|
|
33
|
+
self.alice = Principal(principal_entity_id='alice')
|
|
34
|
+
self.scope = _make_entity(_register(f'TeamScope{next(_SCOPE_IDS)}', shareable=True))
|
|
35
|
+
|
|
36
|
+
def _team(self, *members):
|
|
37
|
+
team = self.service.create(_Team)
|
|
38
|
+
for member in members:
|
|
39
|
+
team.add_member(member)
|
|
40
|
+
with kernel_internal_context():
|
|
41
|
+
return async_to_sync(self.service.save_entity)(team, None)
|
|
42
|
+
|
|
43
|
+
def test_a_subclass_counts_as_a_group_for_membership(self):
|
|
44
|
+
team = self._team('alice')
|
|
45
|
+
_make_grant(self.scope, team.entity_id, 'viewer')
|
|
46
|
+
|
|
47
|
+
self.assertTrue(async_to_sync(self.adapter.allows)(self.alice, Read(), self.scope))
|
|
48
|
+
|
|
49
|
+
def test_removing_a_member_takes_effect_immediately(self):
|
|
50
|
+
team = self._team('alice', 'bob')
|
|
51
|
+
_make_grant(self.scope, team.entity_id, 'viewer')
|
|
52
|
+
self.assertTrue(async_to_sync(self.adapter.allows)(self.alice, Read(), self.scope))
|
|
53
|
+
|
|
54
|
+
team = async_to_sync(self.service.load_from_db)(team.entity_id)
|
|
55
|
+
team.remove_member('alice')
|
|
56
|
+
with kernel_internal_context():
|
|
57
|
+
async_to_sync(self.service.save_entity)(team, None)
|
|
58
|
+
|
|
59
|
+
self.assertFalse(async_to_sync(self.adapter.allows)(self.alice, Read(), self.scope))
|
|
60
|
+
|
|
61
|
+
def test_lockout_protects_a_subclass(self):
|
|
62
|
+
team = self._team('alice')
|
|
63
|
+
_make_grant(self.scope, team.entity_id, 'admin')
|
|
64
|
+
|
|
65
|
+
existing = async_to_sync(self.service.load_from_db)(team.entity_id)
|
|
66
|
+
emptied = async_to_sync(self.service.load_from_db)(team.entity_id)
|
|
67
|
+
emptied.remove_member('alice')
|
|
68
|
+
|
|
69
|
+
with self.assertRaises(Forbidden):
|
|
70
|
+
async_to_sync(self.adapter.check_save)(emptied, existing)
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"""Step 9: AccessPort sync-support methods (`granted_resources`, `scopes`,
|
|
2
|
+
`covers`) - the queries the broadcaster uses to route updates, as opposed to
|
|
3
|
+
the decision methods in test_default_adapter.py."""
|
|
4
|
+
import itertools
|
|
5
|
+
from types import SimpleNamespace
|
|
6
|
+
|
|
7
|
+
from asgiref.sync import async_to_sync
|
|
8
|
+
from django.test import TestCase
|
|
9
|
+
|
|
10
|
+
from graphcore.types.identity import Principal
|
|
11
|
+
from graphcore.domain.entity.Entity import Entity
|
|
12
|
+
from graphcore.domain.entity.grant.Grant import Grant
|
|
13
|
+
from graphcore.domain.entity.group.Group import Group
|
|
14
|
+
from graphcore.persistence.tests.fixtures import make, persist
|
|
15
|
+
from graphcore.registry.registry import DEFAULT_REGISTRY
|
|
16
|
+
from graphcore.runtime import django_runtime
|
|
17
|
+
|
|
18
|
+
TEST_REGISTRY = DEFAULT_REGISTRY.fork_open()
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _register(name: str, shareable: bool = False) -> str:
|
|
22
|
+
cls = type(name, (Entity,), {})
|
|
23
|
+
TEST_REGISTRY.entities.register_entity(cls, app_label='synctest')
|
|
24
|
+
if shareable:
|
|
25
|
+
TEST_REGISTRY.policy.define(cls, shareable=True)
|
|
26
|
+
return TEST_REGISTRY.entities.get_entity_type_id(cls)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _make_entity(entity_type_id: str, parent_id: str = None, owner: str = None) -> str:
|
|
30
|
+
"""Writes straight through the repository, bypassing `EntityService`."""
|
|
31
|
+
entity = make(TEST_REGISTRY.entities.get_entity_class(entity_type_id), TEST_REGISTRY)
|
|
32
|
+
entity.parent_id = parent_id
|
|
33
|
+
entity.owner = owner
|
|
34
|
+
persist(entity, TEST_REGISTRY)
|
|
35
|
+
return entity.entity_id
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _make_grant(resource_id: str, subject_id: str, role_name: str) -> str:
|
|
39
|
+
grant = make(Grant, TEST_REGISTRY)
|
|
40
|
+
grant.parent_id = resource_id
|
|
41
|
+
grant.subject_id = subject_id
|
|
42
|
+
grant.role_name = role_name
|
|
43
|
+
persist(grant, TEST_REGISTRY)
|
|
44
|
+
return grant.entity_id
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class SyncSupportTestCase(TestCase):
|
|
48
|
+
def setUp(self):
|
|
49
|
+
runtime = django_runtime(TEST_REGISTRY)
|
|
50
|
+
self.adapter = runtime.access
|
|
51
|
+
self.deployment_id = runtime.deployment_entity_id
|
|
52
|
+
self.alice = Principal(principal_entity_id='alice')
|
|
53
|
+
self.bob = Principal(principal_entity_id='bob')
|
|
54
|
+
|
|
55
|
+
def granted_resources(self, principal):
|
|
56
|
+
# Every principal holds `member` on the deployment through PUBLIC.
|
|
57
|
+
return async_to_sync(self.adapter.granted_resources)(principal) - {self.deployment_id}
|
|
58
|
+
|
|
59
|
+
def scopes(self, entity):
|
|
60
|
+
return async_to_sync(self.adapter.scopes)(entity.entity_id, entity.ancestor_ids)
|
|
61
|
+
|
|
62
|
+
def covers(self, subject_id, principal_ids):
|
|
63
|
+
return async_to_sync(self.adapter.covers)(subject_id, principal_ids)
|
|
64
|
+
|
|
65
|
+
class GrantedResourcesTests(SyncSupportTestCase):
|
|
66
|
+
def test_every_principal_is_granted_the_deployment_through_public(self):
|
|
67
|
+
self.assertIn(self.deployment_id, async_to_sync(self.adapter.granted_resources)(self.bob))
|
|
68
|
+
|
|
69
|
+
def test_owner_principals_are_returned_for_requested_resources(self):
|
|
70
|
+
scope_type = _register('OwnerSubjectScope', shareable=True)
|
|
71
|
+
owned_id = _make_entity(scope_type, owner='alice')
|
|
72
|
+
other_owned_id = _make_entity(scope_type, owner='carol')
|
|
73
|
+
_make_entity(scope_type, owner='bob')
|
|
74
|
+
|
|
75
|
+
self.assertEqual(
|
|
76
|
+
async_to_sync(self.adapter.owner_principals)({owned_id, other_owned_id}),
|
|
77
|
+
{'alice', 'carol'},
|
|
78
|
+
)
|
|
79
|
+
self.assertNotIn('bob', async_to_sync(self.adapter.owner_principals)({owned_id, other_owned_id}))
|
|
80
|
+
|
|
81
|
+
def test_direct_grant_is_included(self):
|
|
82
|
+
scope_type = _register('GRScopeDirect', shareable=True)
|
|
83
|
+
scope_id = _make_entity(scope_type)
|
|
84
|
+
_make_grant(scope_id, 'alice', 'viewer')
|
|
85
|
+
|
|
86
|
+
self.assertEqual(self.granted_resources(self.alice), {scope_id})
|
|
87
|
+
|
|
88
|
+
def test_via_group_grant_is_included(self):
|
|
89
|
+
scope_type = _register('GRScopeGroup', shareable=True)
|
|
90
|
+
scope_id = _make_entity(scope_type)
|
|
91
|
+
|
|
92
|
+
group = make(Group, TEST_REGISTRY)
|
|
93
|
+
group.name = 'Engineering'
|
|
94
|
+
group.add_member('alice')
|
|
95
|
+
persist(group, TEST_REGISTRY)
|
|
96
|
+
_make_grant(scope_id, group.entity_id, 'editor')
|
|
97
|
+
|
|
98
|
+
self.adapter.cache.set(
|
|
99
|
+
self.adapter._subject_groups_cache_key('alice'),
|
|
100
|
+
[group.entity_id],
|
|
101
|
+
timeout=300,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
self.assertEqual(self.granted_resources(self.alice), {scope_id})
|
|
105
|
+
|
|
106
|
+
def test_ungranted_principal_gets_nothing(self):
|
|
107
|
+
scope_type = _register('GRScopeNone', shareable=True)
|
|
108
|
+
scope_id = _make_entity(scope_type)
|
|
109
|
+
_make_grant(scope_id, 'alice', 'viewer')
|
|
110
|
+
|
|
111
|
+
self.assertEqual(self.granted_resources(self.bob), set())
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class ScopesTests(SyncSupportTestCase):
|
|
115
|
+
def test_includes_entity_and_shareable_ancestors_only(self):
|
|
116
|
+
scope_type = _register('ScopesScope', shareable=True)
|
|
117
|
+
folder_type = _register('ScopesFolder') # non-shareable intermediate
|
|
118
|
+
scope_id = _make_entity(scope_type)
|
|
119
|
+
folder_id = _make_entity(folder_type, parent_id=scope_id)
|
|
120
|
+
|
|
121
|
+
entity_id = _make_entity(folder_type, parent_id=folder_id)
|
|
122
|
+
entity = async_to_sync(self.adapter.repository.load)(entity_id)
|
|
123
|
+
|
|
124
|
+
self.assertEqual(self.scopes(entity), {entity_id, scope_id})
|
|
125
|
+
|
|
126
|
+
def test_works_from_last_known_ancestry_for_a_deleted_entity(self):
|
|
127
|
+
"""No row needs to exist for `entity_id` itself - `scopes()` reads the
|
|
128
|
+
ancestry the caller hands it, so a just-deleted entity can still fan
|
|
129
|
+
out to the scopes that covered it."""
|
|
130
|
+
scope_type = _register('ScopesDeletedScope', shareable=True)
|
|
131
|
+
scope_id = _make_entity(scope_type)
|
|
132
|
+
|
|
133
|
+
deleted = SimpleNamespace(entity_id='deleted-entity-id', ancestor_ids=(scope_id,))
|
|
134
|
+
|
|
135
|
+
self.assertEqual(self.scopes(deleted), {'deleted-entity-id', scope_id})
|
|
136
|
+
|
|
137
|
+
def test_entity_with_no_ancestors_is_its_own_only_scope(self):
|
|
138
|
+
lonely = SimpleNamespace(entity_id='lonely-entity', ancestor_ids=())
|
|
139
|
+
|
|
140
|
+
self.assertEqual(self.scopes(lonely), {'lonely-entity'})
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
class CoversTests(SyncSupportTestCase):
|
|
144
|
+
def test_direct_subject_matches_itself(self):
|
|
145
|
+
self.assertEqual(self.covers('alice', ['alice', 'bob']), {'alice'})
|
|
146
|
+
|
|
147
|
+
def test_group_subject_matches_its_current_members(self):
|
|
148
|
+
group = make(Group, TEST_REGISTRY)
|
|
149
|
+
group.name = 'Engineering'
|
|
150
|
+
group.add_member('alice')
|
|
151
|
+
persist(group, TEST_REGISTRY)
|
|
152
|
+
|
|
153
|
+
self.assertEqual(self.covers(group.entity_id, ['alice', 'bob']), {'alice'})
|
|
154
|
+
|
|
155
|
+
def test_group_subject_does_not_match_non_members(self):
|
|
156
|
+
group = make(Group, TEST_REGISTRY)
|
|
157
|
+
group.name = 'Empty'
|
|
158
|
+
persist(group, TEST_REGISTRY)
|
|
159
|
+
|
|
160
|
+
self.assertEqual(self.covers(group.entity_id, ['alice', 'bob']), set())
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
_SCOPE_IDS = itertools.count()
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class HoldersTests(SyncSupportTestCase):
|
|
167
|
+
def setUp(self):
|
|
168
|
+
super().setUp()
|
|
169
|
+
self.scope_id = _make_entity(_register(f'HoldersScope{next(_SCOPE_IDS)}', shareable=True), owner='owner')
|
|
170
|
+
|
|
171
|
+
def holders(self, perm):
|
|
172
|
+
return async_to_sync(self.adapter.holders)(perm, {self.scope_id})
|
|
173
|
+
|
|
174
|
+
def test_a_principal_subject_whose_role_allows_the_perm(self):
|
|
175
|
+
from graphcore.types.access import ManageAccess
|
|
176
|
+
|
|
177
|
+
_make_grant(self.scope_id, 'alice', 'admin')
|
|
178
|
+
_make_grant(self.scope_id, 'bob', 'viewer')
|
|
179
|
+
|
|
180
|
+
self.assertEqual(self.holders(ManageAccess()), ({'owner', 'alice'}, False))
|
|
181
|
+
|
|
182
|
+
def test_a_group_subject_expands_to_its_members(self):
|
|
183
|
+
from graphcore.types.access import ManageAccess
|
|
184
|
+
|
|
185
|
+
group = make(Group, TEST_REGISTRY)
|
|
186
|
+
group.name = 'Admins'
|
|
187
|
+
group.add_member('alice')
|
|
188
|
+
group.add_member('bob')
|
|
189
|
+
persist(group, TEST_REGISTRY)
|
|
190
|
+
_make_grant(self.scope_id, group.entity_id, 'admin')
|
|
191
|
+
|
|
192
|
+
self.assertEqual(self.holders(ManageAccess()), ({'owner', 'alice', 'bob'}, False))
|
|
193
|
+
|
|
194
|
+
def test_a_public_subject_means_everyone(self):
|
|
195
|
+
from graphcore.types.access import Read
|
|
196
|
+
from graphcore.types.identity import PUBLIC
|
|
197
|
+
|
|
198
|
+
_make_grant(self.scope_id, PUBLIC, 'viewer')
|
|
199
|
+
|
|
200
|
+
self.assertTrue(self.holders(Read())[1])
|
|
201
|
+
|
|
202
|
+
def test_the_owner_holds_only_what_admin_allows(self):
|
|
203
|
+
from graphcore.types.access import ManageAccess, Perm
|
|
204
|
+
|
|
205
|
+
class _Sign(Perm):
|
|
206
|
+
admin_implied = False
|
|
207
|
+
|
|
208
|
+
self.assertEqual(self.holders(ManageAccess()), ({'owner'}, False))
|
|
209
|
+
self.assertEqual(self.holders(_Sign()), (set(), False))
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""The kernel's own access definitions: its built-in roles and the group
|
|
2
|
+
that administers the deployment.
|
|
3
|
+
|
|
4
|
+
Depends only on ``graphcore.types.access``, so it is safe to import before
|
|
5
|
+
``django.setup()``. See ``docs/AUTHORIZATION_TECHNICAL_TDD.md``.
|
|
6
|
+
"""
|
|
7
|
+
from graphcore.types.access import Create, Delete, ManageAccess, Read, Role, Write
|
|
8
|
+
|
|
9
|
+
VIEWER = Role('viewer', perms=frozenset({Read()}), description='Can view')
|
|
10
|
+
EDITOR = Role(
|
|
11
|
+
'editor', perms=frozenset({Read(), Write(), Delete(), Create()}),
|
|
12
|
+
description='Can view, edit, delete, and create inside',
|
|
13
|
+
)
|
|
14
|
+
ADMIN = Role(
|
|
15
|
+
'admin', perms=frozenset({Read(), Write(), Delete(), ManageAccess()}),
|
|
16
|
+
description='Can do everything, including managing access',
|
|
17
|
+
)
|
|
18
|
+
MEMBER = Role(
|
|
19
|
+
'member', perms=frozenset({Read(), Create()}),
|
|
20
|
+
description='Can create top-level entities in this deployment',
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
DEFAULT_ROLES = (VIEWER, EDITOR, ADMIN)
|
|
24
|
+
|
|
25
|
+
ADMINS_GROUP_KEY = 'graphcore.admins'
|
|
26
|
+
"""Key of the kernel-seeded group whose members administer the deployment."""
|