Skip to content

Commit 13bf2dd

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 3a214df commit 13bf2dd

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/tests_all_settings.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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: Get custom settings from pwquality.conf
28+
command: sed -n '/^# BEGIN ANSIBLE MANAGED BLOCK/,/^END ANSIBLE MANAGED BLOCK/ p' /etc/security/pwquality.conf
29+
register: pwquality_conf
30+
changed_when: false
31+
32+
- name: Check pwquality.conf settings
33+
assert:
34+
that:
35+
- "'minlen = 12' in pwquality_conf.stdout_lines"
36+
- "'dcredit = -1' in pwquality_conf.stdout_lines"
37+
- "'ucredit = -2' in pwquality_conf.stdout_lines"
38+
- "'lcredit = -3' in pwquality_conf.stdout_lines"
39+
- "'ocredit = -4' in pwquality_conf.stdout_lines"
40+
- "'minclass = 4' in pwquality_conf.stdout_lines"
41+
42+
- name: Read PAM config files
43+
command: "cat {{ item }}"
44+
register: pam_conf
45+
changed_when: false
46+
loop:
47+
# settings should be in our custom policy
48+
- /etc/authselect/custom/password-policy/password-auth
49+
- /etc/authselect/custom/password-policy/system-auth
50+
# /etc/pam.d/* are authselect symlinks, also check the effective end result
51+
- /etc/pam.d/password-auth
52+
- /etc/pam.d/system-auth
53+
54+
- name: Verify PAM config file settings
55+
assert:
56+
that:
57+
- item.stdout is search('pam_pwhistory.so.*remember=10')
58+
- item.stdout is search('pam_pwquality.so.*enforce_for_root')
59+
loop: "{{ pam_conf.results }}"
60+
61+
- name: Get faillock.conf settings
62+
command: cat /etc/security/faillock.conf
63+
register: faillock_conf
64+
changed_when: false
65+
66+
- name: Check faillock.conf settings
67+
assert:
68+
that:
69+
- "'deny=5' in faillock_conf.stdout_lines"
70+
- "'unlock_time=300' in faillock_conf.stdout_lines"

0 commit comments

Comments
 (0)