Skip to content

Commit

Permalink
Update user permissions and add SQL comparison files for MySQL 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ptankov committed Dec 17, 2024
1 parent 704ac8a commit a98e66d
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 15 deletions.
4 changes: 4 additions & 0 deletions e2e-tests/custom-users/compare/user-five-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GRANT USAGE ON *.* TO 'user-five'@'%'
GRANT SELECT, UPDATE, DELETE ON `db1`.* TO 'user-five'@'%'
GRANT SELECT, UPDATE, DELETE ON `db2`.* TO 'user-five'@'%'
GRANT SELECT, UPDATE, DELETE ON `db3`.* TO 'user-five'@'%'
4 changes: 4 additions & 0 deletions e2e-tests/custom-users/compare/user-four-2-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GRANT USAGE ON *.* TO 'user-four'@'%'
GRANT SELECT, UPDATE ON `db1`.* TO 'user-four'@'%'
GRANT SELECT, UPDATE ON `db2`.* TO 'user-four'@'%'
GRANT SELECT, UPDATE ON `db3`.* TO 'user-four'@'%'
4 changes: 4 additions & 0 deletions e2e-tests/custom-users/compare/user-four-3-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GRANT USAGE ON *.* TO 'user-four'@'%'
GRANT SELECT, UPDATE, DELETE ON `db1`.* TO 'user-four'@'%'
GRANT SELECT, UPDATE, DELETE ON `db2`.* TO 'user-four'@'%'
GRANT SELECT, UPDATE, DELETE ON `db3`.* TO 'user-four'@'%'
4 changes: 4 additions & 0 deletions e2e-tests/custom-users/compare/user-four-4-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GRANT USAGE ON *.* TO 'user-four'@'%'
GRANT SELECT, INSERT, UPDATE, DELETE ON `db1`.* TO 'user-four'@'%'
GRANT SELECT, UPDATE, DELETE ON `db2`.* TO 'user-four'@'%'
GRANT SELECT, UPDATE, DELETE ON `db3`.* TO 'user-four'@'%'
3 changes: 3 additions & 0 deletions e2e-tests/custom-users/compare/user-four-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GRANT USAGE ON *.* TO 'user-four'@'%'
GRANT SELECT, UPDATE ON `db1`.* TO 'user-four'@'%'
GRANT SELECT, UPDATE ON `db2`.* TO 'user-four'@'%'
5 changes: 5 additions & 0 deletions e2e-tests/custom-users/compare/user-one-2-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
GRANT USAGE ON *.* TO 'user-one'@'127.0.0.1'
GRANT SELECT, INSERT ON `db1`.* TO 'user-one'@'127.0.0.1'
GRANT SELECT, INSERT ON `db2`.* TO 'user-one'@'127.0.0.1'
GRANT SELECT, INSERT ON `db1`.* TO 'user-one'@'%'
GRANT SELECT, INSERT ON `db2`.* TO 'user-one'@'%'
3 changes: 3 additions & 0 deletions e2e-tests/custom-users/compare/user-one-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GRANT USAGE ON *.* TO 'user-one'@'%'
GRANT SELECT, INSERT ON `db1`.* TO 'user-one'@'%'
GRANT SELECT, INSERT ON `db2`.* TO 'user-one'@'%'
1 change: 1 addition & 0 deletions e2e-tests/custom-users/compare/user-three-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GRANT USAGE ON *.* TO 'user-three'@'%'
1 change: 1 addition & 0 deletions e2e-tests/custom-users/compare/user-two-57.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GRANT INSERT, UPDATE ON *.* TO 'user-two'@'%'
8 changes: 4 additions & 4 deletions e2e-tests/custom-users/run
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ kubectl_bin patch pxc some-name --type=merge -p='{
"name":"user-four",
"dbs": ["db1", "db2"],
"grants":["SELECT, UPDATE"],
"hosts": ["%"]
"hosts": ["%"]
}
]}
}'
Expand All @@ -75,7 +75,7 @@ kubectl_bin patch pxc some-name --type=merge -p='{
"name":"user-four",
"dbs": ["db1", "db2", "db3"],
"grants":["SELECT, UPDATE"],
"hosts": ["%"]
"hosts": ["%"]
}
]}
}'
Expand All @@ -89,7 +89,7 @@ kubectl_bin patch pxc some-name --type=merge -p='{
"name":"user-four",
"dbs": ["db1", "db2", "db3"],
"grants":["SELECT, UPDATE, DELETE"],
"hosts": ["%"]
"hosts": ["%"]
}
]}
}'
Expand All @@ -115,7 +115,7 @@ kubectl_bin patch pxc some-name --type=merge -p='{
"name":"user-five",
"dbs": ["db1", "db2", "db3"],
"grants":["SELECT, UPDATE, DELETE"],
"hosts": ["%"]
"hosts": ["%"]
}
]}
}'
Expand Down
24 changes: 14 additions & 10 deletions e2e-tests/functions
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,14 @@ compare_mysql_cmd() {
local command="$2"
local uri="$3"
local postfix="$4"
local expected_result=${test_dir}/compare/${command_id}${postfix}.sql

if [[ $IMAGE_PXC =~ 8\.0 ]] && [ -f ${test_dir}/compare/${command_id}${postfix}-80.sql ]; then
expected_result=${test_dir}/compare/${command_id}${postfix}-80.sql
elif [[ $IMAGE_PXC =~ 8\.4 ]] && [ -f ${test_dir}/compare/${command_id}${postfix}-84.sql ]; then
expected_result=${test_dir}/compare/${command_id}${postfix}-84.sql
local expected_result=$test_dir/compare/$command_id$postfix.sql

if [[ $IMAGE_PXC =~ 8\.4 && -f $test_dir/compare/$command_id$postfix-84.sql ]]; then
expected_result=$test_dir/compare/$command_id$postfix-84.sql
elif [[ $IMAGE_PXC =~ 8\.0 && -f $test_dir/compare/$command_id$postfix-80.sql ]]; then
expected_result=$test_dir/compare/$command_id$postfix-80.sql
elif [[ $IMAGE_PXC =~ 5\.7 && -f $test_dir/compare/$command_id$postfix-57.sql ]]; then
expected_result=$test_dir/compare/$command_id$postfix-57.sql
fi

run_mysql "$command" "$uri" \
Expand Down Expand Up @@ -612,10 +614,12 @@ compare_mysql_user() {
local user=$(echo $uri | sed -e 's/.*-u//; s/ .*//')
local expected_result=${test_dir}/compare/$user$postfix.sql

if [[ $IMAGE_PXC =~ 8\.0 ]] && [ -f ${test_dir}/compare/$user$postfix-80.sql ]; then
expected_result=${test_dir}/compare/$user$postfix-80.sql
elif [[ $IMAGE_PXC =~ 8\.4 ]] && [ -f ${test_dir}/compare/$user$postfix-84.sql ]; then
expected_result=${test_dir}/compare/$user$postfix-84.sql
if [[ $IMAGE_PXC =~ 8\.4 && -f $test_dir/compare/$user$postfix-84.sql ]]; then
expected_result=$test_dir/compare/$user$postfix-84.sql
elif [[ $IMAGE_PXC =~ 8\.0 && -f $test_dir/compare/$user$postfix-80.sql ]]; then
expected_result=$test_dir/compare/$user$postfix-80.sql
elif [[ $IMAGE_PXC =~ 5\.7 && -f $test_dir/compare/$user$postfix-57.sql ]]; then
expected_result=$test_dir/compare/$user$postfix-57.sql
fi

(run_mysql "SHOW GRANTS;" "$uri" || :) \
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/init-deploy/run
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ compare_kubectl service/$cluster-pxc
compare_kubectl service/$cluster-proxysql
compare_kubectl service/$cluster-proxysql-unready

if [[ ${MYSQL_VERSION} == '8.0' ]]; then
if [[ ! $IMAGE_PXC =~ 5\.7 ]]; then
desc 'check if mysql-state-monitor works as expected'
for pod in $(kubectl_bin get pod -l app.kubernetes.io/component=pxc --no-headers | awk '{print $1}'); do
state=$(kubectl_bin exec ${pod} -- cat /var/lib/mysql/mysql.state)
Expand Down

0 comments on commit a98e66d

Please sign in to comment.