diff options
author | Glenn Strauss <gstrauss@gluelogic.com> | 2018-12-03 18:59:37 -0500 |
---|---|---|
committer | Glenn Strauss <gstrauss@gluelogic.com> | 2018-12-03 23:03:04 -0500 |
commit | 5a32d0f72a35e41db90de2f80531b3059dabdf4c (patch) | |
tree | f05fecd926a4fe441a40233004c0f986b3404b4b /src/t/test_mod_access.c | |
parent | ddf95741b5330e025733ffa6678dac971a48efa0 (diff) | |
download | lighttpd-git-5a32d0f72a35e41db90de2f80531b3059dabdf4c.tar.gz |
[mod_access] t/test_mod_access
create t/test_mod_access to test mod_access basic logic
remove tests/mod-access.t
Diffstat (limited to 'src/t/test_mod_access.c')
-rw-r--r-- | src/t/test_mod_access.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/t/test_mod_access.c b/src/t/test_mod_access.c new file mode 100644 index 00000000..820cee4c --- /dev/null +++ b/src/t/test_mod_access.c @@ -0,0 +1,55 @@ +#include "first.h" + +#undef NDEBUG +#include <assert.h> +#include <stdlib.h> +#include <stdio.h> + +#include "mod_access.c" + +static void test_mod_access_check(void) { + array *allow = array_init(); + array *deny = array_init(); + buffer *urlpath = buffer_init(); + int lc = 0; + + /* empty allow and deny lists */ + buffer_copy_string_len(urlpath, CONST_STR_LEN("/")); + assert(1 == mod_access_check(allow, deny, urlpath, lc)); + + array_insert_value(deny, CONST_STR_LEN("~")); + array_insert_value(deny, CONST_STR_LEN(".inc")); + + /* deny */ + buffer_copy_string_len(urlpath, CONST_STR_LEN("/index.html~")); + assert(0 == mod_access_check(allow, deny, urlpath, lc)); + lc = 1; + buffer_copy_string_len(urlpath, CONST_STR_LEN("/index.INC")); + assert(0 == mod_access_check(allow, deny, urlpath, lc)); + lc = 0; + + array_insert_value(allow, CONST_STR_LEN(".txt")); + array_insert_value(deny, CONST_STR_LEN(".txt"));/* allow takes precedence */ + + /* explicitly allowed */ + buffer_copy_string_len(urlpath, CONST_STR_LEN("/ssi-include.txt")); + assert(1 == mod_access_check(allow, deny, urlpath, lc)); + lc = 1; + buffer_copy_string_len(urlpath, CONST_STR_LEN("/ssi-include.TXT")); + assert(1 == mod_access_check(allow, deny, urlpath, lc)); + lc = 0; + + /* allow not empty and urlpath not explicitly allowed */ + buffer_copy_string_len(urlpath, CONST_STR_LEN("/cgi.pl")); + assert(0 == mod_access_check(allow, deny, urlpath, lc)); + + array_free(allow); + array_free(deny); + buffer_free(urlpath); +} + +int main (void) { + test_mod_access_check(); + + return 0; +} |