Пример #1
0
        public void TestPermissionsCachingOnChange(Action <Common.ExecutionContext> change, bool[] expectedPermissionsAfterChange, string expectedCacheMisses)
        {
            using (var container = new RhetosTestContainer(commitChanges: false))
            {
                var log = new List <string>();
                container.AddLogMonitor(log);
                container.AddFakeUser(User1Name);

                var repository           = container.Resolve <Common.DomRepository>();
                var context              = container.Resolve <Common.ExecutionContext>();
                var authorizationManager = container.Resolve <IAuthorizationManager>();

                AuthorizationDataCache.ClearCache();

                // Get user authorization:

                Assert.AreEqual(TestUtility.Dump(new[] { true, true, false }),
                                TestUtility.Dump(authorizationManager.GetAuthorizations(new[] { Claim1, Claim2, Claim3 })));

                Assert.AreEqual("Claims, Principal, PrincipalPermissions, PrincipalRoles, RolePermissions, RolePermissions, RoleRoles, RoleRoles, Roles",
                                ReportCacheMisses(log, "Initial authorization"), "Initial permission should yield cache misses. See test output log for details.");

                // Modify the permissions. Part of the cache might be invalidated:

                change(context);

                // Get user authorization, with parially invalidated cache:

                Assert.AreEqual(TestUtility.Dump(expectedPermissionsAfterChange),
                                TestUtility.Dump(authorizationManager.GetAuthorizations(new[] { Claim1, Claim2, Claim3 })));

                Assert.AreEqual(expectedCacheMisses, ReportCacheMisses(log, "Authorization after cache invalidation"), "See test output log for details.");
            }
        }
Пример #2
0
        public string TestPermissionsCachingOnChange(Action <Common.ExecutionContext> change, bool[] expectedPermissionsAfterChange, Action <Common.ExecutionContext> init = null)
        {
            using (var container = new RhetosTestContainer(commitChanges: false))
            {
                var log = new List <string>();
                container.AddLogMonitor(log);
                container.AddFakeUser(User1Name);

                var context = container.Resolve <Common.ExecutionContext>();
                var authorizationManager = container.Resolve <IAuthorizationManager>();

                Console.WriteLine("== Begin test initialization ==");
                init?.Invoke(context);
                Console.WriteLine("== End test initialization ==");

                AuthorizationDataCache.ClearCache();

                // Get user authorization:

                Assert.AreEqual(
                    TestUtility.Dump(new[] { true, true, false }),
                    TestUtility.Dump(authorizationManager.GetAuthorizations(new[] { Claim1, Claim2, Claim3 })));

                var systemRoles      = Enum.GetNames(typeof(SystemRole));
                var systemRolesCount = context.Repository.Common.Role.Query(r => systemRoles.Contains(r.Name)).Count();

                var loadingFullAuthorizationData = new List <string> {
                    "Claims", "Principal", "PrincipalPermissions", "PrincipalRoles", "RolePermissions", "RolePermissions", "RoleRoles", "RoleRoles", "Roles", "SystemRoles"
                };
                for (int i = 0; i < systemRolesCount; i++)
                {
                    loadingFullAuthorizationData.Add("RolePermissions");
                    loadingFullAuthorizationData.Add("RoleRoles");
                }

                Assert.AreEqual(
                    TestUtility.DumpSorted(loadingFullAuthorizationData),
                    ReportCacheMisses(log, "Initial authorization"), "Initial permission should yield cache misses. See test output log for details.");

                // Modify the permissions. Part of the cache might be invalidated:

                Console.WriteLine("== Begin test change ==");
                change(context);
                Console.WriteLine("== End test change ==");

                // Get user authorization, with partially invalidated cache:

                Assert.AreEqual(
                    TestUtility.Dump(expectedPermissionsAfterChange),
                    TestUtility.Dump(authorizationManager.GetAuthorizations(new[] { Claim1, Claim2, Claim3 })));

                return(ReportCacheMisses(log, "Authorization after cache invalidation"));
            }
        }
Пример #3
0
        public void KeepSyncRepositoryMembers()
        {
            using (var container = new RhetosTestContainer())
            {
                container.AddFakeUser("bb");

                container.Resolve <ISqlExecuter>().ExecuteSql("DELETE FROM TestComputedFrom.KeepSyncRepositoryMembers");
                var repository = container.Resolve <Common.DomRepository>();

                repository.TestComputedFrom.KeepSyncRepositoryMembers.RecomputeFromSource();
                Assert.AreEqual("bb 22", TestUtility.DumpSorted(repository.TestComputedFrom.KeepSyncRepositoryMembers.Query(), item => item.Name + " " + item.Code));
            }
        }
Пример #4
0
        public void TestPermissionsCachingOnChange(Action<Common.ExecutionContext> change, bool[] expectedPermissionsAfterChange, string expectedCacheMisses)
        {
            using (var container = new RhetosTestContainer(commitChanges: false))
            {
                var log = new List<string>();
                container.AddLogMonitor(log);
                container.AddFakeUser(User1Name);
                
                var repository = container.Resolve<Common.DomRepository>();
                var context = container.Resolve<Common.ExecutionContext>();
                var authorizationManager = container.Resolve<IAuthorizationManager>();

                AuthorizationDataCache.ClearCache();

                // Get user authorization:

                Assert.AreEqual(TestUtility.Dump(new[] { true, true, false }),
                    TestUtility.Dump(authorizationManager.GetAuthorizations(new[] { Claim1, Claim2, Claim3 })));

                Assert.AreEqual("Claims, Principal, PrincipalPermissions, PrincipalRoles, RolePermissions, RolePermissions, RoleRoles, RoleRoles, Roles",
                    ReportCacheMisses(log, "Initial authorization"), "Initial permission should yield cache misses. See test output log for details.");

                // Modify the permissions. Part of the cache might be invalidated:

                change(context);

                // Get user authorization, with parially invalidated cache:

                Assert.AreEqual(TestUtility.Dump(expectedPermissionsAfterChange),
                    TestUtility.Dump(authorizationManager.GetAuthorizations(new[] { Claim1, Claim2, Claim3 })));

                Assert.AreEqual(expectedCacheMisses, ReportCacheMisses(log, "Authorization after cache invalidation"), "See test output log for details.");
            }
        }