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 void test_mod_access (void); 52 void test_mod_access (void) 53 { 54 test_mod_access_check(); 55 } 56