Exemple #1
0
 public static void TearDownClass()
 {
     //Drop the user that this unit test class created within SetupClass().
     DbAdminMysql.DropUser(new DataConnection(), USER_LOW_NAME);
     //Put the Middle Tier mock server back to the way it was when this test class was initialized.
     OpenDentalServerProxy.MockOpenDentalServerCur = _middleTierMockOld;
 }
        private void butDrop_Click(object sender, EventArgs e)
        {
            if (listBoxUsers.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a user to drop.");
                return;
            }
            string user = (string)listBoxUsers.Items[listBoxUsers.SelectedIndex];

            if (user.ToLower() == _dataConnection.UserCur.ToLower())
            {
                MessageBox.Show("Cannot drop the current MySQL user.");
                return;
            }
            if (MessageBox.Show($"Are you sure you want to drop '{user}'?", "", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }
            try {
                DbAdminMysql.DropUser(_dataConnection, user);
            }
            catch (Exception ex) {
                MessageBox.Show("Error dropping user: " + ex.Message);
                return;
            }
            FillUsers();
        }
 private void butOK_Click(object sender, EventArgs e)
 {
     if (textUser.Text == "" && (_isNew || _userName != ""))         //If the existing username is '', we will allow it.
     {
         MessageBox.Show("Please enter a MySQL user.");
         return;
     }
     if (textPassword.Text == "")
     {
         MessageBox.Show("Please enter a password.");
         return;
     }
     if (WasPasswordChanged && textPassword.Text != textRetypePassword.Text)
     {
         MessageBox.Show("Passwords do not match.");
         return;
     }
     if (textUser.Text != _userName && !WasPasswordChanged)
     {
         MessageBox.Show("Please enter a password if changing the username.");
         return;
     }
     if (_hasNonStandardPermissions && radioLow.Checked && MessageBox.Show("This user has more permissions than the 'Low' permissions set. Continuing"
                                                                           + " will reduce the user's permission to just the SELECT permission. Do you want to continue?", "", MessageBoxButtons.OKCancel) != DialogResult.OK)
     {
         return;
     }
     if (_userName.ToLower() == _dataConnection.UserCur.ToLower() && radioLow.Checked)
     {
         MessageBox.Show("Cannot change the current user to low permission.");
         return;
     }
     try {
         bool doCreateNew = _isNew;
         if (textUser.Text != _userName)               //It doesn't really work to update a username, so we'll drop and recreate.
         {
             DbAdminMysql.DropUser(_dataConnection, _userName);
             doCreateNew = true;
         }
         if (doCreateNew)
         {
             DbAdminMysql.CreateUser(_dataConnection, textUser.Text, _hasLocalhostUserOnly);
         }
         if (WasPasswordChanged || doCreateNew)
         {
             DbAdminMysql.SetPassword(_dataConnection, textUser.Text, textPassword.Text);
         }
         if (_hasFullPermission != radioFull.Checked || _hasNonStandardPermissions || doCreateNew)
         {
             DbAdminMysql.GrantToUser(_dataConnection, textUser.Text, radioFull.Checked);
         }
     }
     catch (Exception ex) {
         MessageBox.Show("Error updating user: " + ex.Message);
         return;
     }
     DialogResult = DialogResult.OK;
 }
Exemple #4
0
        public void ODInstallerTests_DbAdminMysql_CreateAndDestroyAdminUsers()
        {
            DataConnection conAdmin = new DataConnection();                                              //A brand new admin connection to the unittest### database.

            Assert.AreEqual(null, DbAdminMysql.ModifyUser(conAdmin, "fakeuser1", "od123", "fakeuser1")); //Grants, verifies new user.
            Assert.AreEqual(null, DbAdminMysql.ModifyUser(conAdmin, "fakeuser2", "abcde", "fakeuser1")); //Drops fakeuser1 and verifies.
            try {
                DbAdminMysql.DropUser(conAdmin, "fakeuser2");                                            //Drops fakeuser2 and verifies.
            }
            catch (Exception ex) {
                Assert.Fail(ex.Message);
            }
        }
Exemple #5
0
 public static void SetupClass(TestContext testContext)
 {
     //Create and set the Open Dental user called UnitTest so that we don't get trolled by failed login attempts from an invalid Security.CurUser.
     TestBase.CreateAndSetUnitTestUser();
     //Drop any users that already exist with this specific name.
     DbAdminMysql.DropUser(new DataConnection(), USER_LOW_NAME);
     //Create a new user with this unit test method name as the database user name.
     DataCore.NonQ($"CREATE USER '{USER_LOW_NAME}'@'localhost' IDENTIFIED BY '{USER_LOW_PASS}'");
     //Only give the SELECT permission to simulate a user of lower status in life.
     DataCore.NonQ($"GRANT SELECT ON *.* TO '{USER_LOW_NAME}'@'localhost'");
     //Reload all privileges to make sure the proletariat permission takes effect.
     DataCore.NonQ("FLUSH PRIVILEGES");
     //Preserve the old Middle Tier Mock service and replace it with a new one that knows about our new user low.
     _middleTierMockOld = OpenDentalServerProxy.MockOpenDentalServerCur;
     //Pass in new connection settings so that this plebeian is set as our "UserLow" when invoking Reports.GetTable().
     OpenDentalServerProxy.MockOpenDentalServerCur = new OpenDentalServerMockIIS("localhost"
                                                                                 , UnitTestDbName
                                                                                 , "root"
                                                                                 , ""
                                                                                 , USER_LOW_NAME
                                                                                 , USER_LOW_PASS
                                                                                 , DatabaseType.MySql);
 }