3 Provides unit tests and examples for the <Nginx> lens.
7 (* Check for non-recursive ambiguities *)
8 let directive = Nginx.simple
11 | Nginx.block Nginx.simple
14 (* Do some limited typechecking on the recursive lens; note that
15 unrolling once more leads to a typecheck error that seems to
16 be spurious, though it's not clear why
18 Unrolling once more amounts to adding the clause
19 Nginx.block (Nginx.block Nginx.simple)
20 to unrolled and results in an error
21 overlapping lenses in union.get
22 Example matched by both: 'upstream{}\n'
24 let unrolled = Nginx.simple | Nginx.block Nginx.simple
26 let lns_unrolled = (Util.comment | Util.empty | unrolled)
28 (* Normal unit tests *)
31 let conf ="user nginx nginx;
33 error_log /var/log/nginx/error_log info;
36 worker_connections 1024;
45 include /etc/nginx/mime.types;
46 default_type application/octet-stream;
48 '$remote_addr - $remote_user [$time_local] '
49 '\"$request\" $status $bytes_sent '
50 '\"$http_referer\" \"$http_user_agent\" '
52 client_header_timeout 10m;
53 client_body_timeout 10m;
55 connection_pool_size 256;
56 client_header_buffer_size 2k;
57 large_client_header_buffers 4 8k;
62 gzip_types text/plain application/json;
68 keepalive_timeout 75 20;
69 ignore_invalid_headers on;
70 index index.html index.php;
71 include vhosts/*.conf;
76 { "user" = "nginx nginx" }
77 { "worker_processes" = "1" }
78 { "error_log" = "/var/log/nginx/error_log info" }
81 { "worker_connections" = "1024" }
84 { "#comment" = "comment1" }
85 { "#comment" = "comment2" }
88 { "#comment" = "comment3" }
89 { "include" = "/etc/nginx/mime.types" }
90 { "default_type" = "application/octet-stream" }
91 { "log_format" = "main
92 '$remote_addr - $remote_user [$time_local] '
93 '\"$request\" $status $bytes_sent '
94 '\"$http_referer\" \"$http_user_agent\" '
96 { "client_header_timeout" = "10m" }
97 { "client_body_timeout" = "10m" }
98 { "send_timeout" = "10m" }
99 { "connection_pool_size" = "256" }
100 { "client_header_buffer_size" = "2k" }
101 { "large_client_header_buffers" = "4 8k" }
102 { "request_pool_size" = "4k" }
104 { "gzip_min_length" = "1000" }
105 { "gzip_buffers" = "4 8k" }
106 { "gzip_types" = "text/plain application/json" }
107 { "output_buffers" = "1 32k" }
108 { "postpone_output" = "1460" }
109 { "sendfile" = "on" }
110 { "tcp_nopush" = "on" }
111 { "tcp_nodelay" = "on" }
112 { "keepalive_timeout" = "75 20" }
113 { "ignore_invalid_headers" = "on" }
114 { "index" = "index.html index.php" }
115 { "include" = "vhosts/*.conf" } }
117 (* location blocks *)
118 test lns get "location / { }\n" =
122 test lns get "location = / { }\n" =
127 test lns get "location /documents/ { }\n" =
129 { "#uri" = "/documents/" } }
131 test lns get "location ^~ /images/ { }\n" =
134 { "#uri" = "/images/" } }
136 test lns get "location ~* \.(gif|jpg|jpeg)$ { }\n" =
139 { "#uri" = "\.(gif|jpg|jpeg)$" } }
141 test lns get "location @fallback { }\n" =
143 { "#uri" = "@fallback" } }
146 test lns get "if ($slow) {
150 { "#cond" = "($slow)" }
151 { "tcp_nodelay" = "on" } }
153 test lns get "if ($request_method = POST) { }\n" =
155 { "#cond" = "($request_method = POST)" } }
158 test lns get "if ($http_cookie ~* \"id=([^;]+)(?:;|$)\") { }\n" =
160 { "#cond" = "($http_cookie ~* \"id=([^;]+)(?:;|$)\")" } }
163 test lns get "geo $geo { }\n" =
165 { "#geo" = "$geo" } }
167 test lns get "geo $address $geo { }\n" =
169 { "#address" = "$address" }
170 { "#geo" = "$geo" } }
173 test lns get "map $http_host $name { }\n" =
175 { "#source" = "$http_host" }
176 { "#variable" = "$name" } }
178 (* split_clients block *)
179 test lns get "split_clients \"${remote_addr}AAA\" $variable { }\n" =
181 { "#string" = "\"${remote_addr}AAA\"" }
182 { "#variable" = "$variable" } }
185 test lns get "upstream backend { }\n" =
187 { "#name" = "backend" } }
189 (* GH #179 - recursive blocks *)
206 { "root" = "html" } } }
210 (* GH #335 - server single line entries *)
211 let http_server_single_line_entries = "http {
212 upstream big_server_com {
213 server 127.0.0.3:8000 weight=5;
214 server 127.0.0.3:8001 weight=5;
215 server 192.168.0.1:8000;
216 server 192.168.0.1:8001;
217 server backend2.example.com:8080 fail_timeout=5s slow_start=30s;
218 server backend3.example.com resolve;
222 test lns get http_server_single_line_entries =
225 { "#name" = "big_server_com" }
226 { "@server" { "@address" = "127.0.0.3:8000" } { "weight" = "5" } }
227 { "@server" { "@address" = "127.0.0.3:8001" } { "weight" = "5" } }
228 { "@server" { "@address" = "192.168.0.1:8000" } }
229 { "@server" { "@address" = "192.168.0.1:8001" } }
231 { "@address" = "backend2.example.com:8080" }
232 { "fail_timeout" = "5s" }
233 { "slow_start" = "30s" } }
235 { "@address" = "backend3.example.com" }
238 (* Make sure we do not screw up the indentation of the file *)
239 test lns put http after set "/http/gzip" "off" =
269 { "127.0.0.1" = "2" }
270 { "192.168.1.0" = "1"
276 { "2001:0db8::" = "1"
277 { "mask" = "32" } } } }
279 test lns get "add_header X-XSS-Protection \"1; mode=block\" always;\n" =
280 { "add_header" = "X-XSS-Protection \"1; mode=block\" always" }
282 test lns get "location /foo {
284 internal; # only valid in location blocks
288 { "root" = "/var/www/html" }
290 { "#comment" = "only valid in location blocks" } } }
292 test lns get "upstream php-handler {
293 server unix:/var/run/php/php7.3-fpm.sock;
296 { "#name" = "php-handler" }
298 { "@address" = "unix:/var/run/php/php7.3-fpm.sock" } } }