Imported Upstream version 1.4.0
[platform/upstream/augeas.git] / lenses / tests / test_httpd.aug
1 module Test_httpd =
2
3 (* Check that we can iterate on directive *)
4 let _ = Httpd.directive+
5
6 (* Check that we can do a non iterative section *)
7 let _ = Httpd.section Httpd.directive
8
9 (* directives testing *)
10 let d1 = "ServerRoot \"/etc/apache2\"\n"
11 test Httpd.directive get d1 =
12   { "directive" = "ServerRoot"
13     { "arg" = "\"/etc/apache2\"" }
14   }
15
16 (* simple quotes *)
17 let d1s = "ServerRoot '/etc/apache2'\n"
18 test Httpd.directive get d1s =
19   { "directive" = "ServerRoot"
20     { "arg" = "'/etc/apache2'" }
21   }
22
23 let d2 = "ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/\n"
24 test Httpd.directive get d2 =
25   { "directive" = "ScriptAlias"
26     { "arg" = "/cgi-bin/" }
27     { "arg" = "/usr/lib/cgi-bin/" }
28   }
29
30 let d3 = "LockFile /var/lock/apache2/accept.lock\n"
31 test Httpd.directive get d3 =
32   { "directive" = "LockFile"
33     { "arg" = "/var/lock/apache2/accept.lock" }
34   }
35
36 let c1 = "
37 <IfModule>
38 </IfModule>
39 "
40 let c1_put =
41 "
42 <IfModule foo bar>
43 </IfModule>
44 "
45
46
47 test Httpd.lns get c1 = { }{ "IfModule" }
48
49 test Httpd.lns put c1 after set "/IfModule/arg[1]" "foo";
50                             set "/IfModule/arg[2]" "bar" = c1_put
51
52 let c2 = "
53 <IfModule !mpm_winnt.c>
54   <IfModule !mpm_netware.c>
55     LockFile /var/lock/apache2/accept.lock
56   </IfModule>
57 </IfModule>
58 "
59
60 test Httpd.lns get c2 =
61   {  }
62   { "IfModule"
63     { "arg" = "!mpm_winnt.c" }
64     { "IfModule"
65       { "arg" = "!mpm_netware.c" }
66       { "directive" = "LockFile"
67         { "arg" = "/var/lock/apache2/accept.lock" }
68       }
69     }
70   }
71
72 (* arguments must be the first child of the section *)
73 test Httpd.lns put c2 after rm "/IfModule/arg";
74                             insb "arg" "/IfModule/*[1]";
75                             set "/IfModule/arg" "foo"  =
76 "
77 <IfModule foo>
78   <IfModule !mpm_netware.c>
79     LockFile /var/lock/apache2/accept.lock
80   </IfModule>
81 </IfModule>
82 "
83
84 let c3 = "
85 <IfModule mpm_event_module>
86     StartServers          2
87     MaxClients          150
88     MinSpareThreads      25
89     MaxSpareThreads      75
90     ThreadLimit          64
91     ThreadsPerChild      25
92     MaxRequestsPerChild   0
93 </IfModule>
94 "
95
96 test Httpd.lns get c3 =
97   {  }
98   { "IfModule"
99     { "arg" = "mpm_event_module" }
100     { "directive" = "StartServers"
101       { "arg" = "2" }
102     }
103     { "directive" = "MaxClients"
104       { "arg" = "150" }
105     }
106     { "directive" = "MinSpareThreads"
107       { "arg" = "25" }
108     }
109     { "directive" = "MaxSpareThreads"
110       { "arg" = "75" }
111     }
112     { "directive" = "ThreadLimit"
113       { "arg" = "64" }
114     }
115     { "directive" = "ThreadsPerChild"
116       { "arg" = "25" }
117     }
118     { "directive" = "MaxRequestsPerChild"
119       { "arg" = "0" }
120     }
121   }
122
123
124
125 let c4 = "
126 <Files ~ \"^\.ht\">
127     Order allow,deny
128     Deny from all
129     Satisfy all
130 </Files>
131 "
132
133 test Httpd.lns get c4 =
134   {  }
135   { "Files"
136     { "arg" = "~" }
137     { "arg" = "\"^\.ht\"" }
138     { "directive" = "Order"
139       { "arg" = "allow,deny" }
140     }
141     { "directive" = "Deny"
142       { "arg" = "from" }
143       { "arg" = "all" }
144     }
145     { "directive" = "Satisfy"
146       { "arg" = "all" }
147     }
148   }
149
150
151
152 let c5 = "LogFormat \"%{User-agent}i\" agent\n"
153 test Httpd.lns get c5 =
154   { "directive" = "LogFormat"
155     { "arg" = "\"%{User-agent}i\"" }
156     { "arg" = "agent" }
157   }
158
159 let c7 = "LogFormat \"%v:%p %h %l %u %t \\"%r\\" %>s %O \\"%{Referer}i\\" \\"%{User-Agent}i\\"\" vhost_combined\n"
160 test Httpd.lns get c7 =
161   { "directive" = "LogFormat"
162     { "arg" = "\"%v:%p %h %l %u %t \\"%r\\" %>s %O \\"%{Referer}i\\" \\"%{User-Agent}i\\"\"" }
163     { "arg" = "vhost_combined" }
164   }
165
166 let c8 = "IndexIgnore .??* *~ *# RCS CVS *,v *,t \n"
167 test Httpd.directive get c8 =
168   { "directive" = "IndexIgnore"
169     { "arg" = ".??*" }
170     { "arg" = "*~" }
171     { "arg" = "*#" }
172     { "arg" = "RCS" }
173     { "arg" = "CVS" }
174     { "arg" = "*,v" }
175     { "arg" = "*,t" }
176   }
177
178 (* FIXME: not yet supported:
179  * The backslash "\" may be used as the last character on a line to indicate
180  * that the directive continues onto the next line. There must be no other
181  * characters or white space between the backslash and the end of the line.
182  *)
183 let multiline = "Options Indexes \
184 FollowSymLinks MultiViews
185 "
186
187 test Httpd.directive get multiline =
188   { "directive" = "Options"
189     { "arg" = "Indexes" }
190     { "arg" = "FollowSymLinks" }
191     { "arg" = "MultiViews" }
192   }
193
194
195 let conf2 = "<VirtualHost *:80>
196     ServerAdmin webmaster@localhost
197
198     DocumentRoot /var/www
199     <Directory />
200         Options FollowSymLinks
201         AllowOverride None
202     </Directory>
203     <Directory /var/www/>
204         Options Indexes FollowSymLinks MultiViews
205         AllowOverride None
206         Order allow,deny
207         allow from all
208     </Directory>
209
210     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
211     <Directory \"/usr/lib/cgi-bin\">
212         AllowOverride None
213         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
214         Order allow,deny
215         Allow from all
216     </Directory>
217
218     ErrorLog /var/log/apache2/error.log
219
220     # Possible values include: debug, info, notice, warn, error, crit,
221     # alert, emerg.
222     LogLevel warn
223
224     CustomLog /var/log/apache2/access.log combined
225
226     SSLRequireSSL
227
228     Alias /doc/ \"/usr/share/doc/\"
229     <Directory \"/usr/share/doc/\">
230         Options Indexes MultiViews FollowSymLinks
231         AllowOverride None
232         Order deny,allow
233         Deny from all
234         Allow from 127.0.0.0/255.0.0.0 ::1/128
235     </Directory>
236
237 </VirtualHost>
238 "
239
240 test Httpd.lns get conf2 =
241    { "VirtualHost"
242     { "arg" = "*:80" }
243     { "directive" = "ServerAdmin"
244       { "arg" = "webmaster@localhost" }
245     }
246     {  }
247     { "directive" = "DocumentRoot"
248       { "arg" = "/var/www" }
249     }
250     { "Directory"
251       { "arg" = "/" }
252       { "directive" = "Options"
253         { "arg" = "FollowSymLinks" }
254       }
255       { "directive" = "AllowOverride"
256         { "arg" = "None" }
257       }
258     }
259     { "Directory"
260       { "arg" = "/var/www/" }
261       { "directive" = "Options"
262         { "arg" = "Indexes" }
263         { "arg" = "FollowSymLinks" }
264         { "arg" = "MultiViews" }
265       }
266       { "directive" = "AllowOverride"
267         { "arg" = "None" }
268       }
269       { "directive" = "Order"
270         { "arg" = "allow,deny" }
271       }
272       { "directive" = "allow"
273         { "arg" = "from" }
274         { "arg" = "all" }
275       }
276     }
277     {  }
278     { "directive" = "ScriptAlias"
279       { "arg" = "/cgi-bin/" }
280       { "arg" = "/usr/lib/cgi-bin/" }
281     }
282     { "Directory"
283       { "arg" = "\"/usr/lib/cgi-bin\"" }
284       { "directive" = "AllowOverride"
285         { "arg" = "None" }
286       }
287       { "directive" = "Options"
288         { "arg" = "+ExecCGI" }
289         { "arg" = "-MultiViews" }
290         { "arg" = "+SymLinksIfOwnerMatch" }
291       }
292       { "directive" = "Order"
293         { "arg" = "allow,deny" }
294       }
295       { "directive" = "Allow"
296         { "arg" = "from" }
297         { "arg" = "all" }
298       }
299     }
300     {  }
301     { "directive" = "ErrorLog"
302       { "arg" = "/var/log/apache2/error.log" }
303     }
304     {  }
305     { "#comment" = "Possible values include: debug, info, notice, warn, error, crit," }
306     { "#comment" = "alert, emerg." }
307     { "directive" = "LogLevel"
308       { "arg" = "warn" }
309     }
310     {  }
311     { "directive" = "CustomLog"
312       { "arg" = "/var/log/apache2/access.log" }
313       { "arg" = "combined" }
314     }
315     {  }
316     { "directive" = "SSLRequireSSL" }
317     {  }
318     { "directive" = "Alias"
319       { "arg" = "/doc/" }
320       { "arg" = "\"/usr/share/doc/\"" }
321     }
322     { "Directory"
323       { "arg" = "\"/usr/share/doc/\"" }
324       { "directive" = "Options"
325         { "arg" = "Indexes" }
326         { "arg" = "MultiViews" }
327         { "arg" = "FollowSymLinks" }
328       }
329       { "directive" = "AllowOverride"
330         { "arg" = "None" }
331       }
332       { "directive" = "Order"
333         { "arg" = "deny,allow" }
334       }
335       { "directive" = "Deny"
336         { "arg" = "from" }
337         { "arg" = "all" }
338       }
339       { "directive" = "Allow"
340         { "arg" = "from" }
341         { "arg" = "127.0.0.0/255.0.0.0" }
342         { "arg" = "::1/128" }
343       }
344     }
345     {  }
346   }
347
348 (* Eol comment *)
349 test Httpd.lns get "<a> # a comment
350 MyDirective Foo
351 </a>\n" =
352   { "a"
353     { "#comment" = "a comment" }
354     { "directive" = "MyDirective" { "arg" = "Foo" } } }
355
356 test Httpd.lns get "<a>
357 # a comment
358 </a>\n" =
359   { "a" { "#comment" = "a comment" } }
360
361 (* Test: Httpd.lns
362      Newlines inside quoted value (GH issue #104) *)
363 test Httpd.lns get "Single 'Foo\\
364 bar'
365 Double \"Foo\\
366 bar\"\n" =
367   { "directive" = "Single"
368     { "arg" = "'Foo\\\nbar'" } }
369   { "directive" = "Double"
370     { "arg" = "\"Foo\\\nbar\"" } }
371
372 (* Test: Httpd.lns
373      Support >= in tags (GH #154) *)
374 let versioncheck = "
375 <IfVersion = 2.1>
376 <IfModule !proxy_ajp_module>
377 LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
378 </IfModule>
379 </IfVersion>
380
381 <IfVersion >= 2.4>
382 <IfModule !proxy_ajp_module>
383 LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
384 </IfModule>
385 </IfVersion>
386 "
387
388 test Httpd.lns get versioncheck =
389   { }
390   { "IfVersion"
391     { "arg" = "=" }
392     { "arg" = "2.1" }
393     { "IfModule"
394       { "arg" = "!proxy_ajp_module" }
395       { "directive" = "LoadModule"
396         { "arg" = "proxy_ajp_module" }
397         { "arg" = "modules/mod_proxy_ajp.so" }
398       }
399     }
400   }
401   {}
402   { "IfVersion"
403     { "arg" = ">=" }
404     { "arg" = "2.4" }
405     { "IfModule"
406       { "arg" = "!proxy_ajp_module" }
407       { "directive" = "LoadModule"
408         { "arg" = "proxy_ajp_module" }
409         { "arg" = "modules/mod_proxy_ajp.so" }
410       }
411     }
412   }
413
414
415 (* GH #220 *)
416 let double_comment = "<IfDefine Foo>
417 ##
418 ## Comment
419 ##
420 </IfDefine>\n"
421
422 test Httpd.lns get double_comment =
423   { "IfDefine"
424     { "arg" = "Foo" }
425     { "#comment" = "#" }
426     { "#comment" = "# Comment" }
427     { "#comment" = "#" }
428   }
429
430 let single_comment = "<IfDefine Foo>
431 #
432 ## Comment
433 ##
434 </IfDefine>\n"
435
436 test Httpd.lns get single_comment =
437   { "IfDefine"
438     { "arg" = "Foo" }
439     { "#comment" = "# Comment" }
440     { "#comment" = "#" }
441   }
442
443 let single_empty = "<IfDefine Foo>
444 #
445
446 </IfDefine>\n"
447 test Httpd.lns get single_empty =
448   { "IfDefine"
449     { "arg" = "Foo" }
450   }
451
452 let eol_empty = "<IfDefine Foo> #
453 </IfDefine>\n"
454 test Httpd.lns get eol_empty =
455   { "IfDefine"
456     { "arg" = "Foo" }
457   }
458
459 (* Issue #140 *)
460 test Httpd.lns get "<IfModule mod_ssl.c>
461     # one comment
462     # another comment
463 </IfModule>\n" =
464   { "IfModule"
465     { "arg" = "mod_ssl.c" }
466     { "#comment" = "one comment" }
467     { "#comment" = "another comment" }
468   }