summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2018-12-03 18:59:37 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2018-12-03 23:03:04 -0500
commit5a32d0f72a35e41db90de2f80531b3059dabdf4c (patch)
treef05fecd926a4fe441a40233004c0f986b3404b4b
parentddf95741b5330e025733ffa6678dac971a48efa0 (diff)
downloadlighttpd1.4-5a32d0f72a35e41db90de2f80531b3059dabdf4c.tar.gz
lighttpd1.4-5a32d0f72a35e41db90de2f80531b3059dabdf4c.zip
[mod_access] t/test_mod_access
create t/test_mod_access to test mod_access basic logic remove tests/mod-access.t
-rw-r--r--.gitignore1
-rw-r--r--src/CMakeLists.txt20
-rw-r--r--src/Makefile.am5
-rw-r--r--src/meson.build19
-rw-r--r--src/t/test_mod_access.c55
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/SConscript1
-rw-r--r--tests/meson.build1
-rwxr-xr-xtests/mod-access.t50
10 files changed, 100 insertions, 54 deletions
diff --git a/.gitignore b/.gitignore
index 89180398..36b55a76 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,6 +52,7 @@ test_base64
test_buffer
test_burl
test_configfile
+test_mod_access
test_mod_evhost
test_mod_simple_vhost
test_request
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 91a2fdd0..8056cd7b 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -760,6 +760,22 @@ add_executable(test_configfile
)
add_test(NAME test_configfile COMMAND test_configfile)
+add_executable(test_mod_access
+ t/test_mod_access.c
+ configfile-glue.c
+ buffer.c
+ array.c
+ data_config.c
+ data_integer.c
+ data_string.c
+ http_header.c
+ http_kv.c
+ vector.c
+ log.c
+ sock_addr.c
+)
+add_test(NAME test_mod_access COMMAND test_mod_access)
+
add_executable(test_mod_evhost
t/test_mod_evhost.c
configfile-glue.c
@@ -817,6 +833,8 @@ if(HAVE_PCRE_H)
add_target_properties(mod_redirect COMPILE_FLAGS ${PCRE_CFLAGS})
target_link_libraries(test_configfile ${PCRE_LDFLAGS})
add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS})
+ target_link_libraries(test_mod_access ${PCRE_LDFLAGS})
+ add_target_properties(test_mod_access COMPILE_FLAGS ${PCRE_CFLAGS})
target_link_libraries(test_mod_evhost ${PCRE_LDFLAGS})
add_target_properties(test_mod_evhost COMPILE_FLAGS ${PCRE_CFLAGS})
target_link_libraries(test_mod_simple_vhost ${PCRE_LDFLAGS})
@@ -1018,6 +1036,8 @@ if(WITH_LIBUNWIND)
add_target_properties(test_base64 COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
target_link_libraries(test_configfile ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
add_target_properties(test_configfile COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
+ target_link_libraries(test_mod_access ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
+ add_target_properties(test_mod_access COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
target_link_libraries(test_mod_evhost ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
add_target_properties(test_mod_evhost COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
target_link_libraries(test_mod_simple_vhost ${PCRE_LDFLAGS} ${LIBUNWIND_LDFLAGS})
diff --git a/src/Makefile.am b/src/Makefile.am
index d382d6cf..6bdf40cf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,6 +6,7 @@ noinst_PROGRAMS=\
t/test_burl \
t/test_base64 \
t/test_configfile \
+ t/test_mod_access \
t/test_mod_evhost \
t/test_mod_simple_vhost \
t/test_request
@@ -19,6 +20,7 @@ TESTS=\
t/test_burl$(EXEEXT) \
t/test_base64$(EXEEXT) \
t/test_configfile$(EXEEXT) \
+ t/test_mod_access$(EXEEXT) \
t/test_mod_evhost$(EXEEXT) \
t/test_mod_simple_vhost$(EXEEXT) \
t/test_request$(EXEEXT)
@@ -555,6 +557,9 @@ t_test_burl_LDADD = $(LIBUNWIND_LIBS)
t_test_configfile_SOURCES = t/test_configfile.c buffer.c array.c data_config.c data_integer.c data_string.c http_header.c http_kv.c vector.c log.c sock_addr.c
t_test_configfile_LDADD = $(PCRE_LIB) $(LIBUNWIND_LIBS)
+t_test_mod_access_SOURCES = t/test_mod_access.c configfile-glue.c buffer.c array.c data_config.c data_integer.c data_string.c http_header.c http_kv.c vector.c log.c sock_addr.c
+t_test_mod_access_LDADD = $(PCRE_LIB) $(LIBUNWIND_LIBS)
+
t_test_mod_evhost_SOURCES = t/test_mod_evhost.c configfile-glue.c buffer.c array.c data_config.c data_integer.c data_string.c http_header.c http_kv.c vector.c log.c sock_addr.c
t_test_mod_evhost_LDADD = $(PCRE_LIB) $(LIBUNWIND_LIBS)
diff --git a/src/meson.build b/src/meson.build
index 521e715f..e59a20ec 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -760,6 +760,25 @@ test('test_configfile', executable('test_configfile',
build_by_default: false,
))
+test('test_mod_access', executable('test_mod_access',
+ sources: [
+ 't/test_mod_access.c',
+ 'configfile-glue.c',
+ 'buffer.c',
+ 'array.c',
+ 'data_config.c',
+ 'data_integer.c',
+ 'data_string.c',
+ 'http_header.c',
+ 'http_kv.c',
+ 'vector.c',
+ 'log.c',
+ 'sock_addr.c',
+ ],
+ dependencies: common_flags + libpcre + libunwind,
+ build_by_default: false,
+))
+
test('test_mod_evhost', executable('test_mod_evhost',
sources: [
't/test_mod_evhost.c',
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;
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index f033e562..6bd93b30 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -21,7 +21,6 @@ set(T_FILES
core-response.t
core-var-include.t
lowercase.t
- mod-access.t
mod-auth.t
mod-cgi.t
mod-compress.t
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b680ef23..da67cd21 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -37,7 +37,6 @@ CONFS=\
LightyTest.pm \
lowercase.conf \
lowercase.t \
- mod-access.t \
mod-auth.t \
mod-cgi.t \
mod-compress.conf \
diff --git a/tests/SConscript b/tests/SConscript
index e542dc1c..bbb92df2 100644
--- a/tests/SConscript
+++ b/tests/SConscript
@@ -18,7 +18,6 @@ extra_dist = Split('fastcgi-10.conf \
core-request.t \
core-response.t \
core-keepalive.t \
- mod-access.t \
mod-auth.t \
mod-cgi.t \
mod-compress.t \
diff --git a/tests/meson.build b/tests/meson.build
index 4927f795..006268d0 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -30,7 +30,6 @@ tests = [
'core-response.t',
'core-var-include.t',
'lowercase.t',
- 'mod-access.t',
'mod-auth.t',
'mod-cgi.t',
'mod-compress.t',
diff --git a/tests/mod-access.t b/tests/mod-access.t
deleted file mode 100755
index de4f22c1..00000000
--- a/tests/mod-access.t
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/env perl
-BEGIN {
- # add current source dir to the include-path
- # we need this for make distcheck
- (my $srcdir = $0) =~ s,/[^/]+$,/,;
- unshift @INC, $srcdir;
-}
-
-use strict;
-use IO::Socket;
-use Test::More tests => 6;
-use LightyTest;
-
-my $tf = LightyTest->new();
-my $t;
-
-ok($tf->start_proc == 0, "Starting lighttpd") or die();
-
-$t->{REQUEST} = ( <<EOF
-GET /index.html~ HTTP/1.0
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
-ok($tf->handle_http($t) == 0, 'forbid access to ...~');
-
-$t->{REQUEST} = ( <<EOF
-GET /index.html~/ HTTP/1.0
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
-ok($tf->handle_http($t) == 0, '#1230 - forbid access to ...~ - trailing slash');
-
-$t->{REQUEST} = ( <<EOF
-GET /ssi-include.txt HTTP/1.0
-Host: allow.example.org
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
-ok($tf->handle_http($t) == 0, 'explicitly allowed');
-
-$t->{REQUEST} = ( <<EOF
-GET /cgi.pl HTTP/1.0
-Host: allow.example.org
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
-ok($tf->handle_http($t) == 0, 'not explicitly allowed');
-
-ok($tf->stop_proc == 0, "Stopping lighttpd");
-