def test_user_exists(self): ''' Test to see if mysql module properly forms the MySQL query to see if a user exists Do it before test_user_create_when_user_exists mocks the user_exists call ''' with patch.object(mysql, 'version', return_value='8.0.10'): self._test_call(mysql.user_exists, { 'sql': ('SELECT User,Host FROM mysql.user WHERE ' 'User = %(user)s AND Host = %(host)s AND ' 'Password = PASSWORD(%(password)s)'), 'sql_args': { 'host': 'localhost', 'password': '******', 'user': '******' } }, user='******', host='localhost', password='******') with patch.object(mysql, 'version', return_value='8.0.11'): self._test_call(mysql.user_exists, { 'sql': ('SELECT User,Host FROM mysql.user WHERE ' 'User = %(user)s AND Host = %(host)s'), 'sql_args': { 'host': 'localhost', 'user': '******' } }, user='******', host='localhost', password='******') # test_user_create_when_user_exists(self): # ensure we don't try to create a user when one already exists # mock the version of MySQL with patch.object(mysql, 'version', return_value='8.0.10'): with patch.object(mysql, 'user_exists', MagicMock(return_value=True)): with patch.dict(mysql.__salt__, {'config.option': MagicMock()}): ret = mysql.user_create('testuser') self.assertEqual(False, ret) # test_user_create_when_user_exists(self): # ensure we don't try to create a user when one already exists # mock the version of MySQL with patch.object(mysql, 'version', return_value='8.0.11'): with patch.object(mysql, 'user_exists', MagicMock(return_value=True)): with patch.object(mysql, 'verify_login', MagicMock(return_value=True)): with patch.dict(mysql.__salt__, {'config.option': MagicMock()}): ret = mysql.user_create('testuser') self.assertEqual(False, ret)
def test_user_exists(self): """ Test to see if mysql module properly forms the MySQL query to see if a user exists Do it before test_user_create_when_user_exists mocks the user_exists call """ self._test_call( mysql.user_exists, { "sql": ( "SELECT User,Host FROM mysql.user WHERE " "User = %(user)s AND Host = %(host)s AND " "Password = PASSWORD(%(password)s)" ), "sql_args": {"host": "localhost", "password": "******", "user": "******"}, }, user="******", host="localhost", password="******", ) # test_user_create_when_user_exists(self): # ensure we don't try to create a user when one already exists mock = MagicMock(return_value=True) mysql.user_exists = mock with patch.dict(mysql.__salt__, {"config.option": MagicMock()}): ret = mysql.user_create("testuser") self.assertEqual(False, ret)
def test_user_exists(self): ''' Test to see if mysql module properly forms the MySQL query to see if a user exists Do it before test_user_create_when_user_exists mocks the user_exists call ''' self._test_call(mysql.user_exists, {'sql': ('SELECT User,Host FROM mysql.user WHERE ' 'User = %(user)s AND Host = %(host)s AND ' 'Password = PASSWORD(%(password)s)'), 'sql_args': {'host': 'localhost', 'password': '******', 'user': '******' } }, user='******', host='localhost', password='******' ) # test_user_create_when_user_exists(self): # ensure we don't try to create a user when one already exists mock = MagicMock(return_value=True) mysql.user_exists = mock with patch.dict(mysql.__salt__, {'config.option': MagicMock()}): ret = mysql.user_create('testuser') self.assertEqual(False, ret)
def test_user_exists(): """ Test to see if mysql module properly forms the MySQL query to see if a user exists Do it before test_user_create_when_user_exists mocks the user_exists call """ with patch.object(mysql, "version", return_value="8.0.10"): _test_call( mysql.user_exists, { "sql": ("SELECT User,Host FROM mysql.user WHERE " "User = %(user)s AND Host = %(host)s AND " "Password = PASSWORD(%(password)s)"), "sql_args": { "host": "localhost", "password": "******", "user": "******", }, }, user="******", host="localhost", password="******", ) with patch.object(mysql, "version", return_value="10.1.38-MariaDB"): _test_call( mysql.user_exists, { "sql": ("SELECT User,Host FROM mysql.user WHERE " "User = %(user)s AND Host = %(host)s AND " "Password = PASSWORD(%(password)s)"), "sql_args": { "host": "localhost", "password": "******", "user": "******", }, }, user="******", host="localhost", password="******", ) with patch.object(mysql, "version", return_value="8.0.11"): _test_call( mysql.user_exists, { "sql": ("SELECT User,Host FROM mysql.user WHERE " "User = %(user)s AND Host = %(host)s"), "sql_args": { "host": "localhost", "user": "******" }, }, user="******", host="localhost", password="******", ) with patch.object(mysql, "version", return_value="8.0.11"): with patch.object( mysql, "__get_auth_plugin", MagicMock(return_value="mysql_native_password"), ): _test_call( mysql.user_exists, { "sql": ("SELECT User,Host FROM mysql.user WHERE " "User = %(user)s AND Host = %(host)s AND " "Password = %(password)s"), "sql_args": { "host": "%", "password": "******", "user": "******", }, }, user="******", host="%", password="******", ) with patch.object(mysql, "version", return_value="10.2.21-MariaDB"): _test_call( mysql.user_exists, { "sql": ("SELECT User,Host FROM mysql.user WHERE " "User = %(user)s AND Host = %(host)s AND " "Password = PASSWORD(%(password)s)"), "sql_args": { "host": "localhost", "password": "******", "user": "******", }, }, user="******", host="localhost", password="******", ) with patch.object(mysql, "version", side_effect=["", "10.2.21-MariaDB", "10.2.21-MariaDB"]): _test_call( mysql.user_exists, { "sql": ("SELECT User,Host FROM mysql.user WHERE " "User = %(user)s AND Host = %(host)s AND " "Password = PASSWORD(%(password)s)"), "sql_args": { "host": "localhost", "password": "******", "user": "******", }, }, user="******", host="localhost", password="******", connection_user="******", connection_pass="******", ) # test_user_create_when_user_exists(): # ensure we don't try to create a user when one already exists # mock the version of MySQL with patch.object(mysql, "version", return_value="8.0.10"): with patch.object(mysql, "user_exists", MagicMock(return_value=True)): with patch.dict(mysql.__salt__, {"config.option": MagicMock()}): ret = mysql.user_create("testuser") assert not ret # test_user_create_when_user_exists(): # ensure we don't try to create a user when one already exists # mock the version of MySQL with patch.object(mysql, "version", return_value="8.0.11"): with patch.object(mysql, "user_exists", MagicMock(return_value=True)): with patch.object(mysql, "verify_login", MagicMock(return_value=True)): with patch.dict(mysql.__salt__, {"config.option": MagicMock()}): ret = mysql.user_create("testuser") assert not False