Browse Source

[mod_evhost] t/test_mod_evhost

create t/test_mod_evhost to test mod_evhost basic logic
remove tests/mod-evhost.t
personal/stbuehler/fix-fdevent
Glenn Strauss 3 years ago
parent
commit
8aad091613
  1. 1
      .gitignore
  2. 20
      src/CMakeLists.txt
  3. 5
      src/Makefile.am
  4. 19
      src/meson.build
  5. 80
      src/t/test_mod_evhost.c
  6. 2
      tests/Makefile.am
  7. 47
      tests/mod-evhost.conf
  8. 63
      tests/mod-evhost.t
  9. 6
      tests/prepare.sh

1
.gitignore

@ -52,6 +52,7 @@ test_base64
test_buffer
test_burl
test_configfile
test_mod_evhost
test_mod_simple_vhost
test_request
versionstamp.h

20
src/CMakeLists.txt

@ -760,6 +760,22 @@ add_executable(test_configfile
)
add_test(NAME test_configfile COMMAND test_configfile)
add_executable(test_mod_evhost
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
)
add_test(NAME test_mod_evhost COMMAND test_mod_evhost)
add_executable(test_mod_simple_vhost
t/test_mod_simple_vhost.c
configfile-glue.c
@ -801,6 +817,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_evhost ${PCRE_LDFLAGS})
add_target_properties(test_mod_evhost COMPILE_FLAGS ${PCRE_CFLAGS})
target_link_libraries(test_mod_simple_vhost ${PCRE_LDFLAGS})
add_target_properties(test_mod_simple_vhost COMPILE_FLAGS ${PCRE_CFLAGS})
endif()
@ -1000,6 +1018,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_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})
add_target_properties(test_mod_simple_vhost COMPILE_FLAGS ${PCRE_CFLAGS} ${LIBUNWIND_CFLAGS})
target_link_libraries(test_request ${LIBUNWIND_LDFLAGS})

5
src/Makefile.am

@ -6,6 +6,7 @@ noinst_PROGRAMS=\
t/test_burl \
t/test_base64 \
t/test_configfile \
t/test_mod_evhost \
t/test_mod_simple_vhost \
t/test_request
@ -18,6 +19,7 @@ TESTS=\
t/test_burl$(EXEEXT) \
t/test_base64$(EXEEXT) \
t/test_configfile$(EXEEXT) \
t/test_mod_evhost$(EXEEXT) \
t/test_mod_simple_vhost$(EXEEXT) \
t/test_request$(EXEEXT)
@ -553,6 +555,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_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)
t_test_mod_simple_vhost_SOURCES = t/test_mod_simple_vhost.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_simple_vhost_LDADD = $(PCRE_LIB) $(LIBUNWIND_LIBS)

19
src/meson.build

