issue-744: add integration tests (#751)

This commit is contained in:
Andrew Klychkov 2025-10-16 10:03:51 +02:00 committed by GitHub
commit 5217af0c2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 104 additions and 1 deletions

View file

@ -0,0 +1,98 @@
---
# Test for https://github.com/ansible-collections/community.mysql/issues/664
# Issue 744: Bug revoking 'WITH GRANT OPTION'
# The issue occurs when a user has only USAGE with GRANT OPTION on a database
# and we try to modify their permissions. The revoke logic fails because it
# tries to revoke USAGE twice.
- vars:
mysql_parameters: &mysql_params
login_user: '{{ mysql_user }}'
login_password: '{{ mysql_password }}'
login_host: '{{ mysql_host }}'
login_port: '{{ mysql_primary_port }}'
block:
- name: Issue-744 | Create test database
community.mysql.mysql_db:
<<: *mysql_params
name: issue744_testdb
state: present
- name: Issue-744 | Create user with USAGE privileges only
community.mysql.mysql_user:
<<: *mysql_params
name: "{{ user_name_1 }}"
password: "{{ user_password_1 }}"
state: present
- name: Issue-744 | Grant USAGE with GRANT OPTION on specific database
community.mysql.mysql_user:
<<: *mysql_params
name: "{{ user_name_1 }}"
password: "{{ user_password_1 }}"
priv: 'issue744_testdb.*:USAGE,GRANT'
state: present
- name: Issue-744 | Show grants to verify USAGE with GRANT OPTION
community.mysql.mysql_query:
<<: *mysql_params
query: "SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost'"
register: show_grants_result
- name: Issue-744 | Verify user has USAGE with GRANT OPTION
assert:
that:
- "'issue744_testdb' in (show_grants_result.query_result | string)"
- "'WITH GRANT OPTION' in (show_grants_result.query_result | string)"
# With the fix, this should now succeed
- name: Issue-744 | Modify user permissions (this should now succeed with the fix)
community.mysql.mysql_user:
<<: *mysql_params
name: "{{ user_name_1 }}"
password: "{{ user_password_1 }}"
priv: 'issue744_testdb.*:SELECT'
state: present
register: modify_perms_result
- name: Issue-744 | Debug modification result
debug:
var: modify_perms_result
# With the fix, the operation should succeed
- name: Issue-744 | Verify that modification succeeded
assert:
that:
- modify_perms_result is succeeded
- modify_perms_result is changed
fail_msg: "Expected the modification to succeed with the fix, but got: {{ modify_perms_result.msg }}"
# Verify the final state is correct
- name: Issue-744 | Show final grants to verify SELECT privilege
community.mysql.mysql_query:
<<: *mysql_params
query: "SHOW GRANTS FOR '{{ user_name_1 }}'@'localhost'"
register: final_grants_result
- name: Issue-744 | Verify user now has SELECT privilege
assert:
that:
- "'GRANT SELECT ON' in (final_grants_result.query_result | string)"
- "'issue744_testdb' in (final_grants_result.query_result | string)"
fail_msg: "Expected user to have SELECT privilege on issue744_testdb, but got: {{ final_grants_result.query_result }}"
always:
- name: Issue-744 | Cleanup - Remove test user
community.mysql.mysql_user:
<<: *mysql_params
name: "{{ user_name_1 }}"
state: absent
ignore_errors: true
- name: Issue-744 | Cleanup - Remove test database
community.mysql.mysql_db:
<<: *mysql_params
name: issue744_testdb
state: absent
ignore_errors: true

View file

@ -169,7 +169,7 @@
host_all: yes
password: '{{ user_password_1 }}'
register: result
ignore_errors: yes
ignore_errors: true
- name: check fail message
assert:
@ -313,3 +313,8 @@
# Test that mysql_user still works with default role set
# (https://github.com/ansible-collections/community.mysql/issues/710)
- include_tasks: issue-710.yml
# Test for bug with revoking GRANT OPTION when user has only USAGE
# (https://github.com/ansible-collections/community.mysql/issues/664)
# (https://github.com/ansible-collections/community.mysql/pull/744)
- include_tasks: issue-744.yml