summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-08-25 21:57:42 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2021-09-08 15:06:07 -0400
commitca2898f67896be77d4556c85a536975319a99dee (patch)
treea16f8896e23536fb72d3341204aed0fc63278e92
parent7a21b3856e30d307934a286c2b70aa9455820e68 (diff)
downloadlighttpd-git-ca2898f67896be77d4556c85a536975319a99dee.tar.gz
[tests] t/test_mod_indexfile
also remove some now-redundant tests from request.t and reduce scripts and directories under tests (because automake is sloooow and the fewer dirs, the better)
-rw-r--r--.gitignore1
-rw-r--r--configure.ac1
-rw-r--r--src/CMakeLists.txt21
-rw-r--r--src/Makefile.am5
-rw-r--r--src/meson.build27
-rw-r--r--src/t/test_mod_indexfile.c140
-rwxr-xr-xtests/docroot/www/404.pl4
-rw-r--r--tests/docroot/www/Makefile.am2
-rwxr-xr-xtests/docroot/www/cgi.pl3
-rw-r--r--tests/docroot/www/indexfile/Makefile.am1
-rw-r--r--tests/docroot/www/indexfile/index.pl8
-rw-r--r--tests/lighttpd.conf4
-rwxr-xr-xtests/prepare.sh2
-rwxr-xr-xtests/request.t19
14 files changed, 202 insertions, 36 deletions
diff --git a/.gitignore b/.gitignore
index 2e699450..99e7458c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -54,6 +54,7 @@ test_keyvalue
test_configfile
test_mod_access
test_mod_evhost
+test_mod_indexfile
test_mod_simple_vhost
test_mod_staticfile
test_mod_userdir
diff --git a/configure.ac b/configure.ac
index 50cc72cd..793ec82e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1696,7 +1696,6 @@ AC_CONFIG_FILES([\
Makefile \
src/Makefile \
tests/docroot/Makefile \
- tests/docroot/www/indexfile/Makefile \
tests/docroot/www/Makefile \
tests/Makefile \
])
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fdf0b10c..35e0e542 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -917,6 +917,25 @@ add_executable(test_mod_evhost
)
add_test(NAME test_mod_evhost COMMAND test_mod_evhost)
+add_executable(test_mod_indexfile
+ t/test_mod_indexfile.c
+ request.c
+ base64.c
+ buffer.c
+ burl.c
+ array.c
+ fdevent.c
+ http_etag.c
+ http_header.c
+ http_kv.c
+ log.c
+ sock_addr.c
+ stat_cache.c
+ algo_splaytree.c
+ ck.c
+)
+add_test(NAME test_mod_indexfile COMMAND test_mod_indexfile)
+
add_executable(test_mod_simple_vhost
t/test_mod_simple_vhost.c
buffer.c
@@ -1226,6 +1245,8 @@ if(WITH_LIBUNWIND)
add_target_properties(test_mod_access COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
target_link_libraries(test_mod_evhost ${LIBUNWIND_LDFLAGS})
add_target_properties(test_mod_evhost COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
+ target_link_libraries(test_mod_indexfile ${LIBUNWIND_LDFLAGS})
+ add_target_properties(test_mod_indexfile COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
target_link_libraries(test_mod_simple_vhost ${LIBUNWIND_LDFLAGS})
add_target_properties(test_mod_simple_vhost COMPILE_FLAGS ${LIBUNWIND_CFLAGS})
target_link_libraries(test_mod_staticfile ${LIBUNWIND_LDFLAGS})
diff --git a/src/Makefile.am b/src/Makefile.am
index 2115a732..ad343ec6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,7 @@ noinst_PROGRAMS=\
t/test_keyvalue \
t/test_mod_access \
t/test_mod_evhost \
+ t/test_mod_indexfile \
t/test_mod_simple_vhost \
t/test_mod_staticfile \
t/test_mod_userdir \
@@ -26,6 +27,7 @@ TESTS=\
t/test_keyvalue$(EXEEXT) \
t/test_mod_access$(EXEEXT) \
t/test_mod_evhost$(EXEEXT) \
+ t/test_mod_indexfile$(EXEEXT) \
t/test_mod_simple_vhost$(EXEEXT) \
t/test_mod_staticfile$(EXEEXT) \
t/test_mod_userdir$(EXEEXT) \
@@ -662,6 +664,9 @@ t_test_mod_access_LDADD = $(LIBUNWIND_LIBS)
t_test_mod_evhost_SOURCES = t/test_mod_evhost.c buffer.c array.c log.c ck.c
t_test_mod_evhost_LDADD = $(LIBUNWIND_LIBS)
+t_test_mod_indexfile_SOURCES = t/test_mod_indexfile.c request.c base64.c buffer.c burl.c array.c fdevent.c http_etag.c http_header.c http_kv.c log.c sock_addr.c stat_cache.c algo_splaytree.c ck.c
+t_test_mod_indexfile_LDADD = $(LIBUNWIND_LIBS) $(FAM_LIBS)
+
t_test_mod_simple_vhost_SOURCES = t/test_mod_simple_vhost.c buffer.c array.c log.c ck.c
t_test_mod_simple_vhost_LDADD = $(LIBUNWIND_LIBS)
diff --git a/src/meson.build b/src/meson.build
index daff363a..471dace1 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -942,6 +942,33 @@ test('test_mod_evhost', executable('test_mod_evhost',
build_by_default: false,
))
+test('test_mod_indexfile', executable('test_mod_indexfile',
+ sources: [
+ 't/test_mod_indexfile.c',
+ 'request.c',
+ 'base64.c',
+ 'buffer.c',
+ 'burl.c',
+ 'array.c',
+ 'fdevent.c',
+ 'http_etag.c',
+ 'http_header.c',
+ 'http_kv.c',
+ 'log.c',
+ 'sock_addr.c',
+ 'stat_cache.c',
+ 'algo_splaytree.c',
+ 'ck.c'
+ ],
+ dependencies: [ common_flags
+ , libfam
+ , libpcre
+ , libunwind
+ , libws2_32
+ ],
+ build_by_default: false,
+))
+
test('test_mod_simple_vhost', executable('test_mod_simple_vhost',
sources: [
't/test_mod_simple_vhost.c',
diff --git a/src/t/test_mod_indexfile.c b/src/t/test_mod_indexfile.c
new file mode 100644
index 00000000..f4289f82
--- /dev/null
+++ b/src/t/test_mod_indexfile.c
@@ -0,0 +1,140 @@
+#include "first.h"
+
+#undef NDEBUG
+#include <sys/types.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "mod_indexfile.c"
+
+__attribute_noinline__
+static void test_mod_indexfile_reset (request_st * const r)
+{
+ r->http_status = 0;
+ buffer_copy_string_len(&r->uri.path, CONST_STR_LEN("/"));
+ buffer_copy_string_len(&r->physical.doc_root, CONST_STR_LEN("/tmp"));
+ buffer_copy_string_len(&r->physical.path, CONST_STR_LEN("/tmp/"));
+}
+
+__attribute_noinline__
+static void
+run_mod_indexfile_tryfiles (request_st * const r, const array * const indexfiles, int line, int status, const char *desc)
+{
+ handler_t rc = mod_indexfile_tryfiles(r, indexfiles);
+ if (r->http_status != status
+ || rc != (status ? HANDLER_FINISHED : HANDLER_GO_ON)) {
+ fprintf(stderr,
+ "%s.%d: %s() failed: expected '%d', got '%d' for test %s\n",
+ __FILE__, line, "mod_indexfile_tryfiles", status,
+ r->http_status, desc);
+ fflush(stderr);
+ abort();
+ }
+}
+
+#include <unistd.h> /* unlink() */
+
+static void
+test_mod_indexfile_tryfiles (request_st * const r)
+{
+ char fn[] = "/tmp/lighttpd_mod_indexfile.XXXXXX";
+ #ifdef __COVERITY__
+ /* POSIX-2008 requires mkstemp create file with 0600 perms */
+ umask(0600);
+ #endif
+ /* coverity[secure_temp : FALSE] */
+ int fd = mkstemp(fn);
+ if (fd < 0) {
+ perror("mkstemp()");
+ exit(1);
+ }
+ struct stat st;
+ if (0 != fstat(fd, &st)) {
+ perror("fstat()");
+ exit(1);
+ }
+ array * const indexfiles = array_init(3);
+
+ test_mod_indexfile_reset(r);
+
+ run_mod_indexfile_tryfiles(r, indexfiles, __LINE__, 0,
+ "empty indexfiles");
+ assert(buffer_eq_slen(&r->physical.path, CONST_STR_LEN("/tmp/")));
+ test_mod_indexfile_reset(r);
+
+ /*(assumes modified tempfile name does not exist)*/
+ array_insert_value(indexfiles, fn+5, sizeof(fn)-6-1);
+ run_mod_indexfile_tryfiles(r, indexfiles, __LINE__, 0,
+ "non-matching indexfiles");
+ assert(buffer_eq_slen(&r->physical.path, CONST_STR_LEN("/tmp/")));
+ test_mod_indexfile_reset(r);
+
+ array_insert_value(indexfiles, fn+5, sizeof(fn)-5-1);
+ run_mod_indexfile_tryfiles(r, indexfiles, __LINE__, 0,
+ "matching indexfile entry (w/o leading '/')");
+ assert(buffer_eq_slen(&r->physical.path, fn, sizeof(fn)-1));
+ test_mod_indexfile_reset(r);
+
+ array_reset_data_strings(indexfiles);
+ array_insert_value(indexfiles, fn+4, sizeof(fn)-4-1);
+ run_mod_indexfile_tryfiles(r, indexfiles, __LINE__, 0,
+ "matching indexfile entry (w/ leading '/')");
+ assert(buffer_eq_slen(&r->physical.path, fn, sizeof(fn)-1));
+ test_mod_indexfile_reset(r);
+
+ array_free(indexfiles);
+ unlink(fn);
+}
+
+int main (void)
+{
+ request_st r;
+
+ memset(&r, 0, sizeof(request_st));
+ r.conf.errh = log_error_st_init();
+ r.conf.errh->errorlog_fd = -1; /* (disable) */
+ r.conf.follow_symlink = 1;
+ array * const mimetypes = array_init(0);
+ r.conf.mimetypes = mimetypes; /*(must not be NULL)*/
+
+ test_mod_indexfile_tryfiles(&r);
+
+ array_free(mimetypes);
+ log_error_st_free(r.conf.errh);
+
+ free(r.uri.path.ptr);
+ free(r.physical.path.ptr);
+ free(r.physical.doc_root.ptr);
+
+ stat_cache_free();
+ return 0;
+}
+
+
+/*
+ * stub functions
+ */
+
+#include "fdevent_impl.h"
+int fdevent_select_init(struct fdevents *ev) { return NULL == ev; }
+int fdevent_poll_init(struct fdevents *ev) { return NULL == ev; }
+int fdevent_linux_sysepoll_init(struct fdevents *ev) { return NULL == ev; }
+int fdevent_solaris_devpoll_init(struct fdevents *ev) { return NULL == ev; }
+int fdevent_solaris_port_init(struct fdevents *ev) { return NULL == ev; }
+int fdevent_freebsd_kqueue_init(struct fdevents *ev) { return NULL == ev; }
+int fdevent_libev_init(struct fdevents *ev) { return NULL == ev; }
+
+int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname) {
+ UNUSED(srv);
+ UNUSED(p_d);
+ UNUSED(cpk);
+ UNUSED(mname);
+ return 0;
+}
+
+int config_check_cond(request_st *r, int context_ndx) {
+ UNUSED(r);
+ UNUSED(context_ndx);
+ return 0;
+}
diff --git a/tests/docroot/www/404.pl b/tests/docroot/www/404.pl
index 5b5672cf..eb5df2ee 100755
--- a/tests/docroot/www/404.pl
+++ b/tests/docroot/www/404.pl
@@ -34,6 +34,10 @@ elsif ($request_uri =~ m/^\/dynamic\/redirect_status\// ) {
"\n",
"REDIRECT_STATUS\n";
}
+elsif ($ENV{PATH_INFO} eq "/internal-redir" ) {
+ # (not actually 404 error, but use separate script from cgi.pl for testing)
+ print "Status: 200\r\n\r\n";
+}
else {
print "Status: 500\n",
"Content-Type: text/plain\n",
diff --git a/tests/docroot/www/Makefile.am b/tests/docroot/www/Makefile.am
index 4d702f73..41411e82 100644
--- a/tests/docroot/www/Makefile.am
+++ b/tests/docroot/www/Makefile.am
@@ -9,5 +9,3 @@ EXTRA_DIST=\
ssi-include.shtml \
ssi-include.txt \
ssi.shtml
-SUBDIRS=\
- indexfile
diff --git a/tests/docroot/www/cgi.pl b/tests/docroot/www/cgi.pl
index 3e7ea872..97e00d31 100755
--- a/tests/docroot/www/cgi.pl
+++ b/tests/docroot/www/cgi.pl
@@ -8,7 +8,8 @@ if ($ENV{"QUERY_STRING"} =~ /^env=(\w+)/) {
# redirection
if ($ENV{"QUERY_STRING"} eq "internal-redir") {
- print "Location: /indexfile/index.pl/foo\r\n\r\n";
+ # (not actually 404 error, but use separate script from cgi.pl for testing)
+ print "Location: /404.pl/internal-redir\r\n\r\n";
exit 0;
}
diff --git a/tests/docroot/www/indexfile/Makefile.am b/tests/docroot/www/indexfile/Makefile.am
deleted file mode 100644
index b96fec3d..00000000
--- a/tests/docroot/www/indexfile/Makefile.am
+++ /dev/null
@@ -1 +0,0 @@
-EXTRA_DIST=index.pl
diff --git a/tests/docroot/www/indexfile/index.pl b/tests/docroot/www/indexfile/index.pl
deleted file mode 100644
index dbf047b9..00000000
--- a/tests/docroot/www/indexfile/index.pl
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/usr/bin/perl
-
-if ($ENV{REDIRECT_STATUS}) {
- print "Status: $ENV{REDIRECT_STATUS}\r\n\r\n$ENV{SCRIPT_NAME}";
- exit 0;
-}
-
-print "Status: 200\r\n\r\n";
diff --git a/tests/lighttpd.conf b/tests/lighttpd.conf
index 687fc8b7..dcfb7dc4 100644
--- a/tests/lighttpd.conf
+++ b/tests/lighttpd.conf
@@ -167,8 +167,6 @@ $HTTP["host"] =~ "allow\.example\.org$" {
}
$HTTP["host"] == "cgi.example.org" {
- index-file.names = ( "nonexistent.txt", "index.pl" )
- server.error-handler-404 = "/indexfile/index.pl"
cgi.x-sendfile = "enable"
}
@@ -179,7 +177,7 @@ $HTTP["host"] == "errors.example.org" {
else $HTTP["url"] =~ "^/dynamic/redirect_status/" {
server.error-handler = "/404.pl"
}
- else $HTTP["url"] =~ "." {
+ else {
server.error-handler-404 = "/404.pl"
}
}
diff --git a/tests/prepare.sh b/tests/prepare.sh
index 053b85c7..eb6afb2b 100755
--- a/tests/prepare.sh
+++ b/tests/prepare.sh
@@ -20,7 +20,6 @@ mkdir -p "${tmpdir}/servers/www.example.org/pages/" \
"${tmpdir}/servers/www.example.org/pages/dummydir/" \
"${tmpdir}/servers/www.example.org/pages/~test รค_/" \
"${tmpdir}/servers/www.example.org/pages/expire/" \
- "${tmpdir}/servers/www.example.org/pages/indexfile/" \
"${tmpdir}/servers/123.example.org/pages/" \
"${tmpdir}/servers/a.example.org/pages/a/" \
"${tmpdir}/servers/b.example.org/pages/b/" \
@@ -35,7 +34,6 @@ cp "${srcdir}/docroot/www/"*.html \
"${srcdir}/docroot/www/"*.shtml \
"${srcdir}/docroot/www/"*.txt \
"${tmpdir}/servers/www.example.org/pages/"
-cp "${srcdir}/docroot/www/indexfile/"*.pl "${tmpdir}/servers/www.example.org/pages/indexfile/"
cp "${srcdir}/lighttpd.user" "${tmpdir}/"
cp "${srcdir}/lighttpd.htpasswd" "${tmpdir}/"
cp "${srcdir}/var-include-sub.conf" "${tmpdir}/../"
diff --git a/tests/request.t b/tests/request.t
index 30bc303f..1ed279db 100755
--- a/tests/request.t
+++ b/tests/request.t
@@ -8,7 +8,7 @@ BEGIN {
use strict;
use IO::Socket;
-use Test::More tests => 181;
+use Test::More tests => 179;
use LightyTest;
my $tf = LightyTest->new();
@@ -1407,23 +1407,6 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => 'http://www.example.org/' } ];
ok($tf->handle_http($t) == 0, 'broken header via perl cgi');
-$t->{REQUEST} = ( <<EOF
-GET /indexfile/ HTTP/1.0
-Host: cgi.example.org
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '/indexfile/index.pl' } ];
-ok($tf->handle_http($t) == 0, 'index-file handling, Bug #3, Bug #6');
-
-$t->{REQUEST} = ( <<EOF
-POST /indexfile/abc HTTP/1.0
-Host: cgi.example.org
-Content-Length: 0
-EOF
- );
-$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => '/indexfile/index.pl' } ];
-ok($tf->handle_http($t) == 0, 'server.error-handler-404, Bug #12');
-
## mod_deflate