This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package creator_authority_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.cin.su/m/Assistant/contracts/authority"
|
||||
"git.cin.su/m/Assistant/contracts/identity"
|
||||
authoritydomain "git.cin.su/m/Assistant/modules/authority/domain"
|
||||
identitydomain "git.cin.su/m/Assistant/modules/identity/domain"
|
||||
"git.cin.su/m/Assistant/platform/ids"
|
||||
)
|
||||
|
||||
func TestCreatorRequiresDistinctActiveBindingAndGlobalGrant(t *testing.T) {
|
||||
binding := identity.PrincipalBinding{ActorID: identity.ActorID(ids.ID("creator-actor")), PrincipalID: identity.PrincipalID(ids.ID("creator-principal")), Active: true}
|
||||
scope := authority.Scope{ID: authority.ScopeID(ids.ID("all-domovoy")), Label: "All Domovoy scopes", Global: true}
|
||||
grant := authority.AuthorityGrant{ID: authority.GrantID(ids.ID("creator-grant")), ActorID: binding.ActorID, PrincipalID: binding.PrincipalID, ScopeID: scope.ID, Class: authority.GrantClassCreator, Revision: 1, Active: true}
|
||||
if err := identitydomain.ValidateCreatorBinding(binding); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := authoritydomain.ValidateCreatorGrant(binding, scope, grant); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
grant.Active = false
|
||||
if err := authoritydomain.ValidateCreatorGrant(binding, scope, grant); err == nil {
|
||||
t.Fatal("revoked creator grant was accepted")
|
||||
}
|
||||
grant.Active = true
|
||||
scope.Global = false
|
||||
if err := authoritydomain.ValidateCreatorGrant(binding, scope, grant); err == nil {
|
||||
t.Fatal("non-global creator grant was accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user