예제 #1
0
        public void SystemStartAndShutdown()
        {
            //---- Ensure test data
            var entities    = CreateTestEntities();
            var groups      = CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities
            };

            //---- Start the system
            Context.StartTheSystem(new MemoryDataProvider(storage), new DefaultMessageProvider());
            var ctxAcc = new PrivateType(typeof(SecurityContext));
            var killed = (bool)ctxAcc.GetStaticField("_killed");

            Assert.IsFalse(killed);

            //---- Start the request
            context = new Context(TestUser.User1);

            //---- operation
            context.Security.HasPermission(entities.First().Value.Id, PermissionType.FullControl);

            //---- kill the system
            SecurityContext.Shutdown();

            //---- check killed state
            killed = (bool)ctxAcc.GetStaticField("_killed");
            Assert.IsTrue(killed);
        }
        private static LoadingTimeTestResult TestLoadingBigStructure(int entityMaxLevel, int entityLevelWidth)
        {
            //---- Ensure test data
            var entities    = CreateTestEntities_Big(entityMaxLevel, entityLevelWidth);
            var groups      = CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities
            };

            var timer = Stopwatch.StartNew();

            Context.StartTheSystem(new MemoryDataProvider(storage), new DefaultMessageProvider());
            timer.Stop();
            var elapsed = timer.Elapsed;

            return(new LoadingTimeTestResult
            {
                Entities = entities.Count,
                Users = 0,
                Groups = groups.Count,
                Members = memberships.Count,
                Aces = aces.Count,
                LoadingTime = elapsed
            });
        }
예제 #3
0
        public void SystemStartAndShutdown()
        {
            //---- Ensure test data
            var entities    = CreateTestEntities();
            var groups      = CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities
            };

            //---- Start the system
            var securitySystem = Context.StartTheSystem(new MemoryDataProvider(storage), new DefaultMessageProvider(new MessageSenderManager()));
            var ctxAcc         = new ObjectAccessor(securitySystem);
            var killed         = (bool)ctxAcc.GetField("_killed");

            Assert.IsFalse(killed);

            //---- Start the request
            _context = new Context(TestUser.User1, securitySystem);

            //---- operation
            _context.Security.HasPermission(entities.First().Value.Id, PermissionType.Open);

            //---- kill the system
            _context.Security.SecuritySystem.Shutdown();

            //---- check killed state
            killed = (bool)ctxAcc.GetField("_killed");
            Assert.IsTrue(killed);
        }
예제 #4
0
        public void Messaging_BigActivity()
        {
            SnLog.Instance = new TestLogger();

            //---- Ensure test data
            var entities    = CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage
            {
                Aces        = aces,
                Memberships = memberships,
                Entities    = entities,
                Messages    = new List <Tuple <int, DateTime, byte[]> >()
            };

            //---- Start the system
            var msgProvider = new TestMessageProvider();

            msgProvider.Initialize();
            Context.StartTheSystem(new MemoryDataProviderForMessagingTests(storage), msgProvider);

            context = new Context(TestUser.User1);

            // small activity
            var smallActivity = new TestActivity();

            smallActivity.Execute(context.Security);
            var smallActivityId = smallActivity.Id;

            // large activity
            var largeActivity = new TestActivity()
            {
                Body = new String('*', Configuration.DistributableSecurityActivityMaxSize + 1)
            };

            largeActivity.Execute(context.Security);
            var largeActivityId = largeActivity.Id;

            // check the logger
            var expected = String.Format("Executing unprocessed security activities., " +
                                         "Send: TestActivity, Applied: #{0}, " +
                                         "Send: BigActivityMessage, LoadMessage: TestActivity#{1}, Applied: #{1}",
                                         smallActivityId, largeActivityId);

            var testLogger = (TestLogger)SnLog.Instance;
            var actual     = string.Join(", ", testLogger.Informations);

            Assert.AreEqual(expected, actual);
        }
예제 #5
0
        public void Messaging_MessageSender()
        {
            SnLog.Instance = new TestLogger();

            //---- Ensure test data
            var entities    = CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage
            {
                Aces        = aces,
                Memberships = memberships,
                Entities    = entities,
                Messages    = new List <Tuple <int, DateTime, byte[]> >()
            };

            //---- Start the system
            var messageSenderManager = new MessageSenderManager();
            var msgProvider          = new TestMessageProvider(messageSenderManager);

            msgProvider.MessageReceived += MsgProvider_MessageReceived;
            msgProvider.Initialize();

            var securitySystem = Context.StartTheSystem(new MemoryDataProviderForMessagingTests(storage), msgProvider);

            _context = new Context(TestUser.User1, securitySystem);

            // small activity from me
            var activity1 = new TestActivity();

            activity1.Execute(_context.Security);

            // small activity from another
            var activity2 = new TestActivity
            {
                Sender = new TestMessageSender {
                    ComputerID = Environment.MachineName, InstanceID = "AnotherAppDomain"
                }
            };

            activity2.Execute(_context.Security);

            Assert.AreEqual("true, false", string.Join(", ", msgProvider.ReceiverMessages));
        }
