예제 #1
0
        public void FindUsersInRoleTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("evelyn", "eveeve!");
            AddUser("emily", "eveeve!");
            AddUser("robert", "eveeve!");
            AddUser("carly", "eveeve!");
            roleProvider.CreateRole("User");

            roleProvider.AddUsersToRoles(new string[] { "eve", "evelyn", "emily", "robert", "carly" },
                                         new string[] { "User" });

            // no % (startsWith)
            var users = roleProvider.FindUsersInRole("User", "eve");

            Assert.AreEqual(2, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("evelyn"));

            users = roleProvider.FindUsersInRole("User", "bob");
            Assert.AreEqual(0, users.Length);

            users = roleProvider.FindUsersInRole("User", "obert");
            Assert.AreEqual(0, users.Length);

            // StartsWith
            users = roleProvider.FindUsersInRole("User", "eve%");
            Assert.AreEqual(2, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("evelyn"));

            users = roleProvider.FindUsersInRole("User", "bob%");
            Assert.AreEqual(0, users.Length);

            // EndsWith
            users = roleProvider.FindUsersInRole("User", "%ly");
            Assert.AreEqual(2, users.Length);
            Assert.IsTrue(users.Contains("emily"));
            Assert.IsTrue(users.Contains("carly"));

            users = roleProvider.FindUsersInRole("User", "%ark");
            Assert.AreEqual(0, users.Length);

            // Contains
            users = roleProvider.FindUsersInRole("User", "%ly%");
            Assert.AreEqual(3, users.Length);
            Assert.IsTrue(users.Contains("evelyn"));
            Assert.IsTrue(users.Contains("emily"));
            Assert.IsTrue(users.Contains("carly"));

            users = roleProvider.FindUsersInRole("User", "%bob%");
            Assert.AreEqual(0, users.Length);
        }
예제 #2
0
        public void AddUsersToRoles()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");
            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2" },
                                         new string[] { "Administrator", "User" });
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "User"));
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "User"));
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Editor"));

            roleProvider.AddUsersToRoles(new string[] { "eve3" },
                                         new string[] { "Editor", "User" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve3", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "User"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "Editor"));
        }
예제 #3
0
        public void RemoveUsersFromRoles()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");


            // test with one user
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                                         new string[] { "Editor", "User" });
            Assert.AreEqual(2, roleProvider.GetRolesForUser("eve").Length);
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "User"));

            // remove User role
            roleProvider.RemoveUsersFromRoles(new string[] { "eve" }, new string[] { "User" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "User"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.AreEqual(1, roleProvider.GetRolesForUser("eve").Length);

            // try remove again
            roleProvider.RemoveUsersFromRoles(new string[] { "eve" }, new string[] { "User" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "User"));



            // test with two users
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Administrator"));
            roleProvider.AddUsersToRoles(new string[] { "eve2", "eve3" },
                                         new string[] { "Administrator", "User" });
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "Administrator"));

            // remove admin role
            roleProvider.RemoveUsersFromRoles(new string[] { "eve2" }, new string[] { "Administrator" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "User"));
            Assert.AreEqual(1, roleProvider.GetRolesForUser("eve2").Length);
            Assert.AreEqual("user", roleProvider.GetRolesForUser("eve2")[0]);


            // verify didn't touch other user
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "Administrator"));


            // try remove again
            roleProvider.RemoveUsersFromRoles(new string[] { "eve2" }, new string[] { "Administrator" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Administrator"));
        }
예제 #4
0
        public void IllegalRoleAndUserNames()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AttemptToAddUserToRole("test", null);
            AttemptToAddUserToRole("test", "");
            roleProvider.CreateRole("Administrator");
            AttemptToAddUserToRole(null, "Administrator");
            AttemptToAddUserToRole("", "Administrator");
        }
예제 #5
0
        public void GetUsersInRoleTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            AddUser("eve4", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2", "eve3", "eve4" },
                                         new string[] { "User" });
            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2" },
                                         new string[] { "Editor" });
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                                         new string[] { "Administrator" });

            var users   = roleProvider.GetUsersInRole("User");
            var editors = roleProvider.GetUsersInRole("Editor");
            var admins  = roleProvider.GetUsersInRole("Administrator");


            Assert.AreEqual(4, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("eve2"));
            Assert.IsTrue(users.Contains("eve3"));
            Assert.IsTrue(users.Contains("eve4"));

            Assert.AreEqual(2, editors.Length);
            Assert.IsTrue(editors.Contains("eve"));
            Assert.IsTrue(editors.Contains("eve2"));
            Assert.IsFalse(editors.Contains("eve3"));
            Assert.IsFalse(editors.Contains("eve4"));

            Assert.AreEqual(1, admins.Length);
            Assert.IsTrue(admins.Contains("eve"));
            Assert.IsFalse(admins.Contains("eve2"));
            Assert.IsFalse(admins.Contains("eve3"));
            Assert.IsFalse(admins.Contains("eve4"));
        }
