public void Event_AclChanged_OverwriteEntry() { AclManagerBase manager = MockAclManager(); AclEntry entryOld = new AclEntry("Res", "Action", "U.User", Value.Deny); AclEntry entryNew = new AclEntry("Res", "Action", "U.User", Value.Grant); manager.StoreEntry(entryOld.Resource, entryOld.Action, entryOld.Subject, entryOld.Value); bool invokedStore = false; bool invokedDelete = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { if (e.Change == Change.EntryStored) { invokedStore = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entryNew, e.Entries[0]); Assert.AreEqual(Change.EntryStored, e.Change); } else { invokedDelete = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entryOld, e.Entries[0]); Assert.AreEqual(Change.EntryDeleted, e.Change); } }; manager.StoreEntry(entryNew.Resource, entryNew.Action, entryNew.Subject, entryNew.Value); Assert.IsTrue(invokedStore, "Store event not invoked"); Assert.IsTrue(invokedDelete, "Delete event not invoked"); }
public void DeleteEntriesForSubject_RetrieveAllEntries() { AclManagerBase manager = MockAclManager(); Assert.IsTrue(manager.StoreEntry("Res", "Action", "U.User", Value.Grant), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res", "Action", "G.Group", Value.Deny), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res2", "Action2", "G.Group2", Value.Grant), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res2", "Action3", "G.Group2", Value.Deny), "StoreEntry should return true"); Assert.AreEqual(4, manager.TotalEntries, "Wrong entry count"); Assert.IsFalse(manager.DeleteEntriesForSubject("I.Inexistent"), "DeleteEntriesForSubject should return false"); Assert.AreEqual(4, manager.TotalEntries, "Wrong entry count"); Assert.IsTrue(manager.DeleteEntriesForSubject("G.Group2"), "DeleteEntriesForSubject should return true"); Assert.AreEqual(2, manager.TotalEntries, "Wrong entry count"); AclEntry[] allEntries = manager.RetrieveAllEntries(); Assert.AreEqual(2, allEntries.Length, "Wrong entry count"); Array.Sort(allEntries, delegate(AclEntry x, AclEntry y) { return(x.Subject.CompareTo(y.Subject)); }); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "G.Group", Value.Deny), allEntries[0]); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "U.User", Value.Grant), allEntries[1]); }
public void StoreEntry_Subject_Empty() { AclManagerBase manager = MockAclManager(); var ex = Assert.Throws <ArgumentException>(() => manager.StoreEntry("Res", "Action", "", Value.Grant)); Assert.Equal("Subject cannot be empty.\r\nParameter name: subject", ex.Message); }
public void StoreEntry_Action_Null() { AclManagerBase manager = MockAclManager(); var ex = Assert.Throws <ArgumentNullException>(() => manager.StoreEntry("Res", null, "U.User", Value.Grant)); Assert.Equal("Value cannot be null.\r\nParameter name: action", ex.Message); }
public void StoreEntry_Resource_Empty() { AclManagerBase manager = MockAclManager(); var ex = Assert.Throws <ArgumentException>(() => manager.StoreEntry("", "Action", "U.User", Value.Grant)); Assert.Equal("Resource cannot be empty.\r\nParameter name: resource", ex.Message); }
public void StoreEntry_InvalidResource_ShouldThrowArgumentException(string s) { Assert.Throws <ArgumentException>(() => { AclManagerBase manager = MockAclManager(); manager.StoreEntry(s, "Action", "U.User", Value.Grant); }); }
public void StoreEntry_InvalidAction_ShouldThrowArgumentException(string a) { Assert.Throws <ArgumentException>(() => { AclManagerBase manager = MockAclManager(); manager.StoreEntry("Res", a, "U.User", Value.Grant); }); }
public void StoreEntry_InvalidSubject_ShouldThrowArgumentException(string s) { Assert.Throws <ArgumentException>(() => { AclManagerBase manager = MockAclManager(); manager.StoreEntry("Res", "Action", s, Value.Grant); }); }
public void RetrieveEntriesForSubject() { AclManagerBase manager = MockAclManager(); Assert.True(manager.StoreEntry("Res", "Action", "U.User", Value.Grant), "StoreEntry should return true"); Assert.True(manager.StoreEntry("Res", "Action", "G.Group", Value.Deny), "StoreEntry should return true"); Assert.True(manager.StoreEntry("Res2", "Action2", "G.Group2", Value.Grant), "StoreEntry should return true"); Assert.True(manager.StoreEntry("Res2", "Action3", "G.Group2", Value.Deny), "StoreEntry should return true"); Assert.Empty(manager.RetrieveEntriesForSubject("I.Inexistent")); AclEntry[] allEntries = manager.RetrieveEntriesForSubject("G.Group2"); Assert.Equal(2, allEntries.Length); Array.Sort(allEntries, delegate(AclEntry x, AclEntry y) { return(x.Action.CompareTo(y.Action)); }); AssertAclEntriesAreEqual(new AclEntry("Res2", "Action2", "G.Group2", Value.Grant), allEntries[0]); AssertAclEntriesAreEqual(new AclEntry("Res2", "Action3", "G.Group2", Value.Deny), allEntries[1]); }
public void RetrieveEntriesForResource() { AclManagerBase manager = MockAclManager(); Assert.IsTrue(manager.StoreEntry("Res", "Action", "U.User", Value.Grant), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res", "Action", "G.Group", Value.Deny), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res2", "Action2", "G.Group2", Value.Grant), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res2", "Action3", "G.Group2", Value.Deny), "StoreEntry should return true"); Assert.AreEqual(0, manager.RetrieveEntriesForResource("Inexistent").Length, "Wrong result count"); AclEntry[] allEntries = manager.RetrieveEntriesForResource("Res"); Assert.AreEqual(2, allEntries.Length, "Wrong entry count"); Array.Sort(allEntries, delegate(AclEntry x, AclEntry y) { return(x.Subject.CompareTo(y.Subject)); }); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "G.Group", Value.Deny), allEntries[0]); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "U.User", Value.Grant), allEntries[1]); }
public void StoreEntry_RetrieveAllEntries() { AclManagerBase manager = MockAclManager(); Assert.AreEqual(0, manager.TotalEntries, "Wrong initial entry count"); Assert.AreEqual(0, manager.RetrieveAllEntries().Length, "Wrong initial entry count"); Assert.IsTrue(manager.StoreEntry("Res", "Action", "U.User", Value.Grant), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res", "Action", "G.Group", Value.Deny), "StoreEntry should return true"); Assert.AreEqual(2, manager.TotalEntries, "Wrong entry count"); AclEntry[] allEntries = manager.RetrieveAllEntries(); Assert.AreEqual(2, allEntries.Length, "Wrong entry count"); Array.Sort(allEntries, delegate(AclEntry x, AclEntry y) { return(x.Subject.CompareTo(y.Subject)); }); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "G.Group", Value.Deny), allEntries[0]); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "U.User", Value.Grant), allEntries[1]); }
public void StoreEntry_Overwrite( ) { AclManagerBase manager = MockAclManager( ); Assert.IsTrue(manager.StoreEntry("Res", "Action", "U.User", Value.Grant), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res", "Action", "G.Group", Value.Grant), "StoreEntry should return true"); // Overwrite with a deny Assert.IsTrue(manager.StoreEntry("Res", "Action", "U.User", Value.Deny), "StoreEntry should return true"); Assert.AreEqual(2, manager.TotalEntries, "Wrong entry count"); AclEntry[] allEntries = manager.RetrieveAllEntries( ); Assert.AreEqual(2, allEntries.Length, "Wrong entry count"); Array.Sort(allEntries, (x, y) => x.Subject.CompareTo(y.Subject)); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "G.Group", Value.Grant), allEntries[0]); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "U.User", Value.Deny), allEntries[1]); }
public void Event_AclChanged_DeleteEntriesForSubject() { AclManagerBase manager = MockAclManager(); AclEntry entry = new AclEntry("Res", "Action", "U.User", Value.Grant); manager.StoreEntry(entry.Resource, entry.Action, entry.Subject, entry.Value); manager.StoreEntry("Res2", "Action", "G.Group", Value.Deny); bool invokedDelete = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { invokedDelete = true; Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(entry, e.Entries[0]); Assert.AreEqual(Change.EntryDeleted, e.Change, "Wrong change"); }; manager.DeleteEntriesForSubject(entry.Subject); Assert.IsTrue(invokedDelete, "Delete event not invoked"); }
public void DeleteEntry_RetrieveAllEntries() { AclManagerBase manager = MockAclManager(); Assert.IsTrue(manager.StoreEntry("Res", "Action", "U.User", Value.Grant), "StoreEntry should return true"); Assert.IsTrue(manager.StoreEntry("Res", "Action", "G.Group", Value.Deny), "StoreEntry should return true"); Assert.AreEqual(2, manager.TotalEntries, "Wrong entry count"); Assert.IsFalse(manager.DeleteEntry("Res1", "Action", "G.Group"), "DeleteEntry should return false"); Assert.IsFalse(manager.DeleteEntry("Res", "Action1", "G.Group"), "DeleteEntry should return false"); Assert.IsFalse(manager.DeleteEntry("Res", "Action", "G.Group1"), "DeleteEntry should return false"); Assert.AreEqual(2, manager.TotalEntries, "Wrong entry count"); Assert.IsTrue(manager.DeleteEntry("Res", "Action", "G.Group"), "DeleteEntry should return true"); Assert.AreEqual(1, manager.TotalEntries, "Wrong entry count"); AclEntry[] allEntries = manager.RetrieveAllEntries(); Assert.AreEqual(1, allEntries.Length, "Wrong entry count"); AssertAclEntriesAreEqual(new AclEntry("Res", "Action", "U.User", Value.Grant), allEntries[0]); }
public void Event_AclChanged_StoreEntry() { AclManagerBase manager = MockAclManager(); AclEntry entry = new AclEntry("Res", "Action", "U.User", Value.Grant); bool invoked = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { invoked = true; Assert.Single(e.Entries); AssertAclEntriesAreEqual(entry, e.Entries[0]); Assert.Equal(Change.EntryStored, e.Change); }; manager.StoreEntry(entry.Resource, entry.Action, entry.Subject, entry.Value); Assert.True(invoked, "Store event not invoked"); }
public void StoreEntry_InvalidResource(string s) { AclManagerBase manager = MockAclManager( ); manager.StoreEntry(s, "Action", "U.User", Value.Grant); }
public void StoreEntry_InvalidAction(string a) { AclManagerBase manager = MockAclManager( ); manager.StoreEntry("Res", a, "U.User", Value.Grant); }
public void RenameResource() { AclManagerBase manager = MockAclManager(); Assert.IsFalse(manager.RenameResource("Res", "Res_Renamed"), "RenameResource should return false"); AclEntry entry1 = new AclEntry("Res", "Action", "U.User", Value.Grant); AclEntry newEntry1 = new AclEntry("Res_Renamed", "Action", "U.User", Value.Grant); AclEntry entry2 = new AclEntry("Res", "Action2", "U.User2", Value.Deny); AclEntry newEntry2 = new AclEntry("Res_Renamed", "Action2", "U.User", Value.Deny); manager.StoreEntry(entry1.Resource, entry1.Action, entry1.Subject, entry1.Value); manager.StoreEntry(entry2.Resource, entry2.Action, entry2.Subject, entry2.Value); manager.StoreEntry("Res2", "Action", "G.Group", Value.Deny); bool invokedDelete1 = false; bool invokedStore1 = false; bool invokedDelete2 = false; bool invokedStore2 = false; manager.AclChanged += delegate(object sender, AclChangedEventArgs e) { if (e.Change == Change.EntryDeleted) { Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); Assert.AreEqual("Res", e.Entries[0].Resource, "Wrong resource"); if (e.Entries[0].Action == entry1.Action) { invokedDelete1 = true; } if (e.Entries[0].Action == entry2.Action) { invokedDelete2 = true; } } else { Assert.AreEqual(1, e.Entries.Length, "Wrong entry count"); Assert.AreEqual("Res_Renamed", e.Entries[0].Resource, "Wrong resource"); if (e.Entries[0].Action == entry1.Action) { invokedStore1 = true; } if (e.Entries[0].Action == entry2.Action) { invokedStore2 = true; } } }; Assert.IsTrue(manager.RenameResource("Res", "Res_Renamed"), "RenameResource should return true"); Assert.IsTrue(invokedDelete1, "Delete event 1 not invoked"); Assert.IsTrue(invokedStore1, "Store event 1 not invoked"); Assert.IsTrue(invokedDelete2, "Delete event 2 not invoked"); Assert.IsTrue(invokedStore2, "Store event 2 not invoked"); AclEntry[] entries = manager.RetrieveAllEntries(); Assert.AreEqual(3, entries.Length, "Wrong entry count"); Array.Sort(entries, delegate(AclEntry x, AclEntry y) { return(x.Resource.CompareTo(y.Resource)); }); Assert.AreEqual("Res_Renamed", entries[0].Resource, "Wrong resource"); if (entries[0].Value == Value.Grant) { Assert.AreEqual("Action", entries[0].Action, "Wrong action"); Assert.AreEqual("U.User", entries[0].Subject, "Wrong subject"); } else { Assert.AreEqual("Action2", entries[0].Action, "Wrong action"); Assert.AreEqual("U.User2", entries[0].Subject, "Wrong subject"); } Assert.AreEqual("Res_Renamed", entries[1].Resource, "Wrong resource"); if (entries[1].Value == Value.Grant) { Assert.AreEqual("Action", entries[1].Action, "Wrong action"); Assert.AreEqual("U.User", entries[1].Subject, "Wrong subject"); } else { Assert.AreEqual("Action2", entries[1].Action, "Wrong action"); Assert.AreEqual("U.User2", entries[1].Subject, "Wrong subject"); } Assert.AreEqual("Res2", entries[2].Resource, "Wrong resource"); Assert.AreEqual("Action", entries[2].Action, "Wrong action"); Assert.AreEqual("G.Group", entries[2].Subject, "Wrong subject"); Assert.AreEqual(Value.Deny, entries[2].Value, "Wrong value"); }
public void StoreEntry_InvalidSubject(string s) { AclManagerBase manager = MockAclManager( ); manager.StoreEntry("Res", "Action", s, Value.Grant); }