本文整理汇总了Python中mysql.fabric.server.MySQLServer.has_privileges方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLServer.has_privileges方法的具体用法?Python MySQLServer.has_privileges怎么用?Python MySQLServer.has_privileges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql.fabric.server.MySQLServer
的用法示例。
在下文中一共展示了MySQLServer.has_privileges方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_privileges
# 需要导入模块: from mysql.fabric.server import MySQLServer [as 别名]
# 或者: from mysql.fabric.server.MySQLServer import has_privileges [as 别名]
def test_privileges(self):
"""Test whether user's have the appropriate privileges.
"""
# Some privileges
MINIMUM_PRIVILEGES = [
"REPLICATION SLAVE", "REPLICATION CLIENT", "SUPER",
"SHOW DATABASES", "RELOAD"
]
# Connect to server as root and create temporary user.
uuid = MySQLServer.discover_uuid(OPTIONS["address"])
server = MySQLServer(
_uuid.UUID(uuid), OPTIONS["address"],
tests.utils.MySQLInstances().root_user,
tests.utils.MySQLInstances().root_passwd
)
ConnectionPool().purge_connections(_uuid.UUID(uuid))
server.connect()
server.set_session_binlog(False)
server.exec_stmt(
"CREATE USER 'jeffrey'@'%%' IDENTIFIED BY 'mypass'"
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# There is not privilege associate to jeffrey.
new_server = MySQLServer(
_uuid.UUID(uuid), OPTIONS["address"], "jeffrey", "mypass"
)
new_server.connect()
self.assertFalse(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# Grant required privileges except RELOAD
# There is no RELOAD on a global level.
privileges=", ".join([priv for priv in MINIMUM_PRIVILEGES
if priv != "RELOAD"]
)
server.exec_stmt(
"GRANT {privileges} ON *.* TO 'jeffrey'@'%%'".format(
privileges=privileges)
)
server.exec_stmt("FLUSH PRIVILEGES")
self.assertFalse(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# The RELOAD on a global level was granted.
server.exec_stmt("GRANT RELOAD ON *.* TO 'jeffrey'@'%%'")
server.exec_stmt("FLUSH PRIVILEGES")
self.assertTrue(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# Revoke privilegs from temporary user.
# There is no ALL on a global level.
server.exec_stmt("REVOKE ALL PRIVILEGES, GRANT OPTION FROM "
"'jeffrey'@'%%'"
)
server.exec_stmt("GRANT ALL ON fabric.* TO 'jeffrey'@'%%'")
server.exec_stmt("FLUSH PRIVILEGES")
self.assertFalse(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Check if jeffrey (temporary user) has the appropriate privileges.
# The ALL on a global level was granted.
server.exec_stmt("GRANT ALL ON *.* TO 'jeffrey'@'%%'")
server.exec_stmt("FLUSH PRIVILEGES")
self.assertTrue(
new_server.has_privileges(MINIMUM_PRIVILEGES)
)
# Drop temporary user.
server.exec_stmt("DROP USER 'jeffrey'@'%%'")
server.set_session_binlog(True)
server.disconnect()
new_server.disconnect()
ConnectionPool().purge_connections(_uuid.UUID(uuid))