blob: 5e2e15cdf9f93451295927b60a8e82c60344f14c [file] [log] [blame]
Zack Williamsb313bae2020-04-22 22:00:53 -07001---
2# nginx molecule/default/verify.yml
3#
4# SPDX-FileCopyrightText: © 2020 Open Networking Foundation <support@opennetworking.org>
5# SPDX-License-Identifier: Apache-2.0
6
7- name: Verify
8 hosts: all
9 vars:
10 nginx_static_dir: "/srv/sites"
11 tasks:
12
13 # Static site tests
14 - name: Create a test file to be served for the static site
15 lineinfile:
16 path: "{{ nginx_static_dir }}/static.example.com/index.html"
17 line: "This file is served from static.example.com"
18 mode: 0644
19 create: true
20
21 - name: Test that static site is being served with index.yaml
22 uri:
23 url: http://127.0.0.1/
24 headers:
25 Host: "static.example.com"
26 status_code: 200
27 return_content: true
28 register: webpage
29 failed_when: "'This file is served from static.example.com' not in webpage.content"
30
31 - name: Test that the static site is the default site
32 uri:
33 url: http://127.0.0.1/
34 status_code: 200
35 return_content: true
36 register: webpage
37 failed_when: "'This file is served from static.example.com' not in webpage.content"
38
39 - name: Delete static site test file
40 file:
41 path: "{{ nginx_static_dir }}/static.example.com/index.html"
42 mode: 0644
43 state: absent
44
45 - name: Verify that 403 is returned when no index.html file exists and autoindex is off
46 uri:
47 url: http://127.0.0.1/
48 headers:
49 Host: "static.example.com"
50 status_code: 403
51
52 - name: See if extra_config (teapot with code 418 at /teapot) is working
53 uri:
54 url: http://127.0.0.1/teapot
55 headers:
56 Host: "static.example.com"
57 status_code: 418
58
59 - name: Create a yaml file to check that MIME config is working
60 copy:
61 dest: "{{ nginx_static_dir }}/static.example.com/example.yaml"
62 mode: 0644
63 content: |
64 ---
65 # example YAML file
66
67 - name: Retrieve YAML file
68 uri:
69 url: http://127.0.0.1/example.yaml
70 headers:
71 Host: "static.example.com"
72 status_code: 200
73 return_content: true
74 register: webpagey
75
76 - name: Assert that yaml file uses text/yaml MIME type
77 assert:
78 that:
79 - webpagey['content_type'] == 'text/yaml'
80
81 - name: Delete yaml test file
82 file:
83 path: "{{ nginx_static_dir }}/static.example.com/example.yaml"
84 state: absent
85
86 # Test nginx autoindex
87 - name: Create a test dir to be served for the autoindex site
88 file:
89 path: "{{ nginx_static_dir }}/autoindex.example.com/autoindex_example_dir"
90 mode: 0755
91 state: directory
92
93 - name: Test that autoindex is created and lists directory
94 uri:
95 url: http://127.0.0.1/
96 headers:
97 Host: "autoindex.example.com"
98 status_code: 200
99 return_content: true
100 register: webpageai
101 failed_when: "'autoindex_example_dir' not in webpageai.content"
102
103 - name: Delete test dir for autoindex site
104 file:
105 path: "{{ nginx_static_dir }}/autoindex.example.com/autoindex_example_dir"
106 state: absent
107
108 # HTTP Basic Authentication tests
109 - name: Create a test file to be served for the authenticated site
110 lineinfile:
111 path: "{{ nginx_static_dir }}/authenticated.example.com/index.html"
112 line: "This file is served from authenticated.example.com"
113 mode: 0644
114 create: true
115
116 - name: Test that the authenticated file can't be accessed without authentication
117 uri:
118 url: http://127.0.0.1/
119 headers:
120 Host: "authenticated.example.com"
121 status_code: 401
122
123 - name: Test that the authenticated file can be accessed by authorized user
124 uri:
125 url: http://127.0.0.1/
126 url_username: "ghopper"
127 url_password: "verysecurepassword"
128 headers:
129 Host: "authenticated.example.com"
130 status_code: 200
131 return_content: true
132 register: webpage
133 failed_when: "'authenticated.example.com' not in webpage.content"
134
135 - name: Test that the authenticated file can't be accessed by unauthorized user
136 uri:
137 url: http://127.0.0.1/
138 url_username: "aturing"
139 url_password: "yetanotherpw"
140 headers:
141 Host: "authenticated.example.com"
142 status_code: 401
143
144 - name: Delete authenticated site test file
145 file:
146 path: "{{ nginx_static_dir }}/authenticated.example.com/index.html"
147 state: absent
148
149 # Proxy tests
150 - name: Verify that when proxy isn't running, NGINX returns a 502 "Bad Gateway" error
151 uri:
152 url: http://127.0.0.1/
153 headers:
154 Host: "proxy.example.com"
155 status_code: 502
156
157 - name: Create a test file to be served by the proxy
158 lineinfile:
159 path: "/tmp/index.html"
160 line: "This file is served from proxy.example.com"
161 mode: 0644
162 create: true
163
164 - name: Run a python http.server as proxy target for 20 seconds in the background
165 shell: >-
166 (cd /tmp;
167 python3 -m http.server & PY_PID=$!;
168 echo "server running: $PY_PID";
169 sleep 20;
170 kill $PY_PID) &
171 tags:
172 - skip_ansible_lint
173
174 - name: Wait 10 seconds for Python http.server to get started
175 pause:
176 seconds: 10
177
178 - name: Test that the proxy site is being served
179 uri:
180 url: http://127.0.0.1
181 headers:
182 Host: "proxy.example.com"
183 status_code: 200
184 return_content: true
185 register: webpage
186 failed_when: "'proxy.example.com' not in webpage.content"
187
188 - name: Delete proxy site test file
189 file:
190 path: "/tmp/index.html"
191 state: absent
192
193 # Redirect tests
194 - name: Check that 301 redirect is being served
195 uri:
196 url: http://127.0.0.1
197 headers:
198 Host: "redirect.example.com"
199 follow_redirects: "none"
200 status_code: 301
201 return_content: true
202 register: webpage
203 failed_when: "webpage.location != 'https://destination.example.com'"