예제 #6
0
        public void AddNonExistingUserToRole()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                new string[] { "Administrator" });

            // adrian:
            // The original MySQL Connector Unit Tests use IsTrue but I don't think that makes
            // sense.  If user is non-existant the role mapping should not occur.
            //Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "Administrator"));
        }
예제 #7
0
        public override void Setup()
        {
            base.Setup();


            membershipProvider = new MongoProviders.MembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            membershipProvider.Initialize(null, config);

            roleProvider = new RoleProvider();
            config       = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);
        }
예제 #8
0
        public void RoleExistsTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");


            Assert.IsTrue(roleProvider.RoleExists("Administrator"));
            Assert.IsTrue(roleProvider.RoleExists("User"));
            Assert.IsTrue(roleProvider.RoleExists("Editor"));
            Assert.IsFalse(roleProvider.RoleExists("Jack"));
        }
예제 #9
0
        public void AddNonExistingUserToRole()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                                         new string[] { "Administrator" });

            // adrian:
            // The original MySQL Connector Unit Tests use IsTrue but I don't think that makes
            // sense.  If user is non-existant the role mapping should not occur.
            //Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "Administrator"));
        }
예제 #10
0
        public void IsUserInRoleCrossDomain()
        {
            var provider = new MongoProviders.MembershipProvider();
            NameValueCollection config1 = new NameValueCollection();

            config1.Add("connectionStringName", _connStrName);
            config1.Add("applicationName", _applicationName);
            config1.Add("passwordStrengthRegularExpression", "bar.*");
            config1.Add("passwordFormat", "Clear");
            provider.Initialize(null, config1);
            MembershipCreateStatus status;

            provider.CreateUser("foo", "bar!bar", "*****@*****.**", null, null, true, null, out status);

            var provider2 = new MongoProviders.MembershipProvider();
            NameValueCollection config2 = new NameValueCollection();

            config2.Add("connectionStringName", _connStrName);
            config2.Add("applicationName", _appName2);
            config2.Add("passwordStrengthRegularExpression", ".*");
            config2.Add("passwordFormat", "Clear");
            provider2.Initialize(null, config2);

            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            MongoProviders.RoleProvider r2       = new MongoProviders.RoleProvider();
            NameValueCollection         configr2 = new NameValueCollection();

            configr2.Add("connectionStringName", _connStrName);
            configr2.Add("applicationName", _appName2);
            r2.Initialize(null, configr2);

            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "foo" },
                                         new string[] { "Administrator" });
            Assert.IsFalse(r2.IsUserInRole("foo", "Administrator"));
        }
예제 #11
0
        public void CreateAndDeleteRoles()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            // Add the role
            roleProvider.CreateRole("Administrator");
            string[] roles = roleProvider.GetAllRoles();
            Assert.AreEqual(1, roles.Length);
            Assert.AreEqual("administrator", roles[0]);

            // now delete the role
            roleProvider.DeleteRole("Administrator", false);
            roles = roleProvider.GetAllRoles();
            Assert.AreEqual(0, roles.Length);
        }
예제 #12
0
        public void GetAllRolesTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");


            var roles = roleProvider.GetAllRoles();

            Assert.AreEqual(3, roles.Length);
            Assert.IsTrue(roles.Contains("administrator"));
            Assert.IsTrue(roles.Contains("user"));
            Assert.IsTrue(roles.Contains("editor"));
        }
예제 #13
0
        public void GetRolesForUserTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve" },
                                         new string[] { "Editor", "User", "Administrator" });
            Assert.AreEqual(3, roleProvider.GetRolesForUser("eve").Length);
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "User"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
        }
예제 #14
0
        public void ExampleOfHowToQueryArray()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("evelyn", "eveeve!");
            AddUser("emily", "eveeve!");
            AddUser("robert", "eveeve!");
            AddUser("carly", "eveeve!");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve", "evelyn", "emily", "robert", "carly" },
                                         new string[] { "User" });
            roleProvider.AddUsersToRoles(new string[] { "emily", "robert", "carly" },
                                         new string[] { "Editor" });

            var fb = new FilterDefinitionBuilder <BsonDocument>();

            var cursor = _db.GetCollection <BsonDocument>(roleProvider.UserCollectionName).Find(fb.Eq("roles", "editor"));
            // cursor.SetFields(Fields.Include("lname").Exclude("_id"));

            var names = new List <string>();

            foreach (var doc in cursor.ToEnumerable())
            {
                var str = doc["lname"].AsString;
                names.Add(str);
            }

            Assert.AreEqual(3, names.Count);
        }
