Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void CommunicationMonitor_HearthBeat()
        {
            var testDp               = new TestDp(DatabaseStorage.CreateEmpty());
            var messageProvider      = new DefaultMessageProvider(new MessageSenderManager());
            var missingEntityHandler = new MissingEntityHandler();
            var messagingOptions     = Options.Create(new MessagingOptions()
            {
                CommunicationMonitorRunningPeriodInSeconds = 1
            });
            var securitySystem = new SecuritySystem(testDp, messageProvider, missingEntityHandler,
                                                    new SecurityConfiguration(), messagingOptions.Value);
            var dataHandler           = new DataHandler(testDp, messagingOptions);
            var communicationMonitor  = new CommunicationMonitor(dataHandler, messagingOptions);
            var activityHistory       = new SecurityActivityHistoryController();
            var securityActivityQueue = new SecurityActivityQueue(securitySystem, communicationMonitor, dataHandler, activityHistory);

            // ACTION
            var communicationMonitorAcc = new ObjectAccessor(communicationMonitor);

            communicationMonitorAcc.Invoke("Timer_Elapsed");

            // ASSERT
            Assert.IsTrue(testDp.IsCleanupSecurityActivitiesCalled);
            Assert.IsTrue(testDp.IsGetLastSecurityActivityIdCalled);
        }
        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
            });
        }
Exemplo n.º 5
0
        private Context GetContextAndStartTheSystem(LockRecursionUser currentUser)
        {
            SecurityActivityQueue._setCurrentExecutionState(new CompletionState());
            MemoryDataProvider.LastActivityId = 0;
            Context.StartTheSystem(new MemoryDataProvider(DatabaseStorage.CreateEmpty()), new DefaultMessageProvider(), null);
            var context = new Context(currentUser);

            CreatePlayground(context);
            return(context);
        }
Exemplo n.º 6
0
        private Context GetContextAndStartTheSystem(LockRecursionUser currentUser)
        {
            //SecuritySystem.Instance.SecurityActivityQueue._setCurrentExecutionState(new CompletionState());
            //MemoryDataProvider.LastActivityId = 0;
            var securitySystem = Context.StartTheSystem(new MemoryDataProvider(DatabaseStorage.CreateEmpty()), new DefaultMessageProvider(new MessageSenderManager()));
            var context        = new Context(currentUser, securitySystem);

            CreatePlayground(context);
            return(context);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
 private void StartTheSystem()
 {
     SecurityActivityQueue._setCurrentExecutionState(new CompletionState());
     MemoryDataProvider._lastActivityId = 0;
     Context.StartTheSystem(new MemoryDataProvider(DatabaseStorage.CreateEmpty()), new DefaultMessageProvider());
 }
Exemplo n.º 11
0
 public MemoryDataProviderForMessagingTests(DatabaseStorage storage) : base(storage)
 {
 }
Exemplo n.º 12
0
 internal static Context GetEmptyContext(TestUser currentUser)
 {
     SecurityActivityQueue._setCurrentExecutionState(new CompletionState());
     MemoryDataProvider.LastActivityId = 0;
     return(GetEmptyContext(currentUser, new MemoryDataProvider(DatabaseStorage.CreateEmpty())));
 }
Exemplo n.º 13
0
 public void DeleteEverything()
 {
     _storage = new DatabaseStorage();
 }
Exemplo n.º 14
0
 public MemoryDataProvider(DatabaseStorage storage)
 {
     _storage = storage;
 }
Exemplo n.º 15
0
 protected override ISecurityDataProvider GetDataProvider()
 {
     //MemoryDataProvider.LastActivityId = 0;
     return(new MemoryDataProvider(DatabaseStorage.CreateEmpty()));
 }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
 public TestDp(DatabaseStorage storage) : base(storage)
 {
 }