MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / test_delegation_allows

Function test_delegation_allows

atomic-identity/src/delegation.rs:859–888  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

857
858 #[test]
859 fn test_delegation_allows() {
860 let (user, agent) = create_test_identities();
861 let scope = DelegationScope::builder()
862 .permission(DelegationPermission::Read)
863 .permission(DelegationPermission::Push)
864 .server("https://atomic.storage")
865 .project("acme/*")
866 .build();
867 let delegation = Delegation::new(&user, &agent, scope).expires_in(Duration::days(30));
868
869 let ok = ResourceRef::new()
870 .server("https://atomic.storage")
871 .project("acme/api");
872 assert!(delegation.allows(DelegationPermission::Push, &ok));
873 assert!(delegation.allows(DelegationPermission::Read, &ok));
874 // Permission not granted.
875 assert!(!delegation.allows(DelegationPermission::Admin, &ok));
876 // Project out of scope.
877 assert!(!delegation.allows(
878 DelegationPermission::Push,
879 &ResourceRef::new().project("other/api")
880 ));
881 // Right project, wrong server.
882 assert!(!delegation.allows(
883 DelegationPermission::Push,
884 &ResourceRef::new()
885 .server("https://staging.atomic.storage")
886 .project("acme/api")
887 ));
888 }
889
890 #[test]
891 fn test_expired_delegation_allows_nothing() {

Callers

nothing calls this directly

Calls 6

create_test_identitiesFunction · 0.85
projectMethod · 0.80
serverMethod · 0.80
permissionMethod · 0.80
expires_inMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected