Skip to content

Commit c593e25

Browse files
committed
tests: Add an actual integration test
tests_default.yml doesn't actually do anything other than making sure that the role succees. It does not have any assertions. Add tests_all_settings.yml based on examples/playbook_with_vars.yml which validates that the role has the desired effect. This uncovers a bug that the custom authselect policy is not applied properly.
1 parent 0d0f492 commit c593e25

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/tests_all_settings.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# SPDX-License-Identifier: MIT
2+
---
3+
- name: Test role with all settings
4+
hosts: all
5+
6+
tasks:
7+
- name: Run the role
8+
include_role:
9+
name: linux-system-roles.pam_pwd
10+
vars:
11+
# /etc/security/pwquality.conf settings
12+
pam_pwd_minlen: "12"
13+
pam_pwd_dcredit: "-1"
14+
pam_pwd_ucredit: "-2"
15+
pam_pwd_lcredit: "-3"
16+
pam_pwd_ocredit: "-4"
17+
pam_pwd_minclass: "4"
18+
19+
# PAM config settings
20+
pam_pwd_history: "10"
21+
pam_pwd_enforce_root: "enforce_for_root"
22+
23+
# /etc/security/faillock.conf settings
24+
pam_pwd_deny: "5"
25+
pam_pwd_unlock_time: "300"
26+
27+
- name: Flush handlers
28+
meta: flush_handlers
29+
30+
- name: Get custom settings from pwquality.conf
31+
command: cat /etc/security/pwquality.conf
32+
register: pwquality_conf
33+
changed_when: false
34+
35+
- name: Check pwquality.conf settings
36+
assert:
37+
that:
38+
- "'minlen = 12' in pwquality_conf.stdout_lines"
39+
- "'dcredit = -1' in pwquality_conf.stdout_lines"
40+
- "'ucredit = -2' in pwquality_conf.stdout_lines"
41+
- "'lcredit = -3' in pwquality_conf.stdout_lines"
42+
- "'ocredit = -4' in pwquality_conf.stdout_lines"
43+
- "'minclass = 4' in pwquality_conf.stdout_lines"
44+
45+
- name: Read PAM config files
46+
command: "cat {{ item }}"
47+
register: pam_conf
48+
changed_when: false
49+
loop:
50+
# settings should be in our custom policy
51+
- /etc/authselect/custom/password-policy/password-auth
52+
- /etc/authselect/custom/password-policy/system-auth
53+
# /etc/pam.d/* are authselect symlinks, also check the effective end result
54+
- /etc/pam.d/password-auth
55+
- /etc/pam.d/system-auth
56+
57+
- name: Verify PAM config file settings
58+
assert:
59+
that:
60+
- item.stdout is search('pam_pwhistory.so.*remember=10')
61+
- item.stdout is search('pam_pwquality.so.*enforce_for_root')
62+
loop: "{{ pam_conf.results }}"
63+
64+
- name: Get faillock.conf settings
65+
command: cat /etc/security/faillock.conf
66+
register: faillock_conf
67+
changed_when: false
68+
69+
- name: Check faillock.conf settings
70+
assert:
71+
that:
72+
- "'deny=5' in faillock_conf.stdout_lines"
73+
- "'unlock_time=300' in faillock_conf.stdout_lines"

0 commit comments

Comments
 (0)