コード例 #1
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()));
            }
        }
コード例 #2
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));
        }
コード例 #3
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()));
            }
        }