public Initialize ( string name, |
||
name | string | The name of the |
config | A collection of the name/value pairs representing the /// provider-specific attributes specified in the configuration for this provider. | |
Результат | void |
public void SchemaCheck() { for (int i = 0; i <= SchemaManager.Version; i++) { DropAllTables(); MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordFormat", "Clear"); if (i > 0) for (int x = 1; x <= i; x++) LoadSchema(x); try { provider.Initialize(null, config); if (i < SchemaManager.Version) Assert.Fail("Should have failed"); } catch (ProviderException) { if (i == SchemaManager.Version) Assert.Fail("This should not have failed"); } } }
public void ChangeAppName() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordStrengthRegularExpression", "bar.*"); config.Add("passwordFormat", "Clear"); provider.Initialize(null, config); MembershipCreateStatus status; provider.CreateUser("foo", "bar!bar", null, null, null, true, null, out status); Assert.IsTrue(status == MembershipCreateStatus.Success); MySQLMembershipProvider provider2 = new MySQLMembershipProvider(); NameValueCollection config2 = new NameValueCollection(); config2.Add("connectionStringName", "LocalMySqlServer"); config2.Add("applicationName", "/myapp"); config2.Add("passwordStrengthRegularExpression", "foo.*"); config2.Add("passwordFormat", "Clear"); provider2.Initialize(null, config2); provider2.CreateUser("foo2", "foo!foo", null, null, null, true, null, out status); Assert.IsTrue(status == MembershipCreateStatus.Success); provider.ApplicationName = "/myapp"; Assert.IsFalse(provider.ValidateUser("foo", "bar!bar")); Assert.IsTrue(provider.ValidateUser("foo2", "foo!foo")); }
public override void Setup() { base.Setup(); execSQL("DROP TABLE IF EXISTS mysql_membership"); execSQL("DROP TABLE IF EXISTS mysql_roles"); membershipProvider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); membershipProvider.Initialize(null, config); }
public void CurrentSchema() { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); provider.Initialize(null, config); MySqlCommand cmd = new MySqlCommand("SHOW CREATE TABLE mysql_membership", conn); using (MySqlDataReader reader = cmd.ExecuteReader()) { reader.Read(); string createTable = reader.GetString(1); int index = createTable.IndexOf("COMMENT='2'"); Assert.AreNotEqual(-1, index); } }
public void SchemaNotPresent() { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordFormat", "Clear"); try { provider.Initialize(null, config); Assert.Fail("Should have failed"); } catch (ProviderException) { } }
private void CreateUserWithFormat(MembershipPasswordFormat format) { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordStrengthRegularExpression", "bar.*"); config.Add("passwordFormat", format.ToString()); provider.Initialize(null, config); // create the user MembershipCreateStatus status; provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status); Assert.AreEqual(MembershipCreateStatus.Success, status); // verify that the password format is hashed. DataTable table = FillTable("SELECT * FROM my_aspnet_Membership"); MembershipPasswordFormat rowFormat = (MembershipPasswordFormat)Convert.ToInt32(table.Rows[0]["PasswordFormat"]); Assert.AreEqual(format, rowFormat); // then attempt to verify the user Assert.IsTrue(provider.ValidateUser("foo", "barbar!")); }
public void CreateUserWithNoQA() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "true"); config.Add("passwordFormat", "clear"); config.Add("applicationName", "/"); provider.Initialize(null, config); try { provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", null, true, null, out status); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.StartsWith("Password answer supplied is invalid")); } try { provider.CreateUser("foo", "barbar!", "*****@*****.**", "", "blue", true, null, out status); Assert.Fail(); } catch (Exception ex) { Assert.IsTrue(ex.Message.StartsWith("Password question supplied is invalid")); } }
private void GetPasswordHelper(bool requireQA, bool enablePasswordRetrieval, string answer) { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", requireQA ? "true" : "false"); config.Add("enablePasswordRetrieval", enablePasswordRetrieval ? "true" : "false"); config.Add("passwordFormat", "clear"); config.Add("applicationName", "/"); provider.Initialize(null, config); provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status); try { string password = provider.GetPassword("foo", answer); if (!enablePasswordRetrieval) Assert.Fail("This should have thrown an exception"); Assert.AreEqual("barbar!", password); } catch (ProviderException) { if (requireQA && answer != null) Assert.Fail("This should not have thrown an exception"); } }
public void DeleteUser() { CreateUserWithHashedPassword(); Assert.IsTrue(provider.DeleteUser("foo", true)); DataTable table = FillTable("SELECT * FROM my_aspnet_Membership"); Assert.AreEqual(0, table.Rows.Count); table = FillTable("SELECT * FROM my_aspnet_Users"); Assert.AreEqual(0, table.Rows.Count); CreateUserWithHashedPassword(); provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); provider.Initialize(null, config); Assert.IsTrue(Membership.DeleteUser("foo", false)); table = FillTable("SELECT * FROM my_aspnet_Membership"); Assert.AreEqual(0, table.Rows.Count); table = FillTable("SELECT * FROM my_aspnet_Users"); Assert.AreEqual(1, table.Rows.Count); }
public void CreateUserWithErrors() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordStrengthRegularExpression", "bar.*"); config.Add("passwordFormat", "Hashed"); provider.Initialize(null, config); // first try to create a user with a password not long enough MembershipCreateStatus status; MembershipUser user = provider.CreateUser("foo", "xyz", "*****@*****.**", null, null, true, null, out status); Assert.IsNull(user); Assert.AreEqual(MembershipCreateStatus.InvalidPassword, status); // now with not enough non-alphas user = provider.CreateUser("foo", "xyz1234", "*****@*****.**", null, null, true, null, out status); Assert.IsNull(user); Assert.AreEqual(MembershipCreateStatus.InvalidPassword, status); // now one that doesn't pass the regex test user = provider.CreateUser("foo", "xyzxyz!", "*****@*****.**", null, null, true, null, out status); Assert.IsNull(user); Assert.AreEqual(MembershipCreateStatus.InvalidPassword, status); // now one that works user = provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status); Assert.IsNotNull(user); Assert.AreEqual(MembershipCreateStatus.Success, status); }
public void ResetPassword() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordStrengthRegularExpression", "bar.*"); config.Add("passwordFormat", "Clear"); config.Add("requiresQuestionAndAnswer", "false"); provider.Initialize(null, config); MembershipCreateStatus status; provider.CreateUser("foo", "bar!bar", null, null, null, true, null, out status); MembershipUser u = provider.GetUser("foo", false); string newpw = provider.ResetPassword("foo", null); }
public void CrossAppLogin() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("passwordStrengthRegularExpression", "bar.*"); config.Add("passwordFormat", "Clear"); provider.Initialize(null, config); 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); bool worked = provider2.ValidateUser("foo", "bar!bar"); Assert.AreEqual(false, worked); }
public void GetPasswordWithWrongAnswer() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "true"); config.Add("enablePasswordRetrieval", "true"); config.Add("passwordFormat", "Encrypted"); config.Add("applicationName", "/"); provider.Initialize(null, config); provider.CreateUser("foo", "barbar!", "*****@*****.**", "color", "blue", true, null, out status); MySQLMembershipProvider provider2 = new MySQLMembershipProvider(); NameValueCollection config2 = new NameValueCollection(); config2.Add("connectionStringName", "LocalMySqlServer"); config2.Add("requiresQuestionAndAnswer", "true"); config2.Add("enablePasswordRetrieval", "true"); config2.Add("passwordFormat", "Encrypted"); config2.Add("applicationName", "/"); provider2.Initialize(null, config2); try { string pw = provider2.GetPassword("foo", "wrong"); Assert.Fail("Should have failed"); } catch (MembershipPasswordException) { } }
public void InitializeInvalidConnStringThrowsArgumentException() { Configuration configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string connStr = configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString; string fakeConnectionString = connStr.Replace("database", "fooKey"); try { configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString = fakeConnectionString; configFile.Save(); ConfigurationManager.RefreshSection("connectionStrings"); MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); provider.Initialize(null, config); } finally { configFile.ConnectionStrings.ConnectionStrings["LocalMySqlServer"].ConnectionString = connStr; configFile.Save(); ConfigurationManager.RefreshSection("connectionStrings"); } }
public void AutoGenerateSchema() { MySQLMembershipProvider provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("autogenerateschema", "true"); config.Add("applicationName", "/"); config.Add("passwordFormat", "Clear"); provider.Initialize(null, config); MembershipCreateStatus status; MembershipUser user = provider.CreateUser("boo", "password", "*****@*****.**", "question", "answer", true, null, out status); }
public void MinRequiredAlpha() { provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("applicationName", "/"); config.Add("minRequiredNonalphanumericCharacters", "3"); provider.Initialize(null, config); MembershipCreateStatus status; MembershipUser user = provider.CreateUser("foo", "pw!pass", "email", null, null, true, null, out status); Assert.IsNull(user); user = provider.CreateUser("foo", "pw!pa!!", "email", null, null, true, null, out status); Assert.IsNotNull(user); }
public void GetEncryptedPassword() { MembershipCreateStatus status; provider = new MySQLMembershipProvider(); NameValueCollection config = new NameValueCollection(); config.Add("connectionStringName", "LocalMySqlServer"); config.Add("requiresQuestionAndAnswer", "false"); config.Add("enablePasswordRetrieval", "true"); config.Add("passwordFormat", "encrypted"); config.Add("applicationName", "/"); provider.Initialize(null, config); MembershipUser user = provider.CreateUser("foo", "barbar!", "*****@*****.**", null, null, true, null, out status); Assert.IsNotNull(user); string pw = provider.GetPassword("foo", null); Assert.AreEqual("barbar!", pw); }
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.IsFalse(r2.IsUserInRole("foo", "Administrator")); }