create t/test_mod_evhost to test mod_evhost basic logic remove tests/mod-evhost.tpersonal/stbuehler/fix-fdevent
parent
5299bded32
commit
8aad091613
@ -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;
|
||||
}
|
@ -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 = ("")
|
||||
}
|
@ -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");
|
||||
|
Loading…
Reference in new issue