Skip to content

Commit 2f93835

Browse files
authored
Merge pull request #801 from dev-sec/guard_molecule
Don't run tests if the environment is not correct
2 parents f380343 + 6cc57e1 commit 2f93835

File tree

9 files changed

+38
-0
lines changed

9 files changed

+38
-0
lines changed

Diff for: CONTRIBUTING.md

+15
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ We generally include test for coding guidelines:
9393

9494
Remember: Code is generally read much more often than written.
9595

96+
### Local testing of roles in this collection
97+
98+
We are using Molecule to test our roles.
99+
If you want to execute the tests on your machine you need Docker and Molecule.
100+
You will also need to set the `MOLECULE_DISTRO` environment variable to execute the tests.
101+
To find valid values for the variable you can take a look at our GitHub Action workflows in `.github/workflows/`.
102+
103+
Example for executing tests locally:
104+
105+
```bash
106+
pip install -r requirements.txt
107+
export MOLECULE_DISTRO="debian12"
108+
molecule test -s os_hardening
109+
```
110+
96111
### Use Markdown
97112

98113
Wherever possible, please refrain from any other formats and stick to simple markdown.

Diff for: molecule/mysql_hardening/molecule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ scenario:
3333
- prepare
3434
check_sequence:
3535
- dependency
36+
- verify ../shared/prerequisites.yml
3637
- destroy
3738
- create
3839
- prepare
@@ -48,6 +49,7 @@ scenario:
4849
- destroy
4950
test_sequence:
5051
- dependency
52+
- verify ../shared/prerequisites.yml
5153
- destroy
5254
- syntax
5355
- create

Diff for: molecule/nginx_hardening/molecule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ scenario:
3232
- prepare
3333
check_sequence:
3434
- dependency
35+
- verify ../shared/prerequisites.yml
3536
- destroy
3637
- create
3738
- prepare
@@ -47,6 +48,7 @@ scenario:
4748
- destroy
4849
test_sequence:
4950
- dependency
51+
- verify ../shared/prerequisites.yml
5052
- destroy
5153
- syntax
5254
- create

Diff for: molecule/os_hardening/molecule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ scenario:
2828
- prepare
2929
check_sequence:
3030
- dependency
31+
- verify ../shared/prerequisites.yml
3132
- destroy
3233
- create
3334
- prepare
@@ -43,6 +44,7 @@ scenario:
4344
- destroy
4445
test_sequence:
4546
- dependency
47+
- verify ../shared/prerequisites.yml
4648
- destroy
4749
- syntax
4850
- create

Diff for: molecule/os_hardening_vm/molecule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ scenario:
3737
- prepare
3838
check_sequence:
3939
- dependency
40+
- verify ../shared/prerequisites.yml
4041
- destroy
4142
- create
4243
- prepare
@@ -52,6 +53,7 @@ scenario:
5253
- destroy
5354
test_sequence:
5455
- dependency
56+
- verify ../shared/prerequisites.yml
5557
- destroy
5658
- syntax
5759
- create

Diff for: molecule/shared/prerequisites.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- name: Verify prerequisites
3+
hosts: localhost
4+
tasks:
5+
- name: Make sure environment variable for MOLECULE_DISTRO is set
6+
ansible.builtin.assert:
7+
that:
8+
- "lookup('env','MOLECULE_DISTRO')"
9+
fail_msg: "You need to set MOLECULE_DISTRO to a supported image name. See CONTRIBUTING.md"

Diff for: molecule/ssh_hardening/molecule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ scenario:
3434
- prepare
3535
check_sequence:
3636
- dependency
37+
- verify ../shared/prerequisites.yml
3738
- destroy
3839
- create
3940
- prepare
@@ -49,6 +50,7 @@ scenario:
4950
- destroy
5051
test_sequence:
5152
- dependency
53+
- verify ../shared/prerequisites.yml
5254
- destroy
5355
- syntax
5456
- create

Diff for: molecule/ssh_hardening_bsd/molecule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ scenario:
3333
- prepare
3434
check_sequence:
3535
- dependency
36+
- verify ../shared/prerequisites.yml
3637
- destroy
3738
- create
3839
- prepare
@@ -48,6 +49,7 @@ scenario:
4849
- destroy
4950
test_sequence:
5051
- dependency
52+
- verify ../shared/prerequisites.yml
5153
- destroy
5254
- syntax
5355
- create

Diff for: molecule/ssh_hardening_custom_tests/molecule.yml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ scenario:
2828
- prepare
2929
check_sequence:
3030
- dependency
31+
- verify ../shared/prerequisites.yml
3132
- destroy
3233
- create
3334
- prepare
@@ -43,6 +44,7 @@ scenario:
4344
- destroy
4445
test_sequence:
4546
- dependency
47+
- verify ../shared/prerequisites.yml
4648
- destroy
4749
- syntax
4850
- create

0 commit comments

Comments
 (0)