mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #50551 from garethgreenaway/50542_mysql_ensure_verify_login_uses_connection_host
[2018.3] Fixes to verify_login in mysql module
This commit is contained in:
commit
26759c2cd1
2 changed files with 17 additions and 5 deletions
|
@ -1247,7 +1247,7 @@ def user_exists(user,
|
|||
args['password'] = password_hash
|
||||
|
||||
if run_verify:
|
||||
if not verify_login(user, host, password):
|
||||
if not verify_login(user, password, **connection_args):
|
||||
return False
|
||||
try:
|
||||
_execute(cur, qry, args)
|
||||
|
@ -2235,7 +2235,7 @@ def showglobal(**connection_args):
|
|||
return rtnv
|
||||
|
||||
|
||||
def verify_login(user, host='localhost', password=None, **connection_args):
|
||||
def verify_login(user, password=None, **connection_args):
|
||||
'''
|
||||
Attempt to login using the provided credentials.
|
||||
If successful, return true. Otherwise, return False.
|
||||
|
@ -2244,11 +2244,10 @@ def verify_login(user, host='localhost', password=None, **connection_args):
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
salt '*' mysql.verify_login root localhost password
|
||||
salt '*' mysql.verify_login root password
|
||||
'''
|
||||
# Override the connection args
|
||||
# Override the connection args for username and password
|
||||
connection_args['connection_user'] = user
|
||||
connection_args['connection_host'] = host
|
||||
connection_args['connection_pass'] = password
|
||||
|
||||
dbc = _connect(**connection_args)
|
||||
|
|
|
@ -66,6 +66,19 @@ class MySQLTestCase(TestCase, LoaderModuleMockMixin):
|
|||
password='BLUECOW'
|
||||
)
|
||||
|
||||
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': '%',
|
||||
'user': 'mytestuser'
|
||||
}
|
||||
},
|
||||
user='mytestuser',
|
||||
host='%',
|
||||
password='BLUECOW'
|
||||
)
|
||||
|
||||
# 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
|
||||
|
|
Loading…
Add table
Reference in a new issue