generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[stable-1] mysql_user: fix parsing privs when a user has roles assign…
…ed to it (#346) * mysql_user: fix parsing privs when a user has roles assigned to it * Fix CI * Fix CI
- Loading branch information
1 parent
256817c
commit 393023e
Showing
5 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/tests/output/ | ||
/changelogs/.plugin-cache.yaml | ||
*.swp | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
|
2 changes: 2 additions & 0 deletions
2
changelogs/fragments/001-mysql_user_fix_pars_users_with_roles_assigned.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bugfixes: | ||
- mysql_user - fix parsing privs when a user has roles assigned (https://github.com/ansible-collections/community.mysql/issues/231). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
tests/integration/targets/test_mysql_user/tasks/test_user_grants_with_roles_applied.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# https://github.com/ansible-collections/community.mysql/issues/231 | ||
- vars: | ||
mysql_parameters: &mysql_params | ||
login_user: '{{ mysql_user }}' | ||
login_password: '{{ mysql_password }}' | ||
login_host: 127.0.0.1 | ||
login_port: '{{ mysql_primary_port }}' | ||
|
||
block: | ||
- name: Get server version | ||
mysql_info: | ||
<<: *mysql_params | ||
register: srv | ||
|
||
# Skip unsupported versions | ||
- meta: end_play | ||
when: srv['version']['major'] < 8 | ||
|
||
- name: Create test databases | ||
mysql_db: | ||
<<: *mysql_params | ||
name: '{{ item }}' | ||
state: present | ||
loop: | ||
- data1 | ||
- data2 | ||
|
||
- name: Create user with privileges | ||
mysql_user: | ||
<<: *mysql_params | ||
name: '{{ user_name_3 }}' | ||
password: '{{ user_password_3 }}' | ||
priv: | ||
"data1.*": "SELECT" | ||
"data2.*": "SELECT" | ||
state: present | ||
|
||
- name: Run command to show privileges for user (expect privileges in stdout) | ||
command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_3 }}'@'localhost'\"" | ||
register: result | ||
|
||
- name: Assert user has giving privileges | ||
assert: | ||
that: | ||
- "'GRANT SELECT ON `data1`.*' in result.stdout" | ||
- "'GRANT SELECT ON `data2`.*' in result.stdout" | ||
|
||
- name: Create role | ||
mysql_query: | ||
<<: *mysql_params | ||
query: CREATE ROLE IF NOT EXISTS test231 | ||
|
||
|
||
- name: Grant role | ||
mysql_query: | ||
<<: *mysql_params | ||
query: 'GRANT test231 TO {{ user_name_3 }}@localhost' | ||
|
||
- name: Try to change privs | ||
mysql_user: | ||
<<: *mysql_params | ||
name: '{{ user_name_3 }}' | ||
priv: | ||
"data1.*": "INSERT" | ||
"data2.*": "INSERT" | ||
state: present | ||
|
||
- name: Run command to show privileges for user (expect privileges in stdout) | ||
command: "{{ mysql_command }} -e \"SHOW GRANTS FOR '{{ user_name_3 }}'@'localhost'\"" | ||
register: result | ||
|
||
- name: Assert user has giving privileges | ||
assert: | ||
that: | ||
- "'GRANT INSERT ON `data1`.*' in result.stdout" | ||
- "'GRANT INSERT ON `data2`.*' in result.stdout" | ||
|
||
########## | ||
# Clean up | ||
- name: Drop test databases | ||
mysql_db: | ||
<<: *mysql_params | ||
name: '{{ item }}' | ||
state: present | ||
loop: | ||
- data1 | ||
- data2 | ||
|
||
- name: Drop test user | ||
mysql_user: | ||
<<: *mysql_params | ||
name: '{{ user_name_3 }}' | ||
state: absent | ||
|
||
- name: Drop test role | ||
mysql_query: | ||
<<: *mysql_params | ||
query: DROP ROLE IF EXISTS test231 |