()
| 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() { |
nothing calls this directly
no test coverage detected