[mod_access] t/test_mod_access

create t/test_mod_access to test mod_access basic logic
remove tests/mod-access.t
This commit is contained in:
Glenn Strauss 2018-12-03 18:59:37 -05:00
parent ddf95741b5
commit 5a32d0f72a
10 changed files with 100 additions and 54 deletions

1
.gitignore vendored
View File

@ -52,6 +52,7 @@ test_base64
test_buffer
test_burl
test_configfile
test_mod_access
test_mod_evhost
test_mod_simple_vhost
test_request

View File

@ -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})

View File

@ -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)

View File

@ -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',

55
src/t/test_mod_access.c Normal file
View File

@ -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;
}

View File

@ -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

View File

@ -37,7 +37,6 @@ CONFS=\
LightyTest.pm \
lowercase.conf \
lowercase.t \
mod-access.t \
mod-auth.t \
mod-cgi.t \
mod-compress.conf \

View File

@ -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 \

View File

@ -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',

View File

@ -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");