Esempio n. 1
0
        public void AddUserToRole()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

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

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

            roleProvider.RemoveUsersFromRoles(new string[] { "eve" }, new string[] { "Administrator" });
            Assert.False(roleProvider.IsUserInRole("eve", "Administrator"));

            roleProvider.DeleteRole("Administrator", false);
            Assert.Equal(0, roleProvider.GetAllRoles().Length);

            //clean up
            membershipProvider.DeleteUser("eve", true);
        }
Esempio n. 2
0
        public RoleManagement()
        {
            membershipProvider = new MySQLMembershipProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            membershipProvider.Initialize(null, config);

            roleProvider = new MySQLRoleProvider();
            roleProvider.Initialize(null, config);
        }
Esempio n. 3
0
        public void AddNonExistingUserToRole()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                                         new string[] { "Administrator" });
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
        }
Esempio n. 4
0
        public void AddUserToRole()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            AddUser("eve", "eve");
            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                new string[] { "Administrator" });
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
            membershipProvider.DeleteUser("foo", false);
        }
        public void AttemptLatestSchemaVersion()
        {
            execSQL(string.Format("alter database `{0}` character set = 'utf32' collate = 'utf32_general_ci'", Connection.Database));
            for (int i = 1; i <= 4; i++)
            {
                LoadSchema(i);
            }
            MySQLRoleProvider   roleProvider = new MySQLRoleProvider();
            NameValueCollection config       = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            config.Add("autogenerateschema", "true");
            roleProvider.Initialize(null, config);
        }
Esempio n. 6
0
        public void IllegalRoleAndUserNames()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            AttemptToAddUserToRole("test", null);
            AttemptToAddUserToRole("test", "");
            roleProvider.CreateRole("Administrator");
            AttemptToAddUserToRole(null, "Administrator");
            AttemptToAddUserToRole("", "Administrator");
        }
Esempio n. 7
0
        public void IsUserInRoleCrossDomain()
        {
            MySQLMembershipProvider provider = new MySQLMembershipProvider();
            NameValueCollection     config1  = new NameValueCollection();

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

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

            MySQLMembershipProvider provider2 = new MySQLMembershipProvider();
            NameValueCollection     config2   = new NameValueCollection();

            config2.Add("connectionStringName", "LocalMySqlServer");
            config2.Add("applicationName", "/myapp");
            config2.Add("passwordStrengthRegularExpression", ".*");
            config2.Add("passwordFormat", "Clear");
            provider2.Initialize(null, config2);

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

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            MySQLRoleProvider   r2       = new MySQLRoleProvider();
            NameValueCollection configr2 = new NameValueCollection();

            configr2.Add("connectionStringName", "LocalMySqlServer");
            configr2.Add("applicationName", "/myapp");
            r2.Initialize(null, configr2);

            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "foo" },
                                         new string[] { "Administrator" });
            Assert.False(r2.IsUserInRole("foo", "Administrator"));

            roleProvider.DeleteRole("Administrator", false);
            Assert.AreEqual(0, roleProvider.GetAllRoles().Length);

            //Cleanup
            provider.DeleteUser("foo", true);
        }
Esempio n. 8
0
        public void CreateAndDeleteRoles()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            // Add the role
            roleProvider.CreateRole("Administrator");
            string[] roles = roleProvider.GetAllRoles();
            Assert.Equal(1, roles.Length);
            Assert.Equal("Administrator", roles[0]);
            roleProvider.DeleteRole("Administrator", false);
        }
Esempio n. 9
0
        public void CreateAndDeleteRoles()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("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);
        }
Esempio n. 10
0
        public void TestUserRemoveFindFromRole()
        {
            roleProvider = new MySQLRoleProvider();
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "LocalMySqlServer");
            config.Add("applicationName", "/");
            roleProvider.Initialize(null, config);

            AddUser("eve", "eveeve!");
            roleProvider.CreateRole("Administrator");
            roleProvider.AddUsersToRoles(new string[] { "eve" },
                                         new string[] { "Administrator" });
            Assert.IsTrue(roleProvider.IsUserInRole("eve", "Administrator"));
            string[] users = roleProvider.FindUsersInRole("Administrator", "eve");
            Assert.AreEqual(1, users.Length);
            Assert.AreEqual("eve", users[0]);
            roleProvider.RemoveUsersFromRoles(new string[] { "eve" }, new string[] { "Administrator" });
            Assert.IsFalse(roleProvider.IsUserInRole("eve", "Administrator"));
        }