public void Initialize_WithTenantAndWithoutUserAndWithoutRoles() { Tenant tenant = _testHelper.CreateTenant("tenant"); Principal principal = PrincipalTestHelper.Create(tenant, null, new Role[0]); Assert.That(principal.Tenant, Is.EqualTo(tenant).Using(DomainObjectHandleComparer.Instance)); Assert.That(principal.User, Is.Null); Assert.That(principal.Roles, Is.Empty); Assert.That(principal.IsNull, Is.False); }
public void Initialize_Empty() { Tenant principalTenant = CreateTenant("principalTenant"); Principal principal = PrincipalTestHelper.Create(principalTenant, null, new Role[0]); SecurityToken token = SecurityToken.Create(principal, null, null, null, Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >()); Assert.That(token.OwningTenant, Is.Null); Assert.That(token.OwningGroup, Is.Null); Assert.That(token.OwningUser, Is.Null); Assert.That(token.AbstractRoles, Is.Empty); }
public void Initialize_WithTenantAndWithoutUserAndWithRoles() { Tenant tenant = _testHelper.CreateTenant("tenant"); Role[] roles = new[] { CreateRole(tenant), CreateRole(tenant) }; Principal principal = PrincipalTestHelper.Create(tenant, null, roles); Assert.That(principal.Tenant, Is.EqualTo(tenant).Using(DomainObjectHandleComparer.Instance)); Assert.That(principal.User, Is.Null); Assert.That(principal.Roles, Is.EquivalentTo(roles).Using(PrincipalRoleComparer.Instance)); Assert.That(principal.IsNull, Is.False); }
public void TokenWithoutPrincipalUser_Matches() { SecurityToken token = SecurityToken.Create( PrincipalTestHelper.Create(_companyHelper.CompanyTenant, null, new Role[0]), _companyHelper.CompanyTenant, null, null, Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >()); SecurityTokenMatcher matcher = new SecurityTokenMatcher(_ace); Assert.That(matcher.MatchesToken(token), Is.True); }
public void TokenWithTenantDifferentFromOwningTenant_DoesNotMatch() { SecurityToken token = SecurityToken.Create( PrincipalTestHelper.Create(TestHelper.CreateTenant("tenant"), null, new Role[0]), _companyHelper.CompanyTenant, null, null, Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >()); SecurityTokenMatcher matcher = new SecurityTokenMatcher(_ace); Assert.That(matcher.MatchesToken(token), Is.False); }
public void TokenWithoutPrincipalRoles_DoesNotMatch() { SecurityToken token = SecurityToken.Create( PrincipalTestHelper.Create(_companyHelper.CompanyTenant, _companyHelper.CarTeamMember, new Role[0]), null, _companyHelper.AustrianCarTeam, null, Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >()); SecurityTokenMatcher matcher = new SecurityTokenMatcher(_ace); Assert.That(matcher.MatchesToken(token), Is.False); }
public void TokenWithoutPrincipalUserButWithPrincipalRole_Matches() { User user = CreateUser(_companyHelper.CompanyTenant, null); Group userGroup = _companyHelper.AustrianProjectsDepartment; Role userRole = TestHelper.CreateRole(user, userGroup, _companyHelper.HeadPosition); SecurityToken token = SecurityToken.Create( PrincipalTestHelper.Create(_companyHelper.CompanyTenant, null, new[] { userRole }), null, userGroup, null, Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >()); SecurityTokenMatcher matcher = new SecurityTokenMatcher(_ace); Assert.That(matcher.MatchesToken(token), Is.True); }
public void TokenWithoutTenantAndOwningTenant_DoesNotMatch() { // Creating a non-null principal with a null Tenant is only possible via reflection. var principal = PrincipalTestHelper.Create(TestHelper.CreateTenant("tenant"), null, new Role[0]); PrivateInvoke.SetNonPublicField(principal, "_tenant", null); SecurityToken token = SecurityToken.Create( principal, _companyHelper.CompanyTenant, null, null, Enumerable.Empty <IDomainObjectHandle <AbstractRoleDefinition> >()); SecurityTokenMatcher matcher = new SecurityTokenMatcher(_ace); Assert.That(matcher.MatchesToken(token), Is.False); }
public void Initialize_Values() { Tenant principalTenant = CreateTenant("principalTenant"); Principal principal = PrincipalTestHelper.Create(principalTenant, null, new Role[0]); Tenant owningTenant = CreateTenant("owningTenant"); Group owningGroup = CreateGroup("owningGroup", null, owningTenant); User owningUser = CreateUser("owningUser", CreateGroup("owningUserGroup", null, owningTenant), owningTenant); AbstractRoleDefinition abstractRole1 = AbstractRoleDefinition.NewObject(Guid.NewGuid(), "role1", 0); AbstractRoleDefinition abstractRole2 = AbstractRoleDefinition.NewObject(Guid.NewGuid(), "role2", 1); SecurityToken token = SecurityToken.Create( principal, owningTenant, owningGroup, owningUser, new[] { abstractRole1.GetHandle(), abstractRole2.GetHandle() }); Assert.That(token.Principal, Is.SameAs(principal)); Assert.That(token.OwningTenant, Is.EqualTo(owningTenant).Using(DomainObjectHandleComparer.Instance)); Assert.That(token.OwningGroup, Is.EqualTo(owningGroup).Using(DomainObjectHandleComparer.Instance)); Assert.That(token.OwningUser, Is.EqualTo(owningUser).Using(DomainObjectHandleComparer.Instance)); Assert.That(token.AbstractRoles, Is.EquivalentTo(new[] { abstractRole1, abstractRole2 }).Using(DomainObjectHandleComparer.Instance)); }