public void VisibilityTest() { context.AccessLevel = EntityAccessLevel.Administrator; context.Execute("DELETE FROM pubserver;"); User user = new User(context); user.Username = "******"; user.Store(); User user2 = new User(context); user2.Username = "******"; user2.Store(); Group group = new Group(context); group.Name = "groupVis"; group.Identifier = "groupVis"; group.Store(); Group group2 = new Group(context); group2.Name = "groupVis2"; group2.Identifier = "groupVis2"; group2.Store(); group.AssignUser(user); PublishServer ppub = new PublishServer(context); ppub.Name = "public"; ppub.Protocol = "ftp"; ppub.Hostname = "test.org"; ppub.Store(); ppub.GrantPermissionsToAll(); PublishServer ppubresg = new PublishServer(context); ppubresg.Name = "public and assigned to group"; ppubresg.Protocol = "ftp"; ppubresg.Hostname = "test.org"; ppubresg.Store(); ppubresg.GrantPermissionsToAll(); ppubresg.GrantPermissionsToGroups(new Group[] { group }); PublishServer ppubresg2 = new PublishServer(context); ppubresg2.Name = "public and assigned to other group"; ppubresg2.Protocol = "ftp"; ppubresg2.Hostname = "test.org"; ppubresg2.Store(); ppubresg2.GrantPermissionsToAll(); ppubresg2.GrantPermissionsToGroups(new Group[] { group2 }); PublishServer ppubresu = new PublishServer(context); ppubresu.Name = "public and assigned to user"; ppubresu.Protocol = "ftp"; ppubresu.Hostname = "test.org"; ppubresu.Store(); ppubresu.GrantPermissionsToAll(); ppubresu.GrantPermissionsToUsers(new User[] { user }); PublishServer ppubresu2 = new PublishServer(context); ppubresu2.Name = "public and assigned to other user"; ppubresu2.Protocol = "ftp"; ppubresu2.Hostname = "test.org"; ppubresu2.Store(); ppubresu2.GrantPermissionsToAll(); ppubresu2.GrantPermissionsToUsers(new User[] { user2 }); PublishServer presg = new PublishServer(context); presg.Name = "restricted to group"; presg.Protocol = "ftp"; presg.Hostname = "test.org"; presg.Store(); presg.GrantPermissionsToGroups(new Group[] { group }); PublishServer presu = new PublishServer(context); presu.Name = "restricted to user"; presu.Protocol = "ftp"; presu.Hostname = "test.org"; presu.Store(); presu.GrantPermissionsToUsers(new User[] { user }); PublishServer powna = new PublishServer(context); powna.OwnerId = user.Id; powna.Name = "owned by user (shared with all)"; powna.Protocol = "ftp"; powna.Hostname = "test.org"; powna.Store(); powna.GrantPermissionsToAll(); PublishServer powng = new PublishServer(context); powng.OwnerId = user.Id; powng.Name = "owned by user (shared with group)"; powng.Protocol = "ftp"; powng.Hostname = "test.org"; powng.Store(); powng.GrantPermissionsToGroups(new Group[] { group }); PublishServer pownu = new PublishServer(context); pownu.OwnerId = user.Id; pownu.Name = "owned by user (shared with other user)"; pownu.Protocol = "ftp"; pownu.Hostname = "test.org"; pownu.Store(); pownu.GrantPermissionsToUsers(new User[] { user2 }); PublishServer pown = new PublishServer(context); pown.OwnerId = user.Id; pown.Name = "owned by user (exclusive)"; pown.Protocol = "ftp"; pown.Hostname = "test.org"; pown.Store(); PublishServer pn = new PublishServer(context); pn.Name = "not accessible"; pn.Protocol = "ftp"; pn.Hostname = "test.org"; pn.Store(); context.StartImpersonation(user.Id); context.AccessLevel = EntityAccessLevel.Privilege; EntityDictionary <PublishServer> pd = new EntityDictionary <PublishServer>(context); pd.ItemVisibility = EntityItemVisibility.All; pd.Load(); Assert.AreEqual(11, pd.Count); Assert.IsTrue(pd.Contains(ppub.Id)); Assert.AreEqual(EntityItemVisibility.Public, pd[ppub.Id].Visibility); Assert.IsTrue(pd.Contains(ppubresg.Id)); Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresg.Id].Visibility); Assert.IsTrue(pd.Contains(ppubresg2.Id)); Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresg2.Id].Visibility); Assert.IsTrue(pd.Contains(ppubresu.Id)); Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresu.Id].Visibility); Assert.IsTrue(pd.Contains(ppubresu2.Id)); Assert.AreEqual(EntityItemVisibility.Public, pd[ppubresu2.Id].Visibility); Assert.IsTrue(pd.Contains(presg.Id)); Assert.AreEqual(EntityItemVisibility.Restricted, pd[presg.Id].Visibility); Assert.IsTrue(pd.Contains(presu.Id)); Assert.AreEqual(EntityItemVisibility.Private, pd[presu.Id].Visibility); Assert.IsTrue(pd.Contains(powna.Id)); Assert.AreEqual(EntityItemVisibility.Public, pd[powna.Id].Visibility); Assert.IsTrue(pd.Contains(powng.Id)); Assert.AreEqual(EntityItemVisibility.Restricted, pd[powng.Id].Visibility); Assert.IsTrue(pd.Contains(pownu.Id)); Assert.AreEqual(EntityItemVisibility.Restricted, pd[pownu.Id].Visibility); Assert.IsTrue(pd.Contains(pown.Id)); Assert.AreEqual(EntityItemVisibility.Private, pd[pown.Id].Visibility); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Public; pd.Load(); Assert.AreEqual(6, pd.Count); Assert.IsTrue(pd.Contains(ppub.Id)); Assert.IsTrue(pd.Contains(ppubresg.Id)); Assert.IsTrue(pd.Contains(ppubresg2.Id)); Assert.IsTrue(pd.Contains(ppubresu.Id)); Assert.IsTrue(pd.Contains(ppubresu2.Id)); Assert.IsTrue(pd.Contains(powna.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Restricted; pd.Load(); Assert.AreEqual(3, pd.Count); Assert.IsTrue(pd.Contains(presg.Id)); Assert.IsTrue(pd.Contains(powng.Id)); Assert.IsTrue(pd.Contains(pownu.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Private; pd.Load(); Assert.AreEqual(2, pd.Count); Assert.IsTrue(pd.Contains(presu.Id)); Assert.IsTrue(pd.Contains(pown.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Public | EntityItemVisibility.Restricted; pd.Load(); Assert.AreEqual(9, pd.Count); Assert.IsTrue(pd.Contains(ppub.Id)); Assert.IsTrue(pd.Contains(ppubresg.Id)); Assert.IsTrue(pd.Contains(ppubresg2.Id)); Assert.IsTrue(pd.Contains(ppubresu.Id)); Assert.IsTrue(pd.Contains(ppubresu2.Id)); Assert.IsTrue(pd.Contains(presg.Id)); Assert.IsTrue(pd.Contains(powna.Id)); Assert.IsTrue(pd.Contains(powng.Id)); Assert.IsTrue(pd.Contains(pownu.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Public | EntityItemVisibility.Private; pd.Load(); Assert.AreEqual(8, pd.Count); Assert.IsTrue(pd.Contains(ppub.Id)); Assert.IsTrue(pd.Contains(ppubresg.Id)); Assert.IsTrue(pd.Contains(ppubresg2.Id)); Assert.IsTrue(pd.Contains(ppubresu.Id)); Assert.IsTrue(pd.Contains(ppubresu2.Id)); Assert.IsTrue(pd.Contains(presu.Id)); Assert.IsTrue(pd.Contains(powna.Id)); Assert.IsTrue(pd.Contains(pown.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.All | EntityItemVisibility.OwnedOnly; pd.Load(); Assert.AreEqual(4, pd.Count); Assert.IsTrue(pd.Contains(powna.Id)); Assert.IsTrue(pd.Contains(powng.Id)); Assert.IsTrue(pd.Contains(pownu.Id)); Assert.IsTrue(pd.Contains(pown.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Public | EntityItemVisibility.OwnedOnly; pd.Load(); Assert.AreEqual(1, pd.Count); Assert.IsTrue(pd.Contains(powna.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Restricted | EntityItemVisibility.OwnedOnly; pd.Load(); Assert.AreEqual(2, pd.Count); Assert.IsTrue(pd.Contains(powng.Id)); Assert.IsTrue(pd.Contains(pownu.Id)); pd.Clear(); pd.ItemVisibility = EntityItemVisibility.Private | EntityItemVisibility.OwnedOnly; pd.Load(); Assert.AreEqual(1, pd.Count); Assert.IsTrue(pd.Contains(pown.Id)); context.EndImpersonation(); }
public void OwnerFilterTest() { context.AccessLevel = EntityAccessLevel.Administrator; context.Execute("DELETE FROM usr WHERE username IN ('user1', 'user2', 'psmith');"); context.Execute("DELETE FROM pubserver;"); User user1 = new User(context); user1.Username = "******"; user1.FirstName = "John"; user1.LastName = "Doe"; user1.Store(); User user2 = new User(context); user2.Username = "******"; user2.FirstName = "Jane"; user2.LastName = "Doe"; user2.Store(); User user3 = new User(context); user3.Username = "******"; user3.FirstName = "Peter"; user3.LastName = "Smith"; user3.Store(); PublishServer p1 = new PublishServer(context); p1.Name = "p1"; p1.Protocol = "ftp"; p1.Hostname = "test1.org"; p1.FileRootDir = "/dir"; p1.OwnerId = user1.Id; p1.Store(); PublishServer p2 = new PublishServer(context); p2.Name = "p2"; p2.Protocol = "ftp"; p2.Hostname = "test2.org"; p2.FileRootDir = "/dir"; p2.OwnerId = user2.Id; p2.Store(); PublishServer p3 = new PublishServer(context); p3.Name = "p3"; p3.Protocol = "ftp"; p3.Hostname = "test3.org"; p3.FileRootDir = "/dir"; p3.OwnerId = user3.Id; p3.Store(); EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context); pd1.SearchKeyword = "doe"; pd1.IncludeOwnerFieldsInSearch = true; pd1.Load(); Assert.AreEqual(2, pd1.TotalResults); Assert.AreEqual(2, pd1.Count); Assert.IsTrue(pd1.Contains(p1.Id) && pd1.Contains(p2.Id)); EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context); pd2.SearchKeyword = "peter"; pd2.IncludeOwnerFieldsInSearch = true; context.ConsoleDebug = true; pd2.Load(); Assert.AreEqual(1, pd2.TotalResults); Assert.AreEqual(1, pd2.Count); Assert.IsTrue(pd2.Contains(p3.Id)); EntityDictionary <PublishServer> pd3 = new EntityDictionary <PublishServer>(context); pd3.SearchKeyword = "Smith"; pd3.IncludeOwnerFieldsInSearch = true; context.ConsoleDebug = true; pd3.Load(); Assert.AreEqual(1, pd3.TotalResults); Assert.AreEqual(1, pd3.Count); Assert.IsTrue(pd3.Contains(p3.Id)); }
public void KeywordFilterTest() { context.AccessLevel = EntityAccessLevel.Administrator; context.Execute("DELETE FROM pubserver;"); PublishServer p1 = new PublishServer(context); p1.Name = "pf1 abc def ghi"; p1.Protocol = "ftp"; p1.Hostname = "test.org"; p1.Store(); PublishServer p2 = new PublishServer(context); p2.Name = "pf2"; p2.Protocol = "ftp"; p2.Hostname = "def.org"; p2.Store(); PublishServer p3 = new PublishServer(context); p3.Name = "pf3"; p3.Protocol = "ftp"; p3.Hostname = "test.org"; p3.Path = "/ghi/jkl"; p3.Store(); PublishServer p4 = new PublishServer(context); p4.Name = "z*"; p4.Protocol = "z"; p4.Hostname = "z.org"; p4.Path = "/z"; p4.Store(); EntityDictionary <PublishServer> pd; pd = new EntityDictionary <PublishServer>(context); pd.SearchKeyword = "abc"; pd.Load(); Assert.AreEqual(1, pd.TotalResults); Assert.AreEqual(1, pd.Count); Assert.IsTrue(pd.Contains(p1.Id)); pd = new EntityDictionary <PublishServer>(context); pd.SearchKeyword = "def"; pd.Load(); Assert.AreEqual(2, pd.TotalResults); Assert.AreEqual(2, pd.Count); Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p2.Id)); pd = new EntityDictionary <PublishServer>(context); pd.SearchKeyword = "ghi"; pd.Load(); Assert.AreEqual(2, pd.TotalResults); Assert.AreEqual(2, pd.Count); Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p3.Id)); pd = new EntityDictionary <PublishServer>(context); pd.SearchKeyword = "de"; pd.FindWholeWords = true; pd.Load(); Assert.AreEqual(0, pd.TotalResults); Assert.AreEqual(0, pd.Count); pd = new EntityDictionary <PublishServer>(context); pd.SearchKeyword = "de"; pd.FindWholeWords = false; pd.Load(); Assert.AreEqual(2, pd.TotalResults); Assert.AreEqual(2, pd.Count); Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p2.Id)); pd = new EntityDictionary <PublishServer>(context); pd.SearchKeyword = "*"; pd.FindWholeWords = false; pd.Load(); Assert.AreEqual(4, pd.TotalResults); Assert.AreEqual(4, pd.Count); Assert.IsTrue(pd.Contains(p1.Id) && pd.Contains(p2.Id) && pd.Contains(p3.Id) && pd.Contains(p4.Id)); pd = new EntityDictionary <PublishServer>(context); pd.SearchKeyword = "z*"; pd.FindWholeWords = false; pd.LiteralSearch = true; pd.Load(); Assert.AreEqual(1, pd.TotalResults); Assert.AreEqual(1, pd.Count); Assert.IsTrue(pd.Contains(p4.Id)); }
public void FilterTest() { context.AccessLevel = EntityAccessLevel.Administrator; context.Execute("DELETE FROM domain;"); context.Execute("DELETE FROM pubserver;"); Domain testDomain1 = new Domain(context); testDomain1.Identifier = "domain1"; testDomain1.Store(); Domain testDomain2 = new Domain(context); testDomain2.Identifier = "domain2"; testDomain2.Store(); PublishServer p1 = new PublishServer(context); p1.Name = "pf1"; p1.Protocol = "ftp"; p1.Hostname = "test.org"; p1.Port = 23; p1.FileRootDir = "/dir1"; p1.Domain = testDomain1; p1.Store(); PublishServer p2 = new PublishServer(context); p2.Name = "pf2"; p2.Protocol = "ftp"; p2.Hostname = "anothertest.org"; p2.Port = 123; p2.FileRootDir = "/dir2"; p2.Store(); PublishServer p3a = new PublishServer(context); p3a.Name = "pf3a"; p3a.Protocol = "ftp"; p3a.Hostname = "experiment.org"; p3a.Port = 234; p3a.Store(); PublishServer p3b = new PublishServer(context); p3b.Name = "pf3b"; p3b.Protocol = "ftp"; p3b.Hostname = "try.org"; p3b.Port = 345; p3b.Domain = testDomain2; p3b.Store(); EntityDictionary <PublishServer> pd1 = new EntityDictionary <PublishServer>(context); pd1.SetFilter("Hostname", "*test*.org"); pd1.Load(); Assert.AreEqual(2, pd1.TotalResults); Assert.AreEqual(2, pd1.Count); Assert.IsTrue(pd1.Contains(p1.Id) && pd1.Contains(p2.Id)); EntityDictionary <PublishServer> pd2 = new EntityDictionary <PublishServer>(context); pd2.SetFilter("Port", "123"); pd2.Load(); Assert.AreEqual(1, pd2.TotalResults); Assert.AreEqual(1, pd2.Count); Assert.IsTrue(pd2.Contains(p2.Id)); EntityDictionary <PublishServer> pd3 = new EntityDictionary <PublishServer>(context); pd3.SetFilter("Port", "[234"); pd3.Load(); Assert.AreEqual(2, pd3.TotalResults); Assert.AreEqual(2, pd3.Count); Assert.IsTrue(pd3.Contains(p3a.Id) && pd3.Contains(p3b.Id)); EntityDictionary <PublishServer> pd4 = new EntityDictionary <PublishServer>(context); pd4.SetFilter("Port", "]100,300["); pd4.Load(); Assert.AreEqual(2, pd4.TotalResults); Assert.AreEqual(2, pd4.Count); Assert.IsTrue(pd4.Contains(p2.Id) && pd4.Contains(p3a.Id)); EntityDictionary <PublishServer> pd5 = new EntityDictionary <PublishServer>(context); pd5.SetFilter("Name", "pf3*"); pd5.Load(); Assert.AreEqual(2, pd5.TotalResults); Assert.AreEqual(2, pd5.Count); Assert.IsTrue(pd5.Contains(p3a.Id) && pd3.Contains(p3b.Id)); EntityDictionary <PublishServer> pd6 = new EntityDictionary <PublishServer>(context); pd6.SetFilter("FileRootDir", SpecialSearchValue.Null); pd6.Load(); Assert.AreEqual(2, pd6.TotalResults); Assert.AreEqual(2, pd6.Count); Assert.IsTrue(pd6.Contains(p3a.Id) && pd6.Contains(p3b.Id)); EntityDictionary <PublishServer> pd7 = new EntityDictionary <PublishServer>(context); pd7.SetFilter("FileRootDir", SpecialSearchValue.NotNull); pd7.Load(); Assert.AreEqual(2, pd7.TotalResults); Assert.AreEqual(2, pd7.Count); Assert.IsTrue(pd7.Contains(p1.Id) && pd7.Contains(p2.Id)); EntityDictionary <PublishServer> pd8 = new EntityDictionary <PublishServer>(context); pd8.SetFilter("FileRootDir", new object[] { "/dir2", SpecialSearchValue.Null }); pd8.Load(); Assert.AreEqual(3, pd8.TotalResults); Assert.AreEqual(3, pd8.Count); Assert.IsTrue(pd8.Contains(p2.Id) && pd8.Contains(p3a.Id) && pd8.Contains(p3b.Id)); EntityDictionary <PublishServer> pd9 = new EntityDictionary <PublishServer>(context); pd9.SetFilter("DomainId", new object[] { testDomain1.Id, SpecialSearchValue.Null }); pd9.Load(); Assert.AreEqual(3, pd9.TotalResults); Assert.AreEqual(3, pd9.Count); Assert.IsTrue(pd9.Contains(p1.Id) && pd9.Contains(p2.Id) && pd9.Contains(p3a.Id)); }