[mod_simple_vhost] t/test_mod_simple_vhost
create t/test_mod_simple_vhost to test mod_simple_vhost basic logic remove tests/mod-simplevhost.t, which was not testing mod_simple_vhost
This commit is contained in:
parent
685f4ed62c
commit
b2a6239851
|
@ -52,5 +52,6 @@ test_base64
|
|||
test_buffer
|
||||
test_burl
|
||||
test_configfile
|
||||
test_mod_simple_vhost
|
||||
test_request
|
||||
versionstamp.h
|
||||
|
|
|
@ -760,6 +760,22 @@ add_executable(test_configfile
|
|||
)
|
||||
add_test(NAME test_configfile COMMAND test_configfile)
|
||||
|
||||
add_executable(test_mod_simple_vhost
|
||||
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
|
||||
)
|
||||
add_test(NAME test_mod_simple_vhost COMMAND test_mod_simple_vhost)
|
||||
|
||||
add_executable(test_request
|
||||
t/test_request.c
|
||||
request.c
|
||||
|
@ -785,6 +801,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_simple_vhost ${PCRE_LDFLAGS})
|
||||
add_target_properties(test_mod_simple_vhost COMPILE_FLAGS ${PCRE_CFLAGS})
|
||||
endif()
|
||||
|
||||
if(WITH_PCRE AND (WITH_MEMCACHED OR WITH_GDBM))
|
||||
|
@ -982,6 +1000,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_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})
|
||||
add_target_properties(test_request COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
|
||||
endif()
|
||||
|
|
|
@ -6,6 +6,7 @@ noinst_PROGRAMS=\
|
|||
t/test_burl \
|
||||
t/test_base64 \
|
||||
t/test_configfile \
|
||||
t/test_mod_simple_vhost \
|
||||
t/test_request
|
||||
|
||||
sbin_PROGRAMS=lighttpd lighttpd-angel
|
||||
|
@ -17,6 +18,7 @@ TESTS=\
|
|||
t/test_burl$(EXEEXT) \
|
||||
t/test_base64$(EXEEXT) \
|
||||
t/test_configfile$(EXEEXT) \
|
||||
t/test_mod_simple_vhost$(EXEEXT) \
|
||||
t/test_request$(EXEEXT)
|
||||
|
||||
lemon$(BUILD_EXEEXT): lemon.c
|
||||
|
@ -551,6 +553,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_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)
|
||||
|
||||
t_test_request_SOURCES = t/test_request.c request.c buffer.c array.c data_integer.c data_string.c http_header.c http_kv.c log.c sock_addr.c
|
||||
t_test_request_LDADD = $(LIBUNWIND_LIBS)
|
||||
|
||||
|
|
|
@ -760,6 +760,25 @@ test('test_configfile', executable('test_configfile',
|
|||
build_by_default: false,
|
||||
))
|
||||
|
||||
test('test_mod_simple_vhost', executable('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',
|
||||
],
|
||||
dependencies: common_flags + libpcre + libunwind,
|
||||
build_by_default: false,
|
||||
))
|
||||
|
||||
test('test_request', executable('test_request',
|
||||
sources: [
|
||||
't/test_request.c',
|
||||
|
|
|
@ -119,40 +119,44 @@ SETDEFAULTS_FUNC(mod_simple_vhost_set_defaults) {
|
|||
if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) {
|
||||
return HANDLER_ERROR;
|
||||
}
|
||||
|
||||
if (!buffer_string_is_empty(s->server_root))
|
||||
buffer_append_slash(s->server_root);
|
||||
if (!buffer_string_is_empty(s->document_root))
|
||||
buffer_append_slash(s->document_root);
|
||||
}
|
||||
|
||||
return HANDLER_GO_ON;
|
||||
}
|
||||
|
||||
static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) {
|
||||
stat_cache_entry *sce = NULL;
|
||||
force_assert(!buffer_string_is_empty(p->conf.server_root));
|
||||
|
||||
buffer_string_prepare_copy(out, 127);
|
||||
buffer_copy_buffer(out, p->conf.server_root);
|
||||
static void build_doc_root_path(buffer *out, buffer *sroot, buffer *host, buffer *droot) {
|
||||
force_assert(!buffer_string_is_empty(sroot));
|
||||
buffer_copy_buffer(out, sroot);
|
||||
|
||||
if (!buffer_string_is_empty(host)) {
|
||||
/* a hostname has to start with a alpha-numerical character
|
||||
* and must not contain a slash "/"
|
||||
*/
|
||||
char *dp;
|
||||
|
||||
buffer_append_slash(out);
|
||||
|
||||
if (NULL == (dp = strchr(host->ptr, ':'))) {
|
||||
buffer_append_string_buffer(out, host);
|
||||
} else {
|
||||
buffer_append_string_len(out, host->ptr, dp - host->ptr);
|
||||
}
|
||||
}
|
||||
buffer_append_slash(out);
|
||||
|
||||
if (buffer_string_length(p->conf.document_root) > 1 && p->conf.document_root->ptr[0] == '/') {
|
||||
buffer_append_string_len(out, p->conf.document_root->ptr + 1, buffer_string_length(p->conf.document_root) - 1);
|
||||
} else {
|
||||
buffer_append_string_buffer(out, p->conf.document_root);
|
||||
if (!buffer_string_is_empty(droot)) {
|
||||
buffer_append_path_len(out, CONST_BUF_LEN(droot));
|
||||
}
|
||||
else {
|
||||
buffer_append_slash(out);
|
||||
}
|
||||
}
|
||||
|
||||
static int build_doc_root(server *srv, connection *con, plugin_data *p, buffer *out, buffer *host) {
|
||||
stat_cache_entry *sce = NULL;
|
||||
|
||||
build_doc_root_path(out, p->conf.server_root, host, p->conf.document_root);
|
||||
|
||||
if (HANDLER_ERROR == stat_cache_get_entry(srv, con, out, &sce)) {
|
||||
if (p->conf.debug) {
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
#include "first.h"
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mod_simple_vhost.c"
|
||||
|
||||
static void test_mod_simple_vhost_build_doc_root_path(void) {
|
||||
buffer *sroot = buffer_init();
|
||||
buffer *host = buffer_init();
|
||||
buffer *droot = buffer_init();
|
||||
buffer *result= buffer_init();
|
||||
|
||||
buffer_copy_string_len(sroot, CONST_STR_LEN("/sroot/a/"));
|
||||
buffer_copy_string_len(host, CONST_STR_LEN("www.example.org"));
|
||||
buffer_copy_string_len(droot, CONST_STR_LEN("/droot/b/"));
|
||||
build_doc_root_path(result, sroot, host, droot);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/sroot/a/www.example.org/droot/b/")));
|
||||
|
||||
buffer_copy_string_len(host, CONST_STR_LEN("www.example.org:8080"));
|
||||
build_doc_root_path(result, sroot, host, droot);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/sroot/a/www.example.org/droot/b/")));
|
||||
|
||||
buffer_copy_string_len(droot, CONST_STR_LEN(""));
|
||||
build_doc_root_path(result, sroot, host, droot);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/sroot/a/www.example.org/")));
|
||||
|
||||
buffer_free(sroot);
|
||||
buffer_free(host);
|
||||
buffer_free(droot);
|
||||
buffer_free(result);
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
test_mod_simple_vhost_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;
|
||||
}
|
||||
|
|
@ -32,7 +32,6 @@ set(T_FILES
|
|||
mod-rewrite.t
|
||||
mod-secdownload.t
|
||||
mod-setenv.t
|
||||
mod-simplevhost.t
|
||||
mod-ssi.t
|
||||
mod-userdir.t
|
||||
request.t
|
||||
|
|
|
@ -52,8 +52,6 @@ CONFS=\
|
|||
mod-rewrite.t \
|
||||
mod-secdownload.t \
|
||||
mod-setenv.t \
|
||||
mod-simplevhost.conf \
|
||||
mod-simplevhost.t \
|
||||
mod-ssi.t \
|
||||
mod-userdir.t \
|
||||
proxy.conf \
|
||||
|
|
|
@ -41,7 +41,6 @@ tests = [
|
|||
'mod-rewrite.t',
|
||||
'mod-secdownload.t',
|
||||
'mod-setenv.t',
|
||||
'mod-simplevhost.t',
|
||||
'mod-ssi.t',
|
||||
'mod-userdir.t',
|
||||
'request.t',
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
debug.log-request-handling = "enable"
|
||||
debug.log-response-header = "disable"
|
||||
debug.log-request-header = "disable"
|
||||
|
||||
## bind to localhost (default: all interfaces)
|
||||
server.bind = "localhost"
|
||||
server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
|
||||
server.breakagelog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.breakage.log"
|
||||
server.name = "www.example.org"
|
||||
|
||||
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
|
||||
server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
|
||||
|
||||
## bind to port (default: 80)
|
||||
server.port = 2048
|
||||
|
||||
|
||||
|
||||
######################## MODULE CONFIG ############################
|
||||
|
||||
server.modules = (
|
||||
"mod_simple_vhost",
|
||||
)
|
||||
|
||||
# docroot depending on request path
|
||||
$HTTP["url"] =~ "^/a/" {
|
||||
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/a.example.org/pages/"
|
||||
} else $HTTP["url"] =~ "^/b/" {
|
||||
server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/b.example.org/pages/"
|
||||
}
|
|
@ -1,37 +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 => 4;
|
||||
use LightyTest;
|
||||
|
||||
my $tf = LightyTest->new();
|
||||
my $t;
|
||||
|
||||
$tf->{CONFIGFILE} = 'mod-simplevhost.conf';
|
||||
|
||||
ok($tf->start_proc == 0, "Starting lighttpd") or die();
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /a/a.html HTTP/1.0
|
||||
Host: www.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
||||
ok($tf->handle_http($t) == 0, 'Check /a/a.html path');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /b/b.html HTTP/1.0
|
||||
Host: www.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
||||
ok($tf->handle_http($t) == 0, 'Check /b/b.html path');
|
||||
|
||||
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
|
@ -53,8 +53,6 @@ touch "${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/a.example.org/pages/a/a.html" \
|
||||
"${tmpdir}/servers/b.example.org/pages/b/b.html" \
|
||||
"${tmpdir}/servers/evhost/e/v/evhost1/pages/index.html" \
|
||||
"${tmpdir}/servers/evhost/evhost2/pages/index.html"
|
||||
echo "12345" > "${tmpdir}/servers/www.example.org/pages/range.pdf"
|
||||
|
|
Loading…
Reference in New Issue