@ -760,6 +760,25 @@ test('test_configfile', executable('test_configfile',
build_by_default: false,
))
test('test_mod_evhost', executable('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',
],
dependencies: common_flags + libpcre + libunwind,
build_by_default: false,
))
test('test_mod_simple_vhost', executable('test_mod_simple_vhost',
sources: [
't/test_mod_simple_vhost.c',

80
src/t/test_mod_evhost.c

@ -0,0 +1,80 @@
#include "first.h"
#undef NDEBUG
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "mod_evhost.c"
static plugin_config * test_mod_evhost_plugin_config_init(void) {
plugin_config *s = calloc(1, sizeof(plugin_config));
s->path_pieces_raw = buffer_init();
s->path_pieces = NULL;
s->len = 0;
return s;
}
static void test_mod_evhost_plugin_config_free(plugin_config *s) {
buffer_free(s->path_pieces_raw);
for (size_t i = 0; i < s->len; ++i) buffer_free(s->path_pieces[i]);
free(s->path_pieces);
free(s);
}
static void test_mod_evhost_build_doc_root_path(void) {
buffer *authority = buffer_init_string("host.example.org");
buffer *b = buffer_init();
array *a = array_init();
struct ttt {
const char *pattern;
size_t plen;
const char *expect;
size_t elen;
} tt[] = {
/* correct pattern not using dot notation */
{ CONST_STR_LEN("/web/%3/"),
CONST_STR_LEN("/web/host/") }
/* correct pattern using dot notation */
,{ CONST_STR_LEN("/web/%{3.1}/%{3.2}/%3/"),
CONST_STR_LEN("/web/h/o/host/") }
/* other pattern 1 */
,{ CONST_STR_LEN("/web/%{3.0}/"),
CONST_STR_LEN("/web/host/") }
/* other pattern 2 */
,{ CONST_STR_LEN("/web/%3.\1/"),
CONST_STR_LEN("/web/host.\1/") }
};
for (size_t i = 0; i < sizeof(tt)/sizeof(tt[0]); ++i) {
struct ttt *t = tt+i;
plugin_config *s = test_mod_evhost_plugin_config_init();
buffer_copy_string_len(s->path_pieces_raw, t->pattern, t->plen);
assert(0 == mod_evhost_parse_pattern(s));
mod_evhost_build_doc_root_path(b, a, authority, s->path_pieces, s->len);
assert(buffer_is_equal_string(b, t->expect, t->elen));
test_mod_evhost_plugin_config_free(s);
}
buffer_free(authority);
buffer_free(b);
array_free(a);
}
int main (void) {
test_mod_evhost_build_doc_root_path();
return 0;
}
/*
* stub functions
*/
handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_cache_entry **sce) {
UNUSED(srv);
UNUSED(con);
UNUSED(name);
UNUSED(sce);
return HANDLER_GO_ON;
}

2
tests/Makefile.am

@ -42,8 +42,6 @@ CONFS=\
mod-cgi.t \
mod-compress.conf \
mod-compress.t \
mod-evhost.conf \
mod-evhost.t \
mod-extforward.conf \
mod-extforward.t \
mod-fastcgi.t \

47
tests/mod-evhost.conf

@ -1,47 +0,0 @@
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/evhost"
server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
## bind to port (default: 80)
server.port = 2048
## bind to localhost (default: all interfaces)
server.bind = "localhost"
server.name = "www.example.org"
server.tag = "Proxy"
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
accesslog.filename = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.access.log"
server.modules = (
"mod_evhost",
"mod_accesslog" )
server.indexfiles = ( "index.html" )
######################## MODULE CONFIG ############################
#### mod-evhost
$HTTP["host"] =~ "evhost1.example.org" {
evhost.path-pattern = env.SRCDIR + "/tmp/lighttpd/servers/evhost/%{3.1}/%{3.2}/%3/pages/"
}
else $HTTP["host"] =~ "evhost2.example.org" {
evhost.path-pattern = env.SRCDIR + "/tmp/lighttpd/servers/evhost/%3/pages/"
}
else $HTTP["host"] =~ "evhost3.example.org" {
evhost.path-pattern = env.SRCDIR + "/tmp/lighttpd/servers/evhost/%{3.0}/pages/"
}
else $HTTP["host"] =~ "evhost4.example.org" {
evhost.path-pattern = env.SRCDIR + "/tmp/lighttpd/servers/evhost/%3.\1/pages/"
}
else $HTTP["host"] =~ "evhost5.example.org" {
evhost.path-pattern = env.SRCDIR + "/tmp/lighttpd/servers/evhost/%3.\1/pages/"
}
else $HTTP["host"] =~ "evhost.example.org" {
url.access-deny = ("")
}

63
tests/mod-evhost.t

@ -1,63 +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 => 7;
use LightyTest;
my $tf = LightyTest->new();
$tf->{CONFIGFILE} = 'mod-evhost.conf';
my $t;
ok($tf->start_proc == 0, "Starting lighttpd") or die();
# test for correct config
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Host: evhost1.example.org
EOF
);
ok($tf->handle_http($t) == 0, 'correct pattern using dot notation');
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Host: evhost2.example.org
EOF
);
ok($tf->handle_http($t) == 0, 'correct pattern not using dot notation');
# test for broken config
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Host: evhost3.example.org
EOF
);
ok($tf->handle_http($t) == 0, 'broken pattern 1');
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Host: evhost4.example.org
EOF
);
ok($tf->handle_http($t) == 0, 'broken pattern 2');
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
$t->{REQUEST} = ( <<EOF
GET /index.html HTTP/1.0
Host: evhost5.example.org
EOF
);
ok($tf->handle_http($t) == 0, 'broken pattern 3');
ok($tf->stop_proc == 0, "Stopping lighttpd");

6
tests/prepare.sh

@ -23,8 +23,6 @@ mkdir -p "${tmpdir}/servers/www.example.org/pages/indexfile/"
mkdir -p "${tmpdir}/servers/123.example.org/pages/"
mkdir -p "${tmpdir}/servers/a.example.org/pages/a/"
mkdir -p "${tmpdir}/servers/b.example.org/pages/b/"
mkdir -p "${tmpdir}/servers/evhost/e/v/evhost1/pages"
mkdir -p "${tmpdir}/servers/evhost/evhost2/pages"
mkdir -p "${tmpdir}/logs/"
mkdir -p "${tmpdir}/cache/"
mkdir -p "${tmpdir}/cache/compress/"
@ -52,9 +50,7 @@ touch "${tmpdir}/servers/www.example.org/pages/image.jpg" \
"${tmpdir}/servers/www.example.org/pages/image.JPG" \
"${tmpdir}/servers/www.example.org/pages/Foo.txt" \
"${tmpdir}/servers/www.example.org/pages/a" \
"${tmpdir}/servers/www.example.org/pages/index.html~" \
"${tmpdir}/servers/evhost/e/v/evhost1/pages/index.html" \
"${tmpdir}/servers/evhost/evhost2/pages/index.html"
"${tmpdir}/servers/www.example.org/pages/index.html~"
echo "12345" > "${tmpdir}/servers/www.example.org/pages/range.pdf"
printf "%-40s" "preparing infrastructure"

Loading…
Cancel
Save