Fix issue with MySQL8 and "all privileges" grant

Converts the given "grant" to upper case before compare to "ALL".
This fixes a problem granting "all privileges" to a MySQL user.
This commit is contained in:
piterpunk 2020-11-17 03:00:30 -03:00 committed by Megan Wilhite
parent 0e4e8a458a
commit 13379fc370
3 changed files with 13 additions and 1 deletions

2
changelog/58933.fixed Normal file
View file

@ -0,0 +1,2 @@
Converts the given "grant" to upper case before compare to "ALL".
This fixes a problem granting "all privileges" to a MySQL user.

View file

@ -2370,7 +2370,7 @@ def grant_exists(
)
log.error(err)
return False
if "ALL" in grant:
if "ALL" in grant.upper():
if (
salt.utils.versions.version_cmp(server_version, "8.0") >= 0
and "MariaDB" not in server_version

View file

@ -587,6 +587,16 @@ class MySQLTestCase(TestCase, LoaderModuleMockMixin):
ret = mysql.grant_exists("ALL", "testdb.testtableone", "testuser", "%")
self.assertEqual(ret, True)
with patch.object(mysql, "version", return_value="8.0.10"):
mock = MagicMock(return_value=mock_grants)
with patch.object(
mysql, "user_grants", return_value=mock_grants
) as mock_user_grants:
ret = mysql.grant_exists(
"all privileges", "testdb.testtableone", "testuser", "%"
)
self.assertEqual(ret, True)
mock_grants = ["GRANT ALL PRIVILEGES ON testdb.testtableone TO `testuser`@`%`"]
with patch.object(mysql, "version", return_value="5.6.41"):
mock = MagicMock(return_value=mock_grants)