예제 #1
0
        public virtual void TestAddRemoveAPI()
        {
            AccessControlList    acl;
            ICollection <string> users;
            ICollection <string> groups;

            acl = new AccessControlList(" ");
            Assert.Equal(0, acl.GetUsers().Count);
            Assert.Equal(0, acl.GetGroups().Count);
            Assert.Equal(" ", acl.GetAclString());
            acl.AddUser("drwho");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 1);
            Assert.Equal(users.GetEnumerator().Next(), "drwho");
            Assert.Equal("drwho ", acl.GetAclString());
            acl.AddGroup("tardis");
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 1);
            Assert.Equal(groups.GetEnumerator().Next(), "tardis");
            Assert.Equal("drwho tardis", acl.GetAclString());
            acl.AddUser("joe");
            acl.AddGroup("users");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 2);
            IEnumerator <string> iter = users.GetEnumerator();

            Assert.Equal(iter.Next(), "drwho");
            Assert.Equal(iter.Next(), "joe");
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 2);
            iter = groups.GetEnumerator();
            Assert.Equal(iter.Next(), "tardis");
            Assert.Equal(iter.Next(), "users");
            Assert.Equal("drwho,joe tardis,users", acl.GetAclString());
            acl.RemoveUser("joe");
            acl.RemoveGroup("users");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 1);
            NUnit.Framework.Assert.IsFalse(users.Contains("joe"));
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 1);
            NUnit.Framework.Assert.IsFalse(groups.Contains("users"));
            Assert.Equal("drwho tardis", acl.GetAclString());
            acl.RemoveGroup("tardis");
            groups = acl.GetGroups();
            Assert.Equal(0, groups.Count);
            NUnit.Framework.Assert.IsFalse(groups.Contains("tardis"));
            Assert.Equal("drwho ", acl.GetAclString());
            acl.RemoveUser("drwho");
            Assert.Equal(0, users.Count);
            NUnit.Framework.Assert.IsFalse(users.Contains("drwho"));
            Assert.Equal(0, acl.GetGroups().Count);
            Assert.Equal(0, acl.GetUsers().Count);
            Assert.Equal(" ", acl.GetAclString());
        }
예제 #2
0
        public virtual void TestAccessControlList()
        {
            AccessControlList    acl;
            ICollection <string> users;
            ICollection <string> groups;

            acl   = new AccessControlList("drwho tardis");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 1);
            Assert.Equal(users.GetEnumerator().Next(), "drwho");
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 1);
            Assert.Equal(groups.GetEnumerator().Next(), "tardis");
            acl   = new AccessControlList("drwho");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 1);
            Assert.Equal(users.GetEnumerator().Next(), "drwho");
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 0);
            acl   = new AccessControlList("drwho ");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 1);
            Assert.Equal(users.GetEnumerator().Next(), "drwho");
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 0);
            acl   = new AccessControlList(" tardis");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 0);
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 1);
            Assert.Equal(groups.GetEnumerator().Next(), "tardis");
            IEnumerator <string> iter;

            acl   = new AccessControlList("drwho,joe tardis, users");
            users = acl.GetUsers();
            Assert.Equal(users.Count, 2);
            iter = users.GetEnumerator();
            Assert.Equal(iter.Next(), "drwho");
            Assert.Equal(iter.Next(), "joe");
            groups = acl.GetGroups();
            Assert.Equal(groups.Count, 2);
            iter = groups.GetEnumerator();
            Assert.Equal(iter.Next(), "tardis");
            Assert.Equal(iter.Next(), "users");
        }