예제 #15
0
        public override void Setup()
        {
            base.Setup();

            membershipProvider = new MongoProviders.MembershipProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            membershipProvider.Initialize(null, config);

            roleProvider = new RoleProvider();
            config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);
        }
예제 #16
0
        public void RemoveUsersFromRoles()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            // test with one user
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                new string[] { "Editor", "User" });
            Assert.AreEqual(2, roleProvider.GetRolesForUser("eve").Length);
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "User"));

            // remove User role
            roleProvider.RemoveUsersFromRoles(new string[] { "eve" }, new string[] { "User" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "User"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.AreEqual(1, roleProvider.GetRolesForUser("eve").Length);

            // try remove again
            roleProvider.RemoveUsersFromRoles(new string[] { "eve" }, new string[] { "User" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "User"));

            // test with two users
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Administrator"));
            roleProvider.AddUsersToRoles(new string[] { "eve2", "eve3" },
                new string[] { "Administrator", "User" });
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "Administrator"));

            // remove admin role
            roleProvider.RemoveUsersFromRoles(new string[] { "eve2" }, new string[] { "Administrator" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "User"));
            Assert.AreEqual(1, roleProvider.GetRolesForUser("eve2").Length);
            Assert.AreEqual("user", roleProvider.GetRolesForUser("eve2")[0]);

            // verify didn't touch other user
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "Administrator"));

            // try remove again
            roleProvider.RemoveUsersFromRoles(new string[] { "eve2" }, new string[] { "Administrator" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Administrator"));
        }
예제 #17
0
        public void RoleExistsTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            Assert.IsTrue(roleProvider.RoleExists("Administrator"));
            Assert.IsTrue(roleProvider.RoleExists("User"));
            Assert.IsTrue(roleProvider.RoleExists("Editor"));
            Assert.IsFalse(roleProvider.RoleExists("Jack"));
        }
예제 #18
0
        public void IllegalRoleAndUserNames()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AttemptToAddUserToRole("test", null);
            AttemptToAddUserToRole("test", "");
            roleProvider.CreateRole("Administrator");
            AttemptToAddUserToRole(null, "Administrator");
            AttemptToAddUserToRole("", "Administrator");
        }
예제 #19
0
        public void IsUserInRoleCrossDomain()
        {
            var provider = new MongoProviders.MembershipProvider();
            NameValueCollection config1 = new NameValueCollection();
            config1.Add("connectionStringName", _connStrName);
            config1.Add("applicationName", _applicationName);
            config1.Add("passwordStrengthRegularExpression", "bar.*");
            config1.Add("passwordFormat", "Clear");
            provider.Initialize(null, config1);
            MembershipCreateStatus status;
            provider.CreateUser("foo", "bar!bar", "*****@*****.**", null, null, true, null, out status);

            var provider2 = new MongoProviders.MembershipProvider();
            NameValueCollection config2 = new NameValueCollection();
            config2.Add("connectionStringName", _connStrName);
            config2.Add("applicationName", _appName2);
            config2.Add("passwordStrengthRegularExpression", ".*");
            config2.Add("passwordFormat", "Clear");
            provider2.Initialize(null, config2);

            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            MongoProviders.RoleProvider r2 = new MongoProviders.RoleProvider();
            NameValueCollection configr2 = new NameValueCollection();
            configr2.Add("connectionStringName", _connStrName);
            configr2.Add("applicationName", _appName2);
            r2.Initialize(null, configr2);

            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "foo" },
                new string[] { "Administrator" });
            Assert.IsFalse(r2.IsUserInRole("foo", "Administrator"));
        }
예제 #20
0
        public void GetUsersInRoleTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            AddUser("eve4", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2", "eve3", "eve4" },
                new string[] { "User" });
            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2" },
                new string[] { "Editor" });
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                new string[] { "Administrator" });

            var users = roleProvider.GetUsersInRole("User");
            var editors = roleProvider.GetUsersInRole("Editor");
            var admins = roleProvider.GetUsersInRole("Administrator");

            Assert.AreEqual(4, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("eve2"));
            Assert.IsTrue(users.Contains("eve3"));
            Assert.IsTrue(users.Contains("eve4"));

            Assert.AreEqual(2, editors.Length);
            Assert.IsTrue(editors.Contains("eve"));
            Assert.IsTrue(editors.Contains("eve2"));
            Assert.IsFalse(editors.Contains("eve3"));
            Assert.IsFalse(editors.Contains("eve4"));

            Assert.AreEqual(1, admins.Length);
            Assert.IsTrue(admins.Contains("eve"));
            Assert.IsFalse(admins.Contains("eve2"));
            Assert.IsFalse(admins.Contains("eve3"));
            Assert.IsFalse(admins.Contains("eve4"));
        }
