summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2018-12-02 03:25:20 -0500
committerGlenn Strauss <gstrauss@gluelogic.com>2018-12-03 23:03:04 -0500
commitb2a62398513499cf52e80c615d38ad951cb52f03 (patch)
tree1beb29e5f06256813a93058e8e868ac576edc43a
parent685f4ed62c45aac8196166cf8b5f32f5a8416cb5 (diff)
downloadlighttpd1.4-b2a62398513499cf52e80c615d38ad951cb52f03.tar.gz
lighttpd1.4-b2a62398513499cf52e80c615d38ad951cb52f03.zip
[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
-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/mod_simple_vhost.c32
-rw-r--r--src/t/test_mod_simple_vhost.c53
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/meson.build1
-rw-r--r--tests/mod-simplevhost.conf30
-rwxr-xr-xtests/mod-simplevhost.t37
-rwxr-xr-xtests/prepare.sh2
12 files changed, 116 insertions, 87 deletions
diff --git a/.gitignore b/.gitignore
index 83b9551b..8cc08841 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,5 +52,6 @@ test_base64
test_buffer
test_burl
test_configfile
+test_mod_simple_vhost
test_request
versionstamp.h
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 1fc8b1b6..2cf866eb 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_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()
diff --git a/src/Makefile.am b/src/Makefile.am
index a5c511b3..faec70b2 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_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)
diff --git a/src/meson.build b/src/meson.build
index a5190004..38392569 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_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',
diff --git a/src/mod_simple_vhost.c b/src/mod_simple_vhost.c
index 985e0fe2..1fae140f 100644
--- a/src/mod_simple_vhost.c
+++ b/src/mod_simple_vhost.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) {
diff --git a/src/t/test_mod_simple_vhost.c b/src/t/test_mod_simple_vhost.c
new file mode 100644
index 00000000..55af4c28
--- /dev/null
+++ b/src/t/test_mod_simple_vhost.c
@@ -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;
+}
+
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 98cfb954..f033e562 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -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
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 398c67c3..7f1f1663 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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 \
diff --git a/tests/meson.build b/tests/meson.build
index 1ed3624e..4927f795 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -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',
diff --git a/tests/mod-simplevhost.conf b/tests/mod-simplevhost.conf
deleted file mode 100644
index 533fe3b9..00000000
--- a/tests/mod-simplevhost.conf
+++ /dev/null
@@ -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/"
-}
diff --git a/tests/mod-simplevhost.t b/tests/mod-simplevhost.t
deleted file mode 100755
index 1ff69975..00000000
--- a/tests/mod-simplevhost.t
+++ /dev/null
@@ -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");
diff --git a/tests/prepare.sh b/tests/prepare.sh
index 306d1ce6..f4f11ef8 100755
--- a/tests/prepare.sh
+++ b/tests/prepare.sh
@@ -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"