예제 #6
0
        private SecuritySystem CreateSecuritySystem(string instanceName, Queue <byte[]> messageQueue, bool isReceiver)
        {
            var entities    = SystemStartTests.CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = SystemStartTests.CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities, Messages = new List <Tuple <int, DateTime, byte[]> >()
            };

            var messageSenderManager = new MessageSenderManager(null, instanceName);
            var securitySystem       = new SecuritySystem(
                new MemoryDataProvider(storage),
                new TestMessageProvider(messageSenderManager, messageQueue, isReceiver),
                new MissingEntityHandler(),
                new SecurityConfiguration(),
                new MessagingOptions());

            securitySystem.Start();

            return(securitySystem);
        }
예제 #7
0
        public void SystemStartAndPreloadStructures()
        {
            //---- Ensure test data
            var entities = CreateTestEntities();
            var groups   = CreateTestGroups();
            //var memberships = Tools.CreateInMemoryMembershipTable("G1:U1,U2|G2:U3,U4|G3:U1,U3|G4:U4|G5:U5");
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage {
                Aces = aces, Memberships = memberships, Entities = entities
            };

            //---- Start the system
            Context.StartTheSystem(new MemoryDataProvider(storage), new DefaultMessageProvider());

            //---- Start the request
            context = new Context(TestUser.User1);

            //---- check cache
            var dbAcc = new MemoryDataProviderAccessor((MemoryDataProvider)context.Security.DataProvider);

            Assert.AreEqual(entities.Count, context.Security.Cache.Entities.Count);
            Assert.AreEqual(entities.Count, dbAcc.Storage.Entities.Count);
            Assert.AreEqual(groups.Count, context.Security.Cache.Groups.Count);
            Assert.AreEqual(memberships.Count, dbAcc.Storage.Memberships.Count);
            Assert.AreEqual(aces.Count, storage.Aces.Count);

            //---- check membership in the evaluator
            var s        = Tools.ReplaceIds(context.Security.Evaluator._traceMembership());
            var expected = @"U1:[G1,G3]U2:[G1]U3:[G2,G3]U4:[G2,G4]U5:[G5]";

            Assert.AreEqual(expected, s.Replace(Environment.NewLine, "").Replace(" ", ""));

            //---- preload
            var id1  = Id("E1");
            var id3  = Id("E3");
            var id5  = Id("E5");
            var id50 = Id("E50");

            //---- check nearest holder ids
            var entityTable = context.Security.Cache.Entities;

            Assert.AreEqual(id1, entityTable[Id("E1")].GetFirstAclId());
            Assert.AreEqual(id1, entityTable[Id("E2")].GetFirstAclId());
            Assert.AreEqual(id3, entityTable[Id("E3")].GetFirstAclId());
            Assert.AreEqual(id1, entityTable[Id("E4")].GetFirstAclId());
            Assert.AreEqual(id5, entityTable[Id("E5")].GetFirstAclId());
            Assert.AreEqual(id1, entityTable[Id("E6")].GetFirstAclId());
            Assert.AreEqual(id5, entityTable[Id("E14")].GetFirstAclId());
            Assert.AreEqual(id5, entityTable[Id("E15")].GetFirstAclId());
            Assert.AreEqual(id1, entityTable[Id("E16")].GetFirstAclId());
            Assert.AreEqual(id1, entityTable[Id("E17")].GetFirstAclId());
            Assert.AreEqual(id50, entityTable[Id("E50")].GetFirstAclId());
            Assert.AreEqual(id50, entityTable[Id("E51")].GetFirstAclId());
            Assert.AreEqual(id50, entityTable[Id("E52")].GetFirstAclId());
            Assert.AreEqual(id50, entityTable[Id("E53")].GetFirstAclId());

            //---- check acls in the evaluator
            var allacls = Tools.CollectAllAcls(context.Security);

            Assert.AreEqual(4, allacls.Count);
            var acl1  = GetAcl(allacls, id1);
            var acl3  = GetAcl(allacls, id3);
            var acl5  = GetAcl(allacls, id5);
            var acl50 = GetAcl(allacls, id50);

            Assert.IsNull(acl1.Parent);
            Assert.IsNotNull(acl3.Parent);
            Assert.IsNotNull(acl5.Parent);
            Assert.IsNotNull(acl50.Parent);
            Assert.AreEqual(id1, acl3.Parent.EntityId);
            Assert.AreEqual(id1, acl5.Parent.EntityId);
            Assert.AreEqual(id5, acl50.Parent.EntityId);
        }