Ejemplo n.º 1
0
    def test_grant_exists_all(self):
        """
        Test to ensure that we can find a grant that exists
        """
        mock_grants = [
            "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON testdb.testtableone TO `testuser`@`%`",
            "GRANT BACKUP_ADMIN,BINLOG_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,GROUP_REPLICATION_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SET_USER_ID,SYSTEM_VARIABLES_ADMIN,XA_RECOVER_ADMIN ON testdb.testtableone TO `testuser`@`%`",
        ]
        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", "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)
            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)
Ejemplo n.º 2
0
 def test_grant_exists_false(self):
     '''
     Test to ensure that we don't find a grant that doesn't exist
     '''
     mock_grants = [
         "GRANT USAGE ON *.* TO 'testuser'@'%'",
         "GRANT SELECT, INSERT, UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'",
         "GRANT SELECT ON `testdb`.`testtablethree` TO 'testuser'@'%'",
     ]
     mock = MagicMock(return_value=mock_grants)
     with patch.object(mysql, 'user_grants',
                       return_value=mock_grants) as mock_user_grants:
         ret = mysql.grant_exists('SELECT', 'testdb.testtabletwo',
                                  'testuser', '%')
         self.assertEqual(ret, False)
Ejemplo n.º 3
0
 def test_grant_exists_false(self):
     """
     Test to ensure that we don't find a grant that doesn't exist
     """
     mock_grants = [
         "GRANT USAGE ON *.* TO 'testuser'@'%'",
         "GRANT SELECT, INSERT, UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'",
         "GRANT SELECT ON `testdb`.`testtablethree` TO 'testuser'@'%'",
     ]
     with patch.object(mysql, "version", return_value="5.6.41"):
         mock = MagicMock(return_value=mock_grants)
         with patch.object(mysql, "user_grants",
                           return_value=mock_grants) as mock_user_grants:
             ret = mysql.grant_exists("SELECT", "testdb.testtabletwo",
                                      "testuser", "%")
             self.assertEqual(ret, False)
Ejemplo n.º 4
0
 def test_grant_exists_false(self):
     '''
     Test to ensure that we don't find a grant that doesn't exist
     '''
     mock_grants = [
         "GRANT USAGE ON *.* TO 'testuser'@'%'",
         "GRANT SELECT, INSERT, UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'",
         "GRANT SELECT ON `testdb`.`testtablethree` TO 'testuser'@'%'",
     ]
     mock = MagicMock(return_value=mock_grants)
     with patch.object(mysql, 'user_grants', return_value=mock_grants) as mock_user_grants:
         ret = mysql.grant_exists(
             'SELECT',
             'testdb.testtabletwo',
             'testuser',
             '%'
         )
         self.assertEqual(ret, False)
Ejemplo n.º 5
0
 def test_grant_exists_true(self):
     '''
     Test to ensure that we can find a grant that exists
     '''
     mock_grants = [
         "GRANT USAGE ON *.* TO 'testuser'@'%'",
         "GRANT SELECT, INSERT, UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'",
         "GRANT SELECT ON `testdb`.`testtabletwo` TO 'testuer'@'%'",
         "GRANT SELECT ON `testdb`.`testtablethree` TO 'testuser'@'%'",
     ]
     with patch.object(mysql, 'version', return_value='5.6.41'):
         mock = MagicMock(return_value=mock_grants)
         with patch.object(mysql, 'user_grants',
                           return_value=mock_grants) as mock_user_grants:
             ret = mysql.grant_exists('SELECT, INSERT, UPDATE',
                                      'testdb.testtableone', 'testuser',
                                      '%')
             self.assertEqual(ret, True)
Ejemplo n.º 6
0
def test_grant_exists_true():
    """
    Test to ensure that we can find a grant that exists
    """
    mock_grants = [
        "GRANT USAGE ON *.* TO 'testuser'@'%'",
        "GRANT SELECT, INSERT, UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'",
        "GRANT SELECT(column1,column2) ON `testdb`.`testtableone` TO 'testuser'@'%'",
        "GRANT SELECT(column1,column2), INSERT(column1,column2) ON `testdb`.`testtableone` TO 'testuser'@'%'",
        "GRANT SELECT(column1,column2), UPDATE ON `testdb`.`testtableone` TO 'testuser'@'%'",
        "GRANT SELECT ON `testdb`.`testtabletwo` TO 'testuser'@'%'",
        "GRANT SELECT ON `testdb`.`testtablethree` TO 'testuser'@'%'",
    ]
    with patch.object(mysql, "version", return_value="5.6.41"):
        mock = MagicMock(return_value=mock_grants)
        with patch.object(mysql, "user_grants",
                          return_value=mock_grants) as mock_user_grants:
            ret = mysql.grant_exists("SELECT, INSERT, UPDATE",
                                     "testdb.testtableone", "testuser", "%")
            assert ret