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,543 @@
|
|
|
1
|
+
from asgiref.sync import async_to_sync
|
|
2
|
+
from django.test import TestCase
|
|
3
|
+
|
|
4
|
+
from graphcore.types.access import Delete, ManageAccess, Perm, Read, Write
|
|
5
|
+
from graphcore.auth.authz.defaults import DEFAULT_ROLES
|
|
6
|
+
from graphcore.types.identity import PUBLIC
|
|
7
|
+
from graphcore.types.identity import Principal
|
|
8
|
+
from graphcore.types.query import AllOf, InValues
|
|
9
|
+
from graphcore.persistence.django.models import EntityModel
|
|
10
|
+
from graphcore.persistence.tests.fixtures import make, persist
|
|
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.registry.registry import DEFAULT_REGISTRY
|
|
15
|
+
from graphcore.runtime import django_runtime
|
|
16
|
+
|
|
17
|
+
TEST_DIRECTORY = DEFAULT_REGISTRY.fork_open()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _register(name: str, shareable: bool = False) -> str:
|
|
21
|
+
"""Register a throwaway type under a unique name, optionally shareable,
|
|
22
|
+
and return its entity_type_id."""
|
|
23
|
+
cls = type(name, (Entity,), {})
|
|
24
|
+
TEST_DIRECTORY.entities.register_entity(cls, app_label='accesstest')
|
|
25
|
+
if shareable:
|
|
26
|
+
TEST_DIRECTORY.policy.define(cls, shareable=True)
|
|
27
|
+
return TEST_DIRECTORY.entities.get_entity_type_id(cls)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _make_entity(entity_type_id: str, owner: str = None, parent_id: str = None) -> str:
|
|
31
|
+
"""Writes straight through the repository, bypassing `EntityService` -
|
|
32
|
+
so no permission check and no access hooks, but `ancestor_ids` is
|
|
33
|
+
maintained, since that is the repository's own invariant."""
|
|
34
|
+
entity = make(TEST_DIRECTORY.entities.get_entity_class(entity_type_id), TEST_DIRECTORY)
|
|
35
|
+
entity.owner = owner
|
|
36
|
+
entity.parent_id = parent_id
|
|
37
|
+
persist(entity, TEST_DIRECTORY)
|
|
38
|
+
return entity.entity_id
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _make_grant(resource_id: str, subject_id: str, role_name: str) -> str:
|
|
42
|
+
grant = make(Grant, TEST_DIRECTORY)
|
|
43
|
+
grant.parent_id = resource_id
|
|
44
|
+
grant.subject_id = subject_id
|
|
45
|
+
grant.role_name = role_name
|
|
46
|
+
persist(grant, TEST_DIRECTORY)
|
|
47
|
+
return grant.entity_id
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class Publish(Perm):
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Sign(Perm):
|
|
55
|
+
"""A distinct duty: not implied by Admin."""
|
|
56
|
+
admin_implied = False
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class AccessAdapterTestCase(TestCase):
|
|
60
|
+
def setUp(self):
|
|
61
|
+
self.runtime = django_runtime(TEST_DIRECTORY)
|
|
62
|
+
self.adapter = self.runtime.access
|
|
63
|
+
self.alice = Principal(principal_entity_id='alice')
|
|
64
|
+
self.bob = Principal(principal_entity_id='bob')
|
|
65
|
+
|
|
66
|
+
def allows(self, principal, perm, entity_id):
|
|
67
|
+
return async_to_sync(self.adapter.allows)(principal, perm, entity_id)
|
|
68
|
+
|
|
69
|
+
def read_filter(self, principal, entity_ids, perm=Read()):
|
|
70
|
+
"""The port's predicate for `perm`, resolved against a candidate set."""
|
|
71
|
+
predicate = async_to_sync(self.adapter.read_filters)(principal, [perm])[perm]
|
|
72
|
+
return async_to_sync(self.runtime.repository.list_ids)(AllOf((
|
|
73
|
+
InValues('entity_id', set(entity_ids)), predicate,
|
|
74
|
+
)))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class DirectGrantRoleTests(AccessAdapterTestCase):
|
|
78
|
+
def setUp(self):
|
|
79
|
+
super().setUp()
|
|
80
|
+
self.scope_type = _register('DirectScope', shareable=True)
|
|
81
|
+
self.scope_id = _make_entity(self.scope_type)
|
|
82
|
+
|
|
83
|
+
def test_viewer_can_read_only(self):
|
|
84
|
+
_make_grant(self.scope_id, 'alice', 'viewer')
|
|
85
|
+
|
|
86
|
+
self.assertTrue(self.allows(self.alice, Read(), self.scope_id))
|
|
87
|
+
self.assertFalse(self.allows(self.alice, Write(), self.scope_id))
|
|
88
|
+
self.assertFalse(self.allows(self.alice, Delete(), self.scope_id))
|
|
89
|
+
self.assertFalse(self.allows(self.alice, ManageAccess(), self.scope_id))
|
|
90
|
+
|
|
91
|
+
def test_editor_can_read_write_delete_not_manage_access(self):
|
|
92
|
+
_make_grant(self.scope_id, 'alice', 'editor')
|
|
93
|
+
|
|
94
|
+
self.assertTrue(self.allows(self.alice, Read(), self.scope_id))
|
|
95
|
+
self.assertTrue(self.allows(self.alice, Write(), self.scope_id))
|
|
96
|
+
self.assertTrue(self.allows(self.alice, Delete(), self.scope_id))
|
|
97
|
+
self.assertFalse(self.allows(self.alice, ManageAccess(), self.scope_id))
|
|
98
|
+
|
|
99
|
+
def test_admin_can_do_everything(self):
|
|
100
|
+
_make_grant(self.scope_id, 'alice', 'admin')
|
|
101
|
+
|
|
102
|
+
for perm in (Read(), Write(), Delete(), ManageAccess()):
|
|
103
|
+
self.assertTrue(self.allows(self.alice, perm, self.scope_id))
|
|
104
|
+
|
|
105
|
+
def test_admin_implies_app_perm_by_default(self):
|
|
106
|
+
_make_grant(self.scope_id, 'alice', 'admin')
|
|
107
|
+
|
|
108
|
+
self.assertTrue(self.allows(self.alice, Publish(), self.scope_id))
|
|
109
|
+
|
|
110
|
+
def test_admin_does_not_imply_opted_out_perm(self):
|
|
111
|
+
_make_grant(self.scope_id, 'alice', 'admin')
|
|
112
|
+
|
|
113
|
+
self.assertFalse(self.allows(self.alice, Sign(), self.scope_id))
|
|
114
|
+
|
|
115
|
+
def test_editor_does_not_get_app_perm(self):
|
|
116
|
+
_make_grant(self.scope_id, 'alice', 'editor')
|
|
117
|
+
|
|
118
|
+
self.assertFalse(self.allows(self.alice, Publish(), self.scope_id))
|
|
119
|
+
|
|
120
|
+
def test_no_grant_is_denied(self):
|
|
121
|
+
self.assertFalse(self.allows(self.bob, Read(), self.scope_id))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
class InheritanceTests(AccessAdapterTestCase):
|
|
125
|
+
def setUp(self):
|
|
126
|
+
super().setUp()
|
|
127
|
+
self.scope_type = _register('InheritScope', shareable=True)
|
|
128
|
+
self.folder_type = _register('InheritFolder', shareable=False)
|
|
129
|
+
self.scope_id = _make_entity(self.scope_type)
|
|
130
|
+
self.folder_id = _make_entity(self.folder_type, parent_id=self.scope_id)
|
|
131
|
+
self.child_id = _make_entity(self.folder_type, parent_id=self.folder_id)
|
|
132
|
+
|
|
133
|
+
def test_grant_on_scope_covers_grandchild_through_non_shareable_intermediate(self):
|
|
134
|
+
_make_grant(self.scope_id, 'alice', 'viewer')
|
|
135
|
+
|
|
136
|
+
self.assertTrue(self.allows(self.alice, Read(), self.folder_id))
|
|
137
|
+
self.assertTrue(self.allows(self.alice, Read(), self.child_id))
|
|
138
|
+
|
|
139
|
+
def test_entity_created_after_the_grant_is_covered(self):
|
|
140
|
+
_make_grant(self.scope_id, 'alice', 'editor')
|
|
141
|
+
late_child = _make_entity(self.folder_type, parent_id=self.folder_id)
|
|
142
|
+
|
|
143
|
+
self.assertTrue(self.allows(self.alice, Write(), late_child))
|
|
144
|
+
|
|
145
|
+
def test_union_only_more_specific_grant_does_not_shrink_broader_one(self):
|
|
146
|
+
"""A viewer grant on the child and an editor grant on the scope
|
|
147
|
+
union to editor-level access on the child - the child's own grant
|
|
148
|
+
never narrows what the scope confers."""
|
|
149
|
+
_make_grant(self.scope_id, 'alice', 'editor')
|
|
150
|
+
_make_grant(self.child_id, 'alice', 'viewer')
|
|
151
|
+
|
|
152
|
+
self.assertTrue(self.allows(self.alice, Write(), self.child_id))
|
|
153
|
+
|
|
154
|
+
def test_direct_grant_on_non_scope_entity_is_additive(self):
|
|
155
|
+
"""A direct grant on a non-scope (non-shareable) entity works even
|
|
156
|
+
with no covering scope grant at all."""
|
|
157
|
+
_make_grant(self.folder_id, 'alice', 'editor')
|
|
158
|
+
|
|
159
|
+
self.assertTrue(self.allows(self.alice, Write(), self.folder_id))
|
|
160
|
+
# Does not leak to a sibling with no grant of its own.
|
|
161
|
+
sibling = _make_entity(self.folder_type, parent_id=self.scope_id)
|
|
162
|
+
self.assertFalse(self.allows(self.alice, Read(), sibling))
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
class OwnerImplicitAdminTests(AccessAdapterTestCase):
|
|
166
|
+
def setUp(self):
|
|
167
|
+
super().setUp()
|
|
168
|
+
self.scope_type = _register('OwnerScope', shareable=True)
|
|
169
|
+
self.folder_type = _register('OwnerFolder', shareable=False)
|
|
170
|
+
|
|
171
|
+
def test_owner_of_entity_itself_has_admin(self):
|
|
172
|
+
entity_id = _make_entity(self.scope_type, owner='alice')
|
|
173
|
+
|
|
174
|
+
for perm in (Read(), Write(), Delete(), ManageAccess(), Publish()):
|
|
175
|
+
self.assertTrue(self.allows(self.alice, perm, entity_id))
|
|
176
|
+
|
|
177
|
+
def test_owner_is_admin_not_superuser(self):
|
|
178
|
+
entity_id = _make_entity(self.scope_type, owner='alice')
|
|
179
|
+
|
|
180
|
+
self.assertFalse(self.allows(self.alice, Sign(), entity_id))
|
|
181
|
+
|
|
182
|
+
def test_owner_of_ancestor_scope_has_admin_on_descendant(self):
|
|
183
|
+
scope_id = _make_entity(self.scope_type, owner='alice')
|
|
184
|
+
child_id = _make_entity(self.folder_type, parent_id=scope_id)
|
|
185
|
+
|
|
186
|
+
self.assertTrue(self.allows(self.alice, ManageAccess(), child_id))
|
|
187
|
+
|
|
188
|
+
def test_non_owner_gets_nothing_from_ownership(self):
|
|
189
|
+
entity_id = _make_entity(self.scope_type, owner='alice')
|
|
190
|
+
|
|
191
|
+
self.assertFalse(self.allows(self.bob, Read(), entity_id))
|
|
192
|
+
|
|
193
|
+
def test_group_membership_does_not_make_group_id_a_valid_owner(self):
|
|
194
|
+
group = make(Group, TEST_DIRECTORY)
|
|
195
|
+
group.name = 'Engineering'
|
|
196
|
+
group.add_member('alice')
|
|
197
|
+
persist(group, TEST_DIRECTORY)
|
|
198
|
+
self.adapter.cache.set(
|
|
199
|
+
self.adapter._subject_groups_cache_key('alice'),
|
|
200
|
+
[group.entity_id],
|
|
201
|
+
timeout=300,
|
|
202
|
+
)
|
|
203
|
+
entity_id = _make_entity(self.scope_type, owner=group.entity_id)
|
|
204
|
+
|
|
205
|
+
self.assertFalse(self.allows(self.alice, Read(), entity_id))
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
class PublicPermsTests(AccessAdapterTestCase):
|
|
209
|
+
def test_public_perms_grant_read_with_no_stored_grant(self):
|
|
210
|
+
plain_type = _register('PublicPermType')
|
|
211
|
+
entity_cls = TEST_DIRECTORY.entities.get_entity_class(plain_type)
|
|
212
|
+
TEST_DIRECTORY.policy.define(entity_cls, public=[Read()])
|
|
213
|
+
entity_id = _make_entity(plain_type)
|
|
214
|
+
|
|
215
|
+
self.assertTrue(self.allows(self.bob, Read(), entity_id))
|
|
216
|
+
self.assertFalse(self.allows(self.bob, Write(), entity_id))
|
|
217
|
+
|
|
218
|
+
def test_public_subject_grant_covers_every_authenticated_principal(self):
|
|
219
|
+
scope_type = _register('PublicSubjectScope', shareable=True)
|
|
220
|
+
entity_id = _make_entity(scope_type)
|
|
221
|
+
_make_grant(entity_id, PUBLIC, 'viewer')
|
|
222
|
+
|
|
223
|
+
self.assertTrue(self.allows(self.alice, Read(), entity_id))
|
|
224
|
+
self.assertTrue(self.allows(self.bob, Read(), entity_id))
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
class GroupGrantTests(AccessAdapterTestCase):
|
|
228
|
+
def setUp(self):
|
|
229
|
+
super().setUp()
|
|
230
|
+
self.scope_type = _register('GroupScope', shareable=True)
|
|
231
|
+
self.scope_id = _make_entity(self.scope_type)
|
|
232
|
+
|
|
233
|
+
self.group = make(Group, TEST_DIRECTORY)
|
|
234
|
+
self.group.name = 'Engineering'
|
|
235
|
+
self.group.add_member('alice')
|
|
236
|
+
persist(self.group, TEST_DIRECTORY)
|
|
237
|
+
|
|
238
|
+
_make_grant(self.scope_id, self.group.entity_id, 'editor')
|
|
239
|
+
|
|
240
|
+
# The reverse member_ids lookup uses a Postgres-only JSONB operator
|
|
241
|
+
# (`?`), unavailable on the SQLite test backend - warm the adapter's
|
|
242
|
+
# cache directly rather than mocking the connection, matching how
|
|
243
|
+
# `test_EntityService.py` isolates this same query elsewhere.
|
|
244
|
+
self.adapter.cache.set(
|
|
245
|
+
self.adapter._subject_groups_cache_key('alice'),
|
|
246
|
+
[self.group.entity_id],
|
|
247
|
+
timeout=300,
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
def test_member_covered_by_group_grant(self):
|
|
251
|
+
self.assertTrue(self.allows(self.alice, Write(), self.scope_id))
|
|
252
|
+
|
|
253
|
+
def test_non_member_is_denied(self):
|
|
254
|
+
self.assertFalse(self.allows(self.bob, Write(), self.scope_id))
|
|
255
|
+
|
|
256
|
+
def test_nested_group_membership_is_not_expanded(self):
|
|
257
|
+
"""A group whose only membership is via another group (member-of-
|
|
258
|
+
member) is out of v1 - the outer group is not expanded."""
|
|
259
|
+
outer_group = make(Group, TEST_DIRECTORY)
|
|
260
|
+
outer_group.name = 'AllEngineering'
|
|
261
|
+
outer_group.add_member(self.group.entity_id)
|
|
262
|
+
persist(outer_group, TEST_DIRECTORY)
|
|
263
|
+
_make_grant(self.scope_id, outer_group.entity_id, 'admin')
|
|
264
|
+
|
|
265
|
+
# alice is a member of `self.group`, not of `outer_group` directly,
|
|
266
|
+
# so the outer group's admin grant does not reach her - her access
|
|
267
|
+
# still comes only from the direct editor grant to `self.group`.
|
|
268
|
+
self.assertTrue(self.allows(self.alice, Write(), self.scope_id))
|
|
269
|
+
self.assertFalse(self.allows(self.alice, ManageAccess(), self.scope_id))
|
|
270
|
+
|
|
271
|
+
def test_member_ids_on_non_group_entity_are_ignored(self):
|
|
272
|
+
non_group_type = _register('RosterLikeContent')
|
|
273
|
+
row = EntityModel.objects.create(
|
|
274
|
+
entity_type_id=non_group_type,
|
|
275
|
+
|
|
276
|
+
attributes={'member_ids': ['alice']},
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
group_ids = async_to_sync(self.adapter.get_subject_group_ids)('alice')
|
|
280
|
+
|
|
281
|
+
self.assertNotIn(str(row.entity_id), group_ids)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
class ReadFilterCandidateTests(AccessAdapterTestCase):
|
|
285
|
+
def test_returns_exactly_the_readable_subset(self):
|
|
286
|
+
scope_type = _register('FilterScope', shareable=True)
|
|
287
|
+
readable = _make_entity(scope_type, owner='alice')
|
|
288
|
+
unreadable = _make_entity(scope_type)
|
|
289
|
+
|
|
290
|
+
result = self.read_filter(self.alice, [readable, unreadable])
|
|
291
|
+
|
|
292
|
+
self.assertEqual(result, {readable})
|
|
293
|
+
|
|
294
|
+
def test_one_call_answers_several_perms(self):
|
|
295
|
+
scope_type = _register('FilterPermsScope', shareable=True)
|
|
296
|
+
scope = _make_entity(scope_type)
|
|
297
|
+
_make_grant(scope, 'alice', 'viewer')
|
|
298
|
+
|
|
299
|
+
filters = async_to_sync(self.adapter.read_filters)(self.alice, [Read(), ManageAccess()])
|
|
300
|
+
|
|
301
|
+
self.assertEqual(set(filters), {Read(), ManageAccess()})
|
|
302
|
+
self.assertEqual(self.read_filter(self.alice, [scope], Read()), {scope})
|
|
303
|
+
self.assertEqual(self.read_filter(self.alice, [scope], ManageAccess()), set())
|
|
304
|
+
|
|
305
|
+
def test_one_principal_many_candidates_under_one_hub(self):
|
|
306
|
+
scope_type = _register('FilterHubScope', shareable=True)
|
|
307
|
+
folder_type = _register('FilterHubFolder')
|
|
308
|
+
hub = _make_entity(scope_type)
|
|
309
|
+
_make_grant(hub, 'alice', 'viewer')
|
|
310
|
+
children = [_make_entity(folder_type, parent_id=hub) for _ in range(3)]
|
|
311
|
+
|
|
312
|
+
self.assertEqual(self.read_filter(self.alice, children), set(children))
|
|
313
|
+
|
|
314
|
+
def test_mixed_readable_and_unreadable_returns_exact_subset(self):
|
|
315
|
+
scope_type = _register('FilterMixedScope', shareable=True)
|
|
316
|
+
granted_scope = _make_entity(scope_type)
|
|
317
|
+
_make_grant(granted_scope, 'alice', 'viewer')
|
|
318
|
+
ungranted_scope = _make_entity(scope_type)
|
|
319
|
+
owned = _make_entity(scope_type, owner='alice')
|
|
320
|
+
|
|
321
|
+
result = self.read_filter(self.alice, [granted_scope, ungranted_scope, owned])
|
|
322
|
+
|
|
323
|
+
self.assertEqual(result, {granted_scope, owned})
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
class ReadFilterTests(AccessAdapterTestCase):
|
|
327
|
+
def test_restricts_to_direct_inherited_owned_and_public(self):
|
|
328
|
+
scope_type = _register('RestrictScope', shareable=True)
|
|
329
|
+
folder_type = _register('RestrictFolder')
|
|
330
|
+
|
|
331
|
+
direct = _make_entity(scope_type)
|
|
332
|
+
_make_grant(direct, 'alice', 'viewer')
|
|
333
|
+
hub = _make_entity(scope_type)
|
|
334
|
+
_make_grant(hub, 'alice', 'viewer')
|
|
335
|
+
inherited = _make_entity(folder_type, parent_id=hub)
|
|
336
|
+
owned = _make_entity(scope_type, owner='alice')
|
|
337
|
+
unrelated = _make_entity(scope_type)
|
|
338
|
+
|
|
339
|
+
result = self.read_filter(self.alice, [direct, inherited, owned, unrelated])
|
|
340
|
+
|
|
341
|
+
self.assertEqual(result, {direct, inherited, owned})
|
|
342
|
+
self.assertNotIn(unrelated, result)
|
|
343
|
+
|
|
344
|
+
def test_role_without_read_does_not_admit(self):
|
|
345
|
+
from graphcore.types.access import Role
|
|
346
|
+
|
|
347
|
+
cls = type('RestrictNoReadScope', (Entity,), {})
|
|
348
|
+
TEST_DIRECTORY.entities.register_entity(cls, app_label='accesstest')
|
|
349
|
+
scope_type = TEST_DIRECTORY.entities.get_entity_type_id(cls)
|
|
350
|
+
no_read = Role('write_only', perms=frozenset({Write()}))
|
|
351
|
+
TEST_DIRECTORY.policy.define(cls, shareable=True, roles=[*DEFAULT_ROLES, no_read])
|
|
352
|
+
|
|
353
|
+
entity_id = _make_entity(scope_type)
|
|
354
|
+
_make_grant(entity_id, 'alice', 'write_only')
|
|
355
|
+
|
|
356
|
+
result = self.read_filter(self.alice, [entity_id])
|
|
357
|
+
|
|
358
|
+
self.assertEqual(result, set())
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
class GrantVisibilityTests(AccessAdapterTestCase):
|
|
362
|
+
"""A grant is read with ManageAccess on the resource it grants on. The
|
|
363
|
+
engine asks for that; the adapter answers only the perm it is asked."""
|
|
364
|
+
|
|
365
|
+
def setUp(self):
|
|
366
|
+
super().setUp()
|
|
367
|
+
scope_type = _register('GrantVisibilityScope', shareable=True)
|
|
368
|
+
self.scope = _make_entity(scope_type, owner='alice')
|
|
369
|
+
self.grant = _make_grant(self.scope, 'bob', 'viewer')
|
|
370
|
+
|
|
371
|
+
def _get(self, principal):
|
|
372
|
+
return async_to_sync(self.runtime.entity_service.get_entities)([self.grant], principal)[self.grant]
|
|
373
|
+
|
|
374
|
+
def test_a_viewer_gets_a_forbidden_tombstone_for_the_grant(self):
|
|
375
|
+
from graphcore.types.entities import Tombstone
|
|
376
|
+
|
|
377
|
+
self.assertTrue(self.allows(self.bob, Read(), self.grant))
|
|
378
|
+
result = self._get(self.bob)
|
|
379
|
+
self.assertIsInstance(result, Tombstone)
|
|
380
|
+
self.assertEqual(result.cause, 'forbidden')
|
|
381
|
+
|
|
382
|
+
def test_a_manager_can_read_the_grant(self):
|
|
383
|
+
self.assertIsInstance(self._get(self.alice), Grant)
|
|
384
|
+
|
|
385
|
+
def test_listing_excludes_grants_for_viewers_and_includes_them_for_managers(self):
|
|
386
|
+
from graphcore.types.entities import EntityFilter
|
|
387
|
+
|
|
388
|
+
def listed(principal):
|
|
389
|
+
page = async_to_sync(self.runtime.entity_service.list_entities)(
|
|
390
|
+
principal, EntityFilter(
|
|
391
|
+
type_ids=frozenset({TEST_DIRECTORY.entities.get_entity_type_id(Grant)}),
|
|
392
|
+
parent_id=self.scope,
|
|
393
|
+
),
|
|
394
|
+
)
|
|
395
|
+
return {entity.entity_id for entity in page.entities}
|
|
396
|
+
|
|
397
|
+
self.assertEqual(listed(self.bob), set())
|
|
398
|
+
self.assertEqual(listed(self.alice), {self.grant})
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
class ReadFilterScenarioTests(AccessAdapterTestCase):
|
|
402
|
+
"""The predicate `list_entities` pushes into storage, over the same
|
|
403
|
+
fixtures `allows` decides on - the two must never disagree."""
|
|
404
|
+
|
|
405
|
+
def setUp(self):
|
|
406
|
+
super().setUp()
|
|
407
|
+
self.scope_type = _register('RFScope', shareable=True)
|
|
408
|
+
self.inner_scope_type = _register('RFInnerScope', shareable=True)
|
|
409
|
+
self.folder_type = _register('RFFolder')
|
|
410
|
+
|
|
411
|
+
def assert_agree(self, principal, entity_id, expected):
|
|
412
|
+
self.assertEqual(self.read_filter(principal, [entity_id]),
|
|
413
|
+
{entity_id} if expected else set())
|
|
414
|
+
self.assertEqual(self.allows(principal, Read(), entity_id), expected)
|
|
415
|
+
|
|
416
|
+
def test_grant_inherits_through_two_shareable_levels(self):
|
|
417
|
+
outer = _make_entity(self.scope_type)
|
|
418
|
+
inner = _make_entity(self.inner_scope_type, parent_id=outer)
|
|
419
|
+
leaf = _make_entity(self.folder_type, parent_id=inner)
|
|
420
|
+
_make_grant(outer, 'alice', 'viewer')
|
|
421
|
+
|
|
422
|
+
for entity_id in (outer, inner, leaf):
|
|
423
|
+
self.assert_agree(self.alice, entity_id, True)
|
|
424
|
+
|
|
425
|
+
def test_a_non_shareable_owned_parent_does_not_propagate(self):
|
|
426
|
+
"""Ownership only reaches descendants through a shareable scope -
|
|
427
|
+
owning a plain folder grants nothing on what it contains."""
|
|
428
|
+
folder = _make_entity(self.folder_type, owner='alice')
|
|
429
|
+
child = _make_entity(self.folder_type, parent_id=folder)
|
|
430
|
+
|
|
431
|
+
self.assert_agree(self.alice, folder, True)
|
|
432
|
+
self.assert_agree(self.alice, child, False)
|
|
433
|
+
|
|
434
|
+
def test_an_owned_shareable_scope_does_propagate(self):
|
|
435
|
+
scope = _make_entity(self.scope_type, owner='alice')
|
|
436
|
+
child = _make_entity(self.folder_type, parent_id=scope)
|
|
437
|
+
|
|
438
|
+
self.assert_agree(self.alice, child, True)
|
|
439
|
+
|
|
440
|
+
def test_a_group_grant_reaches_the_members(self):
|
|
441
|
+
scope = _make_entity(self.scope_type)
|
|
442
|
+
child = _make_entity(self.folder_type, parent_id=scope)
|
|
443
|
+
group = make(Group, TEST_DIRECTORY)
|
|
444
|
+
group.add_member('alice')
|
|
445
|
+
persist(group, TEST_DIRECTORY)
|
|
446
|
+
_make_grant(scope, group.entity_id, 'viewer')
|
|
447
|
+
self.adapter.cache.set(
|
|
448
|
+
self.adapter._subject_groups_cache_key('alice'), [group.entity_id], timeout=300,
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
self.assert_agree(self.alice, child, True)
|
|
452
|
+
self.assert_agree(self.bob, child, False)
|
|
453
|
+
|
|
454
|
+
def test_a_public_grant_reaches_everyone(self):
|
|
455
|
+
scope = _make_entity(self.scope_type)
|
|
456
|
+
child = _make_entity(self.folder_type, parent_id=scope)
|
|
457
|
+
_make_grant(scope, PUBLIC, 'viewer')
|
|
458
|
+
|
|
459
|
+
self.assert_agree(self.alice, child, True)
|
|
460
|
+
self.assert_agree(self.bob, child, True)
|
|
461
|
+
|
|
462
|
+
def test_a_revoked_grant_stops_admitting_immediately(self):
|
|
463
|
+
scope = _make_entity(self.scope_type)
|
|
464
|
+
child = _make_entity(self.folder_type, parent_id=scope)
|
|
465
|
+
grant_id = _make_grant(scope, 'alice', 'viewer')
|
|
466
|
+
self.assert_agree(self.alice, child, True)
|
|
467
|
+
|
|
468
|
+
async_to_sync(self.runtime.repository.delete_many)([grant_id])
|
|
469
|
+
|
|
470
|
+
self.assert_agree(self.alice, child, False)
|
|
471
|
+
|
|
472
|
+
def test_a_role_without_read_does_not_admit(self):
|
|
473
|
+
from graphcore.types.access import Role
|
|
474
|
+
|
|
475
|
+
cls = type('RFWriteOnlyScope', (Entity,), {})
|
|
476
|
+
TEST_DIRECTORY.entities.register_entity(cls, app_label='accesstest')
|
|
477
|
+
scope_type = TEST_DIRECTORY.entities.get_entity_type_id(cls)
|
|
478
|
+
TEST_DIRECTORY.policy.define(
|
|
479
|
+
cls, shareable=True, roles=[*DEFAULT_ROLES, Role('rf_write_only', perms=frozenset({Write()}))],
|
|
480
|
+
)
|
|
481
|
+
scope = _make_entity(scope_type)
|
|
482
|
+
_make_grant(scope, 'alice', 'rf_write_only')
|
|
483
|
+
|
|
484
|
+
self.assert_agree(self.alice, scope, False)
|
|
485
|
+
self.assertTrue(self.allows(self.alice, Write(), scope))
|
|
486
|
+
|
|
487
|
+
def test_moving_a_subtree_moves_the_access_with_it(self):
|
|
488
|
+
granted = _make_entity(self.scope_type)
|
|
489
|
+
ungranted = _make_entity(self.scope_type)
|
|
490
|
+
_make_grant(granted, 'alice', 'viewer')
|
|
491
|
+
|
|
492
|
+
subtree_root = _make_entity(self.folder_type, parent_id=ungranted)
|
|
493
|
+
leaf = _make_entity(self.folder_type, parent_id=subtree_root)
|
|
494
|
+
self.assert_agree(self.alice, leaf, False)
|
|
495
|
+
|
|
496
|
+
repository = self.runtime.repository
|
|
497
|
+
moved = async_to_sync(repository.load)(subtree_root)
|
|
498
|
+
moved.parent_id = granted
|
|
499
|
+
async_to_sync(repository.save)(moved)
|
|
500
|
+
|
|
501
|
+
self.assert_agree(self.alice, leaf, True)
|
|
502
|
+
|
|
503
|
+
def test_moving_out_of_a_granted_scope_removes_access(self):
|
|
504
|
+
granted = _make_entity(self.scope_type)
|
|
505
|
+
elsewhere = _make_entity(self.scope_type)
|
|
506
|
+
_make_grant(granted, 'alice', 'viewer')
|
|
507
|
+
|
|
508
|
+
subtree_root = _make_entity(self.folder_type, parent_id=granted)
|
|
509
|
+
leaf = _make_entity(self.folder_type, parent_id=subtree_root)
|
|
510
|
+
self.assert_agree(self.alice, leaf, True)
|
|
511
|
+
|
|
512
|
+
repository = self.runtime.repository
|
|
513
|
+
moved = async_to_sync(repository.load)(subtree_root)
|
|
514
|
+
moved.parent_id = elsewhere
|
|
515
|
+
async_to_sync(repository.save)(moved)
|
|
516
|
+
|
|
517
|
+
self.assert_agree(self.alice, leaf, False)
|
|
518
|
+
|
|
519
|
+
def test_paging_never_narrows_a_page_in_python(self):
|
|
520
|
+
"""`list_entities` composes the criteria and the access predicate
|
|
521
|
+
into one statement, so every returned page is full until the last."""
|
|
522
|
+
from graphcore.types.entities import EntityFilter
|
|
523
|
+
|
|
524
|
+
scope = _make_entity(self.scope_type)
|
|
525
|
+
_make_grant(scope, 'alice', 'viewer')
|
|
526
|
+
readable = {_make_entity(self.folder_type, parent_id=scope) for _ in range(5)}
|
|
527
|
+
for _ in range(5):
|
|
528
|
+
_make_entity(self.folder_type) # unreadable, interleaved by id
|
|
529
|
+
|
|
530
|
+
service = self.runtime.entity_service
|
|
531
|
+
seen, cursor = [], None
|
|
532
|
+
for _ in range(3):
|
|
533
|
+
page = async_to_sync(service.list_entities)(
|
|
534
|
+
self.alice, EntityFilter(type_ids=frozenset({self.folder_type})),
|
|
535
|
+
cursor=cursor, limit=2,
|
|
536
|
+
)
|
|
537
|
+
seen.extend(entity.entity_id for entity in page.entities)
|
|
538
|
+
cursor = page.next_cursor
|
|
539
|
+
if cursor is None:
|
|
540
|
+
break
|
|
541
|
+
|
|
542
|
+
self.assertEqual(set(seen), readable)
|
|
543
|
+
self.assertIsNone(cursor)
|