Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void Sharing_GetAcl_FirstAclIsNotRelevant()
        {
            EnsureRepository();
            var ctx = CurrentContext.Security;

            Tools.SetMembership(ctx, "U1:G1");

            SetAcl("+E1| Normal|+G1:___________++++"); // 0x1
            SetAcl("+E2|Sharing|+G1:_______++++____"); // 0x10

            // ACTION 1: default filter (Normal)
            var entry = ctx.GetAcl(Id("E5")).Entries.First();

            Assert.AreEqual("Normal|+G1:____________________________________________________________++++", Tools.ReplaceIds(entry.ToString()));

            // ACTION 2: Normal only
            entry = ctx.GetAcl(Id("E5"), EntryType.Normal).Entries.First();
            Assert.AreEqual("Normal|+G1:____________________________________________________________++++", Tools.ReplaceIds(entry.ToString()));

            // ACTION 3: Sharing only
            entry = ctx.GetAcl(Id("E5"), EntryType.Sharing).Entries.First();
            Assert.AreEqual("Sharing|+G1:________________________________________________________++++____", Tools.ReplaceIds(entry.ToString()));
        }
Ejemplo n.º 3
0
        public void Sharing_Acl_ExplicitEntries_Filtered()
        {
            EnsureRepository();
            var ctx = CurrentContext.Security;

            Tools.SetMembership(ctx, "U1:G1");

            SetAcl("+E1| Normal|+G1:______________+"); // 0x1
            SetAcl("+E1|Sharing|+G1:___________+___"); // 0x8
            SetAcl("+E2| Normal|+G1:_____________+_"); // 0x2
            SetAcl("+E2|Sharing|+G1:__________+____"); // 0x10
            SetAcl("+E2| Normal|-G1:____________+__"); // 0x4   local
            SetAcl("+E2|Sharing|-G1:_________+_____"); // 0x20  local

            // ACTION 1: query without filter + local entries
            var entries = ctx.GetExplicitEntries(Id("E2"))
                          .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();

            // ASSERT 1
            Assert.AreEqual(4, entries.Count);
            Assert.AreEqual("Normal|+G1:______________________________________________________________+_", Tools.ReplaceIds(entries[0].ToString()));
            Assert.AreEqual("Sharing|+G1:___________________________________________________________+____", Tools.ReplaceIds(entries[1].ToString()));
            Assert.AreEqual("Normal|-G1:_____________________________________________________________+__", Tools.ReplaceIds(entries[2].ToString()));
            Assert.AreEqual("Sharing|-G1:__________________________________________________________+_____", Tools.ReplaceIds(entries[3].ToString()));

            // ACTION 2: query without filter, no local entries
            entries = ctx.GetExplicitEntries(Id("E1"))
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            // ASSERT 2
            Assert.AreEqual(2, entries.Count);
            Assert.IsTrue(!entries[0].LocalOnly && entries[0].EntryType == EntryType.Normal);
            Assert.IsTrue(!entries[1].LocalOnly && entries[1].EntryType == EntryType.Sharing);
            Assert.AreEqual("Normal|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries[0].ToString()));
            Assert.AreEqual("Sharing|+G1:____________________________________________________________+___", Tools.ReplaceIds(entries[1].ToString()));

            // ACTION 3: query + filter Normal + local entries
            entries = ctx.GetExplicitEntries(Id("E2"), null, EntryType.Normal)
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            // ASSERT 3
            Assert.AreEqual(2, entries.Count);
            Assert.AreEqual("Normal|+G1:______________________________________________________________+_", Tools.ReplaceIds(entries[0].ToString()));
            Assert.AreEqual("Normal|-G1:_____________________________________________________________+__", Tools.ReplaceIds(entries[1].ToString()));

            // ACTION 4: query + filter Sharing + local entries
            entries = ctx.GetExplicitEntries(Id("E2"), null, EntryType.Sharing)
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            // ASSERT 4
            Assert.AreEqual(2, entries.Count);
            Assert.AreEqual("Sharing|+G1:___________________________________________________________+____", Tools.ReplaceIds(entries[0].ToString()));
            Assert.AreEqual("Sharing|-G1:__________________________________________________________+_____", Tools.ReplaceIds(entries[1].ToString()));

            // ACTION 5: query + filter Normal, no local entries
            entries = ctx.GetExplicitEntries(Id("E1"), null, EntryType.Normal);
            // ASSERT 5
            Assert.AreEqual(1, entries.Count);
            Assert.AreEqual("Normal|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries[0].ToString()));

            // ACTION 6: query + filter Sharing, no local entries
            entries = ctx.GetExplicitEntries(Id("E1"), null, EntryType.Sharing);
            // ASSERT 6
            Assert.AreEqual("Sharing|+G1:____________________________________________________________+___", Tools.ReplaceIds(entries[0].ToString()));
        }
Ejemplo n.º 4
0
        public void Sharing_Acl_BreakAll_Unbreak_NormalizeOne()
        {
            EnsureRepository();
            var ctx = CurrentContext.Security;

            Tools.SetMembership(ctx, "U1:G1,G2");

            SetAcl("+E1|Sharing|+G1:______________+");
            SetAcl("+E1| Normal|+G1:_____________+_");
            SetAcl("+E2| Normal|+G1:____________+__");
            SetAcl("+E3| Normal|+G2:_____________+_");

            var ed = ctx.CreateAclEditor();

            ed.BreakInheritance(Id("E5"), new[] { EntryType.Normal, EntryType.Sharing });
            ed.BreakInheritance(Id("E8"), new[] { EntryType.Normal, EntryType.Sharing });
            ed.Apply();

            // ACTION
            ed = ctx.CreateAclEditor();
            ed.UnbreakInheritance(Id("E5"), new[] { EntryType.Normal });
            ed.UnbreakInheritance(Id("E8"), new[] { EntryType.Normal });
            ed.Apply();

            // ASSERT
            var entries5 = ctx.GetExplicitEntries(Id("E5")); // E1/E2/E5
            var entries8 = ctx.GetExplicitEntries(Id("E8")); // E1/E3/E8

            Assert.AreEqual(1, entries5.Count);
            Assert.AreEqual("Sharing|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries5[0].ToString()));

            Assert.AreEqual(1, entries8.Count);
            Assert.AreEqual("Sharing|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries8[0].ToString()));
        }
Ejemplo n.º 5
0
        public void Sharing_Acl_BreakOperation_EverythingCopied()
        {
            EnsureRepository();
            var ctx = CurrentContext.Security;

            Tools.SetMembership(ctx, "U1:G1,G2");

            SetAcl("+E1|Sharing|+G1:______________+");
            SetAcl("+E1| Normal|+G1:_____________+_");
            SetAcl("+E2| Normal|+G1:____________+__");
            SetAcl("+E3| Normal|+G2:_____________+_");

            // ACTION
            var ed = ctx.CreateAclEditor();

            ed.BreakInheritance(Id("E5"), new[] { EntryType.Normal, EntryType.Sharing });
            ed.BreakInheritance(Id("E8"), new[] { EntryType.Normal, EntryType.Sharing });
            ed.Apply();

            // ASSERT
            var entries5 = ctx.GetExplicitEntries(Id("E5")) // E1/E2/E5
                           .OrderBy(x => x.EntryType).ThenBy(x => x.IdentityId).ToList();
            var entries8 = ctx.GetExplicitEntries(Id("E8")) // E1/E3/E8
                           .OrderBy(x => x.EntryType).ThenBy(x => x.IdentityId).ToList();

            Assert.AreEqual(2, entries5.Count);
            Assert.AreEqual("Normal|+G1:_____________________________________________________________++_", Tools.ReplaceIds(entries5[0].ToString()));
            Assert.AreEqual("Sharing|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries5[1].ToString()));

            Assert.AreEqual(3, entries8.Count);
            Assert.AreEqual("Normal|+G1:______________________________________________________________+_", Tools.ReplaceIds(entries8[0].ToString()));
            Assert.AreEqual("Normal|+G2:______________________________________________________________+_", Tools.ReplaceIds(entries8[1].ToString()));
            Assert.AreEqual("Sharing|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries8[2].ToString()));
        }
Ejemplo n.º 6
0
        public void Sharing_GetAcl()
        {
            EnsureRepository();
            var ctx = CurrentContext.Security;

            Tools.SetMembership(ctx, "U1:G1");

            SetAcl("+E1| Normal|+G1:______________+"); // 0x1
            SetAcl("+E1|Sharing|+G1:___________+___"); // 0x8
            SetAcl("+E2| Normal|+G1:_____________+_"); // 0x2
            SetAcl("+E2|Sharing|+G1:__________+____"); // 0x10
            SetAcl("+E2| Normal|-G1:____________+__"); // 0x4   local
            SetAcl("+E2|Sharing|-G1:_________+_____"); // 0x20  local

            // ACTION 1 root, default filter (Normal)
            var entries = ctx.GetAcl(Id("E1")).Entries
                          .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();

            Assert.AreEqual("Normal|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries[0].ToString()));

            // ACTION 2 child, default filter (Normal)
            entries = ctx.GetAcl(Id("E2")).Entries
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            Assert.AreEqual("Normal|+G1:______________________________________________________________++", Tools.ReplaceIds(entries[0].ToString()));
            Assert.AreEqual("Normal|-G1:_____________________________________________________________+__", Tools.ReplaceIds(entries[1].ToString()));

            // ACTION 3 root, Normal only
            entries = ctx.GetAcl(Id("E1"), EntryType.Normal).Entries
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            Assert.AreEqual("Normal|+G1:_______________________________________________________________+", Tools.ReplaceIds(entries[0].ToString()));

            // ACTION 4 child, Normal only
            entries = ctx.GetAcl(Id("E2"), EntryType.Normal).Entries
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            Assert.AreEqual("Normal|+G1:______________________________________________________________++", Tools.ReplaceIds(entries[0].ToString()));
            Assert.AreEqual("Normal|-G1:_____________________________________________________________+__", Tools.ReplaceIds(entries[1].ToString()));

            // ACTION 3 root, Sharing only
            entries = ctx.GetAcl(Id("E1"), EntryType.Sharing).Entries
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            Assert.AreEqual("Sharing|+G1:____________________________________________________________+___", Tools.ReplaceIds(entries[0].ToString()));

            // ACTION 4 child, Sharing only
            entries = ctx.GetAcl(Id("E2"), EntryType.Sharing).Entries
                      .OrderBy(x => x.LocalOnly).ThenBy(x => x.EntryType).ToList();
            Assert.AreEqual("Sharing|+G1:___________________________________________________________++___", Tools.ReplaceIds(entries[0].ToString()));
            Assert.AreEqual("Sharing|-G1:__________________________________________________________+_____", Tools.ReplaceIds(entries[1].ToString()));
        }