Ensure that verify_login is using the host from the connection_args and not the host associated with the user. Adding a test to ensure user_exists when the passed host is the MySQL wildcard %.

This commit is contained in:
Gareth J. Greenaway 2018-11-16 14:01:31 -08:00
parent 84edd6269e
commit 0284323d50
No known key found for this signature in database
GPG key ID: 10B62F8A7CAD7A41
2 changed files with 17 additions and 5 deletions

View file

@ -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)

View file

@ -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