예제 #21
0
        public void GetRolesForUserTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve" },
                new string[] { "Editor", "User", "Administrator"});
            Assert.AreEqual(3, roleProvider.GetRolesForUser("eve").Length);
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "User"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
        }
예제 #22
0
        public void GetAllRolesTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            var roles = roleProvider.GetAllRoles();
            Assert.AreEqual(3, roles.Length);
            Assert.IsTrue(roles.Contains("administrator"));
            Assert.IsTrue(roles.Contains("user"));
            Assert.IsTrue(roles.Contains("editor"));
        }
예제 #23
0
        public void FindUsersInRoleTest()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("evelyn", "eveeve!");
            AddUser("emily", "eveeve!");
            AddUser("robert", "eveeve!");
            AddUser("carly", "eveeve!");
            roleProvider.CreateRole("User");

            roleProvider.AddUsersToRoles(new string[] { "eve", "evelyn", "emily", "robert", "carly" },
                new string[] { "User" });

            // no % (startsWith)
            var users = roleProvider.FindUsersInRole("User", "eve");
            Assert.AreEqual(2, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("evelyn"));

            users = roleProvider.FindUsersInRole("User", "bob");
            Assert.AreEqual(0, users.Length);

            users = roleProvider.FindUsersInRole("User", "obert");
            Assert.AreEqual(0, users.Length);

            // StartsWith
            users = roleProvider.FindUsersInRole("User", "eve%");
            Assert.AreEqual(2, users.Length);
            Assert.IsTrue(users.Contains("eve"));
            Assert.IsTrue(users.Contains("evelyn"));

            users = roleProvider.FindUsersInRole("User", "bob%");
            Assert.AreEqual(0, users.Length);

            // EndsWith
            users = roleProvider.FindUsersInRole("User", "%ly");
            Assert.AreEqual(2, users.Length);
            Assert.IsTrue(users.Contains("emily"));
            Assert.IsTrue(users.Contains("carly"));

            users = roleProvider.FindUsersInRole("User", "%ark");
            Assert.AreEqual(0, users.Length);

            // Contains
            users = roleProvider.FindUsersInRole("User", "%ly%");
            Assert.AreEqual(3, users.Length);
            Assert.IsTrue(users.Contains("evelyn"));
            Assert.IsTrue(users.Contains("emily"));
            Assert.IsTrue(users.Contains("carly"));

            users = roleProvider.FindUsersInRole("User", "%bob%");
            Assert.AreEqual(0, users.Length);
        }
예제 #24
0
        public void ExampleOfHowToQueryArray()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("evelyn", "eveeve!");
            AddUser("emily", "eveeve!");
            AddUser("robert", "eveeve!");
            AddUser("carly", "eveeve!");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");

            roleProvider.AddUsersToRoles(new string[] { "eve", "evelyn", "emily", "robert", "carly" },
                new string[] { "User" });
            roleProvider.AddUsersToRoles(new string[] { "emily", "robert", "carly" },
                new string[] { "Editor" });

            var cursor = _db.GetCollection(roleProvider.UserCollectionName).Find(Query.EQ("roles", "editor"));
            cursor.SetFields(Fields.Include("lname").Exclude("_id"));

            var names = new List<string>();
            foreach (var doc in cursor)
            {
                var str = doc["lname"].AsString;
                names.Add(str);
            }

            Assert.AreEqual(3, names.Count);
        }
예제 #25
0
        public void AddUsersToRoles()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            AddUser("eve2", "eveeve!");
            AddUser("eve3", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.CreateRole("User");
            roleProvider.CreateRole("Editor");
            roleProvider.AddUsersToRoles(new string[] { "eve", "eve2" },
                new string[] { "Administrator", "User" });
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "User"));
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "Editor"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve2", "User"));
            Assert.IsFalse(roleProvider.IsUserInRole("eve2", "Editor"));

            roleProvider.AddUsersToRoles(new string[] { "eve3" },
                new string[] { "Editor", "User" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve3", "Administrator"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "User"));
            Assert.IsTrue(roleProvider.IsUserInRole("eve3", "Editor"));
        }
예제 #26
0
        public void CreateAndDeleteRoles()
        {
            roleProvider = new RoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("applicationName", _applicationName);
            roleProvider.Initialize(null, config);

            // Add the role
            roleProvider.CreateRole("Administrator");
            string[] roles = roleProvider.GetAllRoles();
            Assert.AreEqual(1, roles.Length);
            Assert.AreEqual("administrator", roles[0]);

            // now delete the role
            roleProvider.DeleteRole("Administrator", false);
            roles = roleProvider.GetAllRoles();
            Assert.AreEqual(0, roles.Length);
        }