Esempio n. 1
0
        public void AuthIdentity_GetUsersAuthentications()
        {
            TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();

            User user = PopulateAuthData(store);
            AuthIdentityTestService service = new AuthIdentityTestService(user.Username, store);

            var lookup = service.Test_GetRoleMemberLookup(store);
            var roles = service.Test_GetUsersRolesRecursive(store, user.Username, lookup);

            var authzs = service.Test_GetUsersAuthentications(store, user.Username, roles);
        }
Esempio n. 2
0
        public void AuthIdentity_GetRoleMemberLookup()
        {
            TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
            User user = PopulateAuthData(store);

            AuthIdentityTestService service = new AuthIdentityTestService(user.Username, store);

            var lookup = service.Test_GetRoleMemberLookup(store);

            Assert.AreEqual(store.Roles.Count(), lookup.Count, "Lookup should have 1:1 mapping with existing roles");

            foreach (var entry in lookup)
            {
                var flatten = store.Roles.SingleOrDefault(f => entry.Key.Name == f.Name && entry.Key.OrgId == f.OrganizationId).Flatten().Distinct().ToList();
                Assert.AreEqual(flatten.Count, entry.Value.Count, "Should have same count when flattening {0} {1}", entry.Key.Name, entry.Key.OrgId);
                foreach (var role in flatten)
                {
                    Assert.IsNotNull(entry.Value.SingleOrDefault(f => f.Id == role.Id), "Couldn't find role {0} {1}", role.Name, role.OrganizationId);
                }
            }
        }
Esempio n. 3
0
        public void AuthIdentity_HasPermission_1()
        {
            TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
            User user = PopulateAuthData(store);

            // Find a member and their organization
            SarMember member = store.Members.First(f => f.Memberships.Count > 0);
            var orgId = member.Memberships.First().OrganizationId;

            // Create a new role and put our test user in that role
            Role testRole = new Role { Name = "testrole" };
            RoleUserMembership ru = new RoleUserMembership { Role = testRole, User = user };
            testRole.Users.Add(ru);
            user.Roles.Add(ru);
            store.Roles.Add(testRole);

            var tmp = member.Memberships.Select(f => f.OrganizationId).ToArray();

            // Give the role permissions to edit members in org
            Authorization auth = new Authorization { Role = testRole, RoleId = testRole.Id, Permission = PermissionType.EditMember, Scope = orgId };
            store.Authorization.Add(auth);

            AuthIdentityTestService service = new AuthIdentityTestService(user.Username, store);

            Assert.IsTrue(service.HasPermission(PermissionType.EditMember, member.Id));
        }
Esempio n. 4
0
        public void AuthIdentity_GetUsersRolesRecursive()
        {
            TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();

            User user = PopulateAuthData(store);
            AuthIdentityTestService service = new AuthIdentityTestService(user.Username, store);

            var lookup = service.Test_GetRoleMemberLookup(store);

            var roles = service.Test_GetUsersRolesRecursive(store, user.Username, lookup);

            Assert.AreNotEqual(store.Roles.Count(), roles.Count, "Should have gotten all the roles");
            Assert.AreEqual(2, roles.Count, "Should have gotten 2 roles");
            Assert.IsNotNull(roles.SingleOrDefault(f => f.Name == "Parent"));
            Assert.IsNotNull(roles.SingleOrDefault(f => f.Name == "Child"));
        }
Esempio n. 5
0
        public void AuthIdentity_HasPermission_UnknownUser()
        {
            TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
            AuthIdentityTestService service = new AuthIdentityTestService("not_a_user", store);
            User user = PopulateAuthData(store);

            foreach (var perm in Enum.GetValues(typeof(PermissionType)).Cast<PermissionType>())
            {
                Assert.IsFalse(service.HasPermission(perm, null));
                Assert.IsFalse(service.HasPermission(perm, Guid.NewGuid()));
            }
        }
Esempio n. 6
0
        public void AuthIdentity_HasPermission_SiteAdmin()
        {
            TestStore store = ((TestStore)DevWebsiteDataInitializer.FillDefaultDevSet(new TestStore())).FixupReferences();
            AuthIdentityTestService service = new AuthIdentityTestService("admin", store);

            foreach (var perm in Enum.GetValues(typeof(PermissionType)).Cast<PermissionType>())
            {
                Assert.IsTrue(service.HasPermission(perm, null));
                Assert.IsTrue(service.HasPermission(perm, Guid.NewGuid()));
            }
        }