Skip to content

Commit ba0aacc

Browse files
authored
Tweak tests to make TravisCI reliably pass (#30)
1 parent a9697ff commit ba0aacc

File tree

12 files changed

+186
-73
lines changed

12 files changed

+186
-73
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 0.3.1 (Unreleased)
44

5+
ENHANCEMENTS:
6+
7+
* Split the default Molecule scenario into a simple and advanced scenario to solve timeout issues encountered in TravisCI.
8+
59
BUG FIXES:
610

711
* Rename handlers to use more specific role related naming and prevent namespace collision issues.

defaults/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ nginx_app_protect_conf_template:
7979
out_file_location: /etc/nginx/
8080
nginx_app_protect_demo_workload_protocol: http://
8181
nginx_app_protect_demo_workload_host: 10.1.1.1:8080
82-
nginx_app_protect_log_policy_syslog_target: 127.0.0.1:514
82+
nginx_app_protect_log_policy_syslog_target: 127.0.0.1:514 # DEPRECATED -- use nginx_app_protect_log_policy_target instead
83+
nginx_app_protect_log_policy_target: "syslog:server={{ nginx_app_protect_log_policy_syslog_target }}"

molecule/advanced/converge.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
- name: Converge
3+
hosts: nap
4+
tasks:
5+
- name: Install NGINX App Protect
6+
include_role:
7+
name: ansible-role-nginx-app-protect
8+
vars:
9+
nginx_app_protect_license:
10+
certificate: license/nginx-repo.crt
11+
key: license/nginx-repo.key
12+
nginx_app_protect_remove_license: false
13+
nginx_app_protect_install_signatures: true
14+
nginx_app_protect_install_threat_campaigns: true
15+
nginx_app_protect_configure: true
16+
nginx_app_protect_security_policy_template_enable: true
17+
nginx_app_protect_security_policy_enforcement_mode: blocking
18+
nginx_app_protect_log_policy_template_enable: true
19+
nginx_app_protect_log_policy_filter_request_type: all
20+
nginx_app_protect_conf_template_enable: true
21+
nginx_app_protect_demo_workload_protocol: http://
22+
nginx_app_protect_demo_workload_host: test-workload:80
23+
nginx_app_protect_log_policy_syslog_target: localhost:514
24+
nginx_app_protect_timeout: 180

molecule/advanced/molecule.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
driver:
3+
name: docker
4+
lint: |
5+
set -e
6+
yamllint .
7+
ansible-lint --force-color
8+
platforms:
9+
- name: test-workload
10+
groups:
11+
- workload
12+
image: nginxdemos/hello
13+
privileged: true
14+
networks:
15+
- name: molecule-test
16+
- name: centos-7
17+
groups:
18+
- nap
19+
image: centos:7
20+
dockerfile: ../Dockerfile.j2
21+
privileged: true
22+
networks:
23+
- name: molecule-test
24+
volumes:
25+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
26+
command: "/usr/sbin/init"
27+
- name: ubuntu-bionic
28+
groups:
29+
- nap
30+
image: ubuntu:bionic
31+
dockerfile: ../Dockerfile.j2
32+
privileged: true
33+
networks:
34+
- name: molecule-test
35+
volumes:
36+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
37+
command: "/sbin/init"
38+
- name: debian-stretch
39+
groups:
40+
- nap
41+
image: debian:stretch-slim
42+
dockerfile: ../Dockerfile.j2
43+
privileged: true
44+
networks:
45+
- name: molecule-test
46+
volumes:
47+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
48+
command: "/sbin/init"
49+
provisioner:
50+
name: ansible
51+
config_options:
52+
defaults:
53+
no_target_syslog: true
54+
log: false

molecule/advanced/prepare.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
- name: Prepare
3+
hosts: localhost
4+
gather_facts: false
5+
tasks:
6+
- name: Create ephemeral license certificate file from b64 decoded env var
7+
copy:
8+
content: "{{ lookup('env','NGINX_CRT') | b64decode }}"
9+
dest: ../../files/license/nginx-repo.crt
10+
force: false
11+
mode: 0444
12+
13+
- name: Create ephemeral license key file from b64 decoded env var
14+
copy:
15+
content: "{{ lookup('env','NGINX_KEY') | b64decode }}"
16+
dest: ../../files/license/nginx-repo.key
17+
force: false
18+
mode: 0444
19+
20+
- name: Set up rsyslog server for verifying NAP syslog events
21+
hosts: nap
22+
roles:
23+
- role: robertdebock.rsyslog
24+
vars:
25+
rsyslog_receiver: true
26+
rsyslog_remote_tcp: true
27+
rsyslog_remote_port: 514
28+
29+
- name: Prepare workload for tests
30+
hosts: workload
31+
gather_facts: false
32+
tasks:
33+
- name: Start nginx on test workload
34+
raw: nohup nginx </dev/null >/dev/null 2>&1 & sleep 1
35+
changed_when: false

molecule/advanced/verify.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
- name: Verify
3+
hosts: nap
4+
tasks:
5+
- name: Check if NGINX is installed
6+
package:
7+
name: nginx-plus
8+
check_mode: true
9+
register: install
10+
failed_when: (install is changed) or (install is failed)
11+
12+
- name: Check if NGINX App Protect is installed
13+
package:
14+
name: app-protect
15+
check_mode: true
16+
register: install
17+
failed_when: (install is changed) or (install is failed)
18+
19+
- name: Check if NGINX App Protect Signatures is installed
20+
package:
21+
name: app-protect-attack-signatures
22+
check_mode: true
23+
register: install
24+
failed_when: (install is changed) or (install is failed)
25+
26+
- name: Check if NGINX App Protect Threat Campaigns is installed
27+
package:
28+
name: app-protect-threat-campaigns
29+
check_mode: true
30+
register: install
31+
failed_when: (install is changed) or (install is failed)
32+
33+
- name: Check if NGINX service is running
34+
service:
35+
name: nginx
36+
state: started
37+
enabled: true
38+
check_mode: true
39+
register: service
40+
failed_when: (service is changed) or (service is failed)
41+
42+
- name: Check that a page returns a status 200 and fail if the words Hello World are not in the page contents
43+
uri:
44+
url: "http://localhost"
45+
return_content: true
46+
register: this
47+
failed_when: "'Hello World' not in this.content"
48+
49+
- name: Check that a page returns a status 200 and fail if the words Request Rejected are not in the page contents
50+
uri:
51+
url: "http://localhost/?v=<script>"
52+
return_content: true
53+
register: this
54+
failed_when: "'Request Rejected' not in this.content"
55+
56+
- name: Ensure /var/log/messages contains block event from above test
57+
shell: grep -c "Non-browser Client,Abuse of Functionality,Cross Site Scripting (XSS)" /var/log/messages || true
58+
register: event
59+
changed_when: false
60+
failed_when: event.stdout == "0"

molecule/default/converge.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
22
- name: Converge
3-
hosts: nap
3+
hosts: all
44
tasks:
55
- name: Install NGINX App Protect
66
include_role:
77
name: ansible-role-nginx-app-protect
88
vars:
9-
nginx_app_protect_enable: true
9+
nginx_app_protect_license:
10+
certificate: license/nginx-repo.crt
11+
key: license/nginx-repo.key
1012
nginx_app_protect_remove_license: false
1113
nginx_app_protect_install_signatures: true
1214
nginx_app_protect_install_threat_campaigns: true
@@ -15,11 +17,4 @@
1517
nginx_app_protect_security_policy_enforcement_mode: blocking
1618
nginx_app_protect_log_policy_template_enable: true
1719
nginx_app_protect_log_policy_filter_request_type: all
18-
nginx_app_protect_log_policy_syslog_target: localhost:514
19-
nginx_app_protect_conf_template_enable: true
20-
nginx_app_protect_demo_workload_protocol: http://
21-
nginx_app_protect_demo_workload_host: test-workload:80
22-
nginx_app_protect_license:
23-
certificate: license/nginx-repo.crt
24-
key: license/nginx-repo.key
25-
nginx_app_protect_timeout: 180
20+
nginx_app_protect_conf_template_enable: false

molecule/default/molecule.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,26 @@ lint: |
66
yamllint .
77
ansible-lint --force-color
88
platforms:
9-
- name: test-workload
10-
groups:
11-
- workload
12-
image: nginxdemos/hello
13-
privileged: true
14-
networks:
15-
- name: molecule-test
169
- name: centos-7
17-
groups:
18-
- nap
1910
image: centos:7
2011
dockerfile: ../Dockerfile.j2
2112
privileged: true
22-
networks:
23-
- name: molecule-test
2413
volumes:
2514
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
2615
command: "/usr/sbin/init"
2716
- name: ubuntu-bionic
28-
groups:
29-
- nap
3017
image: ubuntu:bionic
3118
dockerfile: ../Dockerfile.j2
3219
privileged: true
33-
networks:
34-
- name: molecule-test
3520
volumes:
3621
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
3722
command: "/sbin/init"
3823
- name: debian-stretch
39-
groups:
40-
- nap
4124
image: debian:stretch-slim
4225
dockerfile: ../Dockerfile.j2
4326
privileged: true
44-
networks:
45-
- name: molecule-test
4627
volumes:
4728
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
4829
command: "/sbin/init"
4930
provisioner:
5031
name: ansible
51-
config_options:
52-
defaults:
53-
no_target_syslog: true
54-
log: false

molecule/default/prepare.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,3 @@
1616
dest: ../../files/license/nginx-repo.key
1717
force: false
1818
mode: 0444
19-
20-
- name: Set up rsyslog server for verifying NAP syslog events
21-
hosts: nap
22-
roles:
23-
- role: robertdebock.rsyslog
24-
vars:
25-
rsyslog_receiver: true
26-
rsyslog_remote_tcp: true
27-
rsyslog_remote_port: 514
28-
29-
- name: Prepare workload for tests
30-
hosts: workload
31-
gather_facts: false
32-
tasks:
33-
- name: Start nginx on test workload
34-
raw: nohup nginx </dev/null >/dev/null 2>&1 & sleep 1
35-
changed_when: false

0 commit comments

Comments
 (0)