xref: /lighttpd1.4/src/t/test_mod_access.c (revision 70b1af06)
1 #include "first.h"
2 
3 #undef NDEBUG
4 #include <assert.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 
8 #include "mod_access.c"
9 
10 static void test_mod_access_check(void) {
11     array *allow    = array_init(0);
12     array *deny     = array_init(0);
13     buffer *urlpath = buffer_init();
14     int lc = 0;
15 
16     /* empty allow and deny lists */
17     buffer_copy_string_len(urlpath, CONST_STR_LEN("/"));
18     assert(1 == mod_access_check(allow, deny, urlpath, lc));
19 
20     array_insert_value(deny, CONST_STR_LEN("~"));
21     array_insert_value(deny, CONST_STR_LEN(".inc"));
22 
23     /* deny */
24     buffer_copy_string_len(urlpath, CONST_STR_LEN("/index.html~"));
25     assert(0 == mod_access_check(allow, deny, urlpath, lc));
26     lc = 1;
27     buffer_copy_string_len(urlpath, CONST_STR_LEN("/index.INC"));
28     assert(0 == mod_access_check(allow, deny, urlpath, lc));
29     lc = 0;
30 
31     array_insert_value(allow, CONST_STR_LEN(".txt"));
32     array_insert_value(deny, CONST_STR_LEN(".txt"));/* allow takes precedence */
33 
34     /* explicitly allowed */
35     buffer_copy_string_len(urlpath, CONST_STR_LEN("/ssi-include.txt"));
36     assert(1 == mod_access_check(allow, deny, urlpath, lc));
37     lc = 1;
38     buffer_copy_string_len(urlpath, CONST_STR_LEN("/ssi-include.TXT"));
39     assert(1 == mod_access_check(allow, deny, urlpath, lc));
40     lc = 0;
41 
42     /* allow not empty and urlpath not explicitly allowed */
43     buffer_copy_string_len(urlpath, CONST_STR_LEN("/cgi.pl"));
44     assert(0 == mod_access_check(allow, deny, urlpath, lc));
45 
46     array_free(allow);
47     array_free(deny);
48     buffer_free(urlpath);
49 }
50 
51 int main (void) {
52     test_mod_access_check();
53 
54     return 0;
55 }
56 
57 /*
58  * stub functions
59  */
60 
61 int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname) {
62     UNUSED(srv);
63     UNUSED(p_d);
64     UNUSED(cpk);
65     UNUSED(mname);
66     return 0;
67 }
68 
69 int config_check_cond(request_st *r, int context_ndx) {
70     UNUSED(r);
71     UNUSED(context_ndx);
72     return 0;
73 }
74