From bf4673d3f78c11fb89dbf6bc0783c7b3e69eee58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 15 Jun 2018 12:37:36 +0300 Subject: [PATCH] MXS-872: Add role test case The test case checks whether roles work via MaxScale. --- maxscale-system-test/CMakeLists.txt | 4 ++ maxscale-system-test/mxs872_roles.cpp | 60 +++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 maxscale-system-test/mxs872_roles.cpp diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 65b4e7ca2..1740ba870 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -483,6 +483,10 @@ add_test_executable(mxs822_maxpasswd.cpp mxs822_maxpasswd maxpasswd LABELS maxsc # Do only SELECTS during time > wait_timeout and then do INSERT add_test_executable(mxs827_write_timeout.cpp mxs827_write_timeout mxs827_write_timeout LABELS readwritesplit REPL_BACKEND) +# MXS-872: MaxScale doesn't understand roles +# https://jira.mariadb.org/browse/MXS-872 +add_test_executable(mxs872_roles.cpp mxs872_roles replication LABELS REPL_BACKEND) + # Block and unblock first and second slaves and check that they are recovered add_test_executable(mxs874_slave_recovery.cpp mxs874_slave_recovery mxs874 LABELS readwritesplit REPL_BACKEND) diff --git a/maxscale-system-test/mxs872_roles.cpp b/maxscale-system-test/mxs872_roles.cpp new file mode 100644 index 000000000..23a583fea --- /dev/null +++ b/maxscale-system-test/mxs872_roles.cpp @@ -0,0 +1,60 @@ +/** + * MXS-872: MaxScale doesn't understand roles + * + * https://jira.mariadb.org/browse/MXS-872 + */ + +#include "testconnections.h" +#include + +using namespace std; + +int main(int argc, char** argv) +{ + TestConnections test(argc, argv); + + test.repl->connect(); + for (auto a : vector({"DROP DATABASE IF EXISTS my_db", + "CREATE DATABASE my_db", + "DROP ROLE IF EXISTS dba", + "CREATE ROLE dba", + "GRANT SELECT ON my_db.* TO dba", + "DROP USER IF EXISTS 'test'@'%'", + "DROP USER IF EXISTS 'test2'@'%'", + "CREATE USER 'test'@'%' IDENTIFIED BY 'test'", + "CREATE USER 'test2'@'%' IDENTIFIED BY 'test2'", + "GRANT dba TO 'test'@'%'", + "GRANT dba TO 'test2'@'%'", + "SET DEFAULT ROLE dba FOR 'test'@'%'"})) + { + test.try_query(test.repl->nodes[0], "%s", a.c_str()); + } + + // Wait for the users to replicate + test.repl->sync_slaves(); + + test.tprintf("Connect with a user that has a default role"); + MYSQL* conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], "my_db", "test", "test"); + test.assert(mysql_errno(conn) == 0, "Connection failed: %s", mysql_error(conn)); + char value[100] {}; + find_field(conn, "SELECT CURRENT_ROLE() AS role", "role", value); + test.assert(strcmp(value, "dba") == 0, "Current role should be 'dba' but is: %s", value); + mysql_close(conn); + + test.tprintf("Connect with a user that doesn't have a default role, expect failure"); + conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], "my_db", "test2", "test2"); + test.assert(mysql_errno(conn) != 0, "Connection should fail"); + mysql_close(conn); + + // Cleanup + for (auto a : vector({"DROP DATABASE IF EXISTS my_db", + "DROP ROLE IF EXISTS dba", + "DROP USER 'test'@'%'", + "DROP USER 'test2'@'%'"})) + { + execute_query_silent(test.repl->nodes[0], "%s", a.c_str()); + } + + test.repl->disconnect(); + return test.global_result; +}