1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

modules: fix names with hyphens (#656) (#659)

* modules: fix names with hyphens (#656)

* modules: fix names with hyphens (#656)

* Fix param name for postgresql_schema

* Add double quotes for schema name

* Add delete created DB objects

* Fix module code

* Set correct test tasks order

Co-authored-by: Maxim Voskresenskiy <maxim.voskresenskiy@uptick.com>
This commit is contained in:
VMax 2020-07-16 17:44:19 +03:00 committed by GitHub
parent 4c4a6ab27c
commit a0c8a3034a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- postgresql_privs - fix crash when set privileges on schema with hyphen in the name (https://github.com/ansible-collections/community.general/issues/656).

View file

@ -766,6 +766,9 @@ class Connection(object):
if target_roles:
as_who = ','.join('"%s"' % r for r in target_roles)
if schema_qualifier:
schema_qualifier = '"%s"' % schema_qualifier
status_before = get_status(objs)
query = QueryBuilder(state) \

View file

@ -4,6 +4,9 @@ db_user2: ansible_db_user2
db_user3: ansible_db_user3
db_user_with_dots1: role.with.dots1
db_user_with_dots2: role.with.dots2
db_name_with_hyphens: ansible-db
db_user_with_hyphens: ansible-db-user
db_schema_with_hyphens: ansible-db-schema
db_session_role1: session_role1
db_session_role2: session_role2
dangerous_name: 'curious.anonymous"; SELECT * FROM information_schema.tables; --'

View file

@ -27,6 +27,125 @@
db: "{{ db_name }}"
login_user: "{{ pg_user }}"
#############################
# Test of solving bug 656 #
#############################
- name: Create DB with hyphen in the name
become_user: "{{ pg_user }}"
become: yes
postgresql_db:
state: present
name: "{{ db_name_with_hyphens }}"
login_user: "{{ pg_user }}"
register: result
- assert:
that:
- result is changed
- name: Create a user with hyphen in the name
postgresql_user:
name: "{{ db_user_with_hyphens }}"
state: present
encrypted: yes
password: password
role_attr_flags: CREATEDB,LOGIN
db: "{{ db_name_with_hyphens }}"
login_user: "{{ pg_user }}"
register: result
- assert:
that:
- result is changed
- name: Create schema with hyphen in the name
postgresql_schema:
login_user: "{{ pg_user }}"
login_password: password
db: "{{ db_name_with_hyphens }}"
name: "{{ db_schema_with_hyphens }}"
state: present
register: result
- assert:
that:
- result is changed
- name: Set table default privs on the schema with hyphen in the name
postgresql_privs:
login_user: "{{ pg_user }}"
password: password
db: "{{ db_name_with_hyphens }}"
schema: "{{ db_schema_with_hyphens }}"
role: "{{ db_user_with_hyphens }}"
type: default_privs
obj: TABLES
privs: all
state: present
register: result
- assert:
that:
- result is changed
- name: Delete table default privs on the schema with hyphen in the name
postgresql_privs:
login_user: "{{ pg_user }}"
password: password
db: "{{ db_name_with_hyphens }}"
schema: "{{ db_schema_with_hyphens }}"
role: "{{ db_user_with_hyphens }}"
type: default_privs
obj: TABLES
privs: all
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete schema with hyphen in the name
postgresql_schema:
login_user: "{{ pg_user }}"
login_password: password
db: "{{ db_name_with_hyphens }}"
name: "{{ db_schema_with_hyphens }}"
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete a user with hyphen in the name
postgresql_user:
name: "{{ db_user_with_hyphens }}"
state: absent
encrypted: yes
password: password
role_attr_flags: CREATEDB,LOGIN
db: "{{ db_name_with_hyphens }}"
login_user: "{{ pg_user }}"
register: result
- assert:
that:
- result is changed
- name: Delete DB with hyphen in the name
become_user: "{{ pg_user }}"
become: yes
postgresql_db:
state: absent
name: "{{ db_name_with_hyphens }}"
login_user: "{{ pg_user }}"
register: result
- assert:
that:
- result is changed
#############################
# Test of solving bug 27327 #
#############################