Skip to content

Commit

Permalink
Fix unsafe conditional statement (#262)
Browse files Browse the repository at this point in the history
* Fix unsafe conditional statements
  • Loading branch information
rhysmeister authored Nov 30, 2023
1 parent 3a0ea57 commit a3d8e56
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
20 changes: 10 additions & 10 deletions tests/integration/targets/cassandra_role/tasks/204.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
- first_run.changed
- first_run.cql == "CREATE ROLE 'test_role' WITH SUPERUSER = False AND LOGIN = True AND PASSWORD = '********' "
- "first_run.permissions.grant.0 == \"GRANT ALL PERMISSIONS ON KEYSPACE test_keyspace TO 'test_role'\""
- "{{ first_run.permissions.grant | length }} == 1"
- "{{ first_run.permissions.revoke | length }} == 0"
- first_run.permissions.grant | length == 1
- first_run.permissions.revoke | length == 0

- name: Create a test role - second run
community.cassandra.cassandra_role:
Expand Down Expand Up @@ -84,8 +84,8 @@
- assert:
that:
- third_run.changed
- "{{ third_run.permissions.revoke | length }} == 5"
- "{{ third_run.permissions.grant | length }} == 0"
- third_run.permissions.revoke | length == 5
- third_run.permissions.grant | length == 0

- name: Create a test role - fourth run
community.cassandra.cassandra_role:
Expand All @@ -104,8 +104,8 @@
- assert:
that:
- fourth_run.changed
- "{{ fourth_run.permissions.revoke | length }} == 5"
- "{{ fourth_run.permissions.grant | length }} == 0"
- fourth_run.permissions.revoke | length == 5
- fourth_run.permissions.grant | length == 0


- name: Create a test role - fifth run
Expand Down Expand Up @@ -146,8 +146,8 @@
- assert:
that:
- sixth_run.changed
- "{{ sixth_run.permissions.revoke | length }} == 0"
- "{{ sixth_run.permissions.grant | length }} == 1"
- sixth_run.permissions.revoke | length == 0
- sixth_run.permissions.grant | length == 1
- "sixth_run.permissions.grant.0 == \"GRANT MODIFY ON KEYSPACE test_keyspace TO 'test_role'\""

- name: Create a test role - seventh run
Expand All @@ -168,8 +168,8 @@
- assert:
that:
- seventh_run.changed
- "{{ seventh_run.permissions.revoke | length }} == 0"
- "{{ seventh_run.permissions.grant | length }} == 1"
- seventh_run.permissions.revoke | length == 0
- seventh_run.permissions.grant | length == 1
- "seventh_run.permissions.grant.0 == \"GRANT MODIFY ON KEYSPACE test_keyspace TO 'test_role'\""

- name: Create a test role - eighth run
Expand Down
38 changes: 28 additions & 10 deletions tests/integration/targets/cassandra_timeout/tasks/timeout_test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
- name: "Set {{ item }} timeout with module"
community.cassandra.cassandra_timeout:
username: "{{ cassandra_admin_user }}"
Expand All @@ -8,18 +8,24 @@
debug: true
register: result

- set_fact:
mymsg: "{{ item }} timeout changed"

- assert:
that:
that:
- result.changed
- "result.msg == '{{ item }} timeout changed'"
- result.msg == mymsg

- name: "Get {{ item }} timeout"
ansible.builtin.shell: nodetool -u {{ cassandra_admin_user }} -pw {{ cassandra_admin_pwd }} -h 127.0.0.1 gettimeout {{ item }}
register: result

- set_fact:
mymsg: "Current timeout for type {{ item }}: 15999 ms"

- name: Assert timeout is 15999 ms
assert:
that: "'Current timeout for type {{ item }}: 15999 ms' == result.stdout"
that: mymsg == result.stdout

- name: Set throughput to 15999 again
community.cassandra.cassandra_timeout:
Expand All @@ -30,10 +36,13 @@
debug: true
register: result

- set_fact:
mymsg: "{{ item }} timeout unchanged"

- assert:
that:
that:
- "result.changed == False"
- "result.msg == '{{ item }} timeout unchanged'"
- result.msg == mymsg

- name: Set timeout to 0 (check mode)
community.cassandra.cassandra_timeout:
Expand All @@ -45,10 +54,13 @@
check_mode: yes
register: result

- set_fact:
mymsg: "{{ item }} timeout changed"

- assert:
that:
- result.changed
- "result.msg == '{{ item }} timeout changed'"
- result.msg == mymsg

- name: Set timeout to 100
community.cassandra.cassandra_timeout:
Expand All @@ -59,23 +71,29 @@
debug: true
register: result

- set_fact:
mymsg: "{{ item }} timeout changed"

- assert:
that:
- result.changed
- "result.msg == '{{ item }} timeout changed'"
- result.msg == mymsg

- name: "Get {{ item }} timeout"
ansible.builtin.shell: nodetool -u {{ cassandra_admin_user }} -pw {{ cassandra_admin_pwd }} -h 127.0.0.1 gettimeout {{ item }}
register: result

- set_fact:
expected_stdout: "Current timeout for type {{ item }}: 100 ms"

- name: Ensure timeout is 100
assert:
that:
- "result.stdout == 'Current timeout for type {{ item }}: 100 ms'"
- result.stdout == expected_stdout

- name: Return timeout to something high otherwise we mess up later tests
community.cassandra.cassandra_timeout:
username: "{{ cassandra_admin_user }}"
password: "{{ cassandra_admin_pwd }}"
timeout: 5000
timeout_type: "{{ item }}"
timeout_type: "{{ item }}"

0 comments on commit a3d8e56

Please sign in to comment.