create t/test_keyvalue to replace sparse tests in tests/mod-redirect.t and tests/mod-rewrite.t remove tests/mod-redirect.t and tests/mod-rewrite.tpersonal/stbuehler/fix-fdevent
parent
dd11144bc8
commit
f03e5e239d
@ -0,0 +1,124 @@
|
||||
#include "first.h"
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> /* STDERR_FILENO */
|
||||
|
||||
#include "keyvalue.c"
|
||||
|
||||
#ifdef HAVE_PCRE_H
|
||||
static pcre_keyvalue_buffer * test_keyvalue_test_kvb_init (void) {
|
||||
pcre_keyvalue_buffer *kvb = pcre_keyvalue_buffer_init();
|
||||
buffer *k = buffer_init();
|
||||
buffer *v = buffer_init();
|
||||
server srv;
|
||||
|
||||
memset(&srv, 0, sizeof(srv));
|
||||
srv.errorlog_fd = STDERR_FILENO;
|
||||
srv.errorlog_mode = ERRORLOG_FD;
|
||||
srv.errorlog_buf = buffer_init();
|
||||
|
||||
buffer_copy_string_len(k, CONST_STR_LEN("^/foo($|\\?.+)"));
|
||||
buffer_copy_string_len(v, CONST_STR_LEN("/foo/$1"));
|
||||
assert(0 == pcre_keyvalue_buffer_append(&srv, kvb, k, v));
|
||||
buffer_copy_string_len(k, CONST_STR_LEN("^/bar(?:$|\\?(.+))"));
|
||||
buffer_copy_string_len(v, CONST_STR_LEN("/?bar&$1"));
|
||||
assert(0 == pcre_keyvalue_buffer_append(&srv, kvb, k, v));
|
||||
buffer_copy_string_len(k, CONST_STR_LEN("^/redirect(?:\\?(.*))?$"));
|
||||
buffer_copy_string_len(v, CONST_STR_LEN("/?seg=%1&$1"));
|
||||
assert(0 == pcre_keyvalue_buffer_append(&srv, kvb, k, v));
|
||||
buffer_copy_string_len(k, CONST_STR_LEN("^(/[^?]*)(?:\\?(.*))?$"));
|
||||
buffer_copy_string_len(v, CONST_STR_LEN("/?file=$1&$2"));
|
||||
assert(0 == pcre_keyvalue_buffer_append(&srv, kvb, k, v));
|
||||
|
||||
buffer_free(k);
|
||||
buffer_free(v);
|
||||
buffer_free(srv.errorlog_buf);
|
||||
|
||||
return kvb;
|
||||
}
|
||||
|
||||
static void test_keyvalue_pcre_keyvalue_buffer_process (void) {
|
||||
pcre_keyvalue_buffer *kvb = test_keyvalue_test_kvb_init();
|
||||
buffer *url = buffer_init();
|
||||
buffer *result = buffer_init();
|
||||
struct burl_parts_t burl;
|
||||
cond_cache_t cache;
|
||||
pcre_keyvalue_ctx ctx;
|
||||
handler_t rc;
|
||||
|
||||
ctx.burl = &burl;
|
||||
burl.scheme = buffer_init();
|
||||
burl.authority = buffer_init();
|
||||
burl.port = 80;
|
||||
burl.path = buffer_init();
|
||||
burl.query = buffer_init();
|
||||
buffer_copy_string_len(burl.scheme, CONST_STR_LEN("http"));
|
||||
buffer_copy_string_len(burl.authority, CONST_STR_LEN("www.example.com"));
|
||||
/* model outer conditional match of $HTTP["host"] =~ "^(www).example.com$" */
|
||||
ctx.cache = &cache;
|
||||
memset(&cache, 0, sizeof(cache));
|
||||
cache.patterncount = 2;
|
||||
cache.comp_value = burl.authority;
|
||||
cache.matches[0] = 0;
|
||||
cache.matches[1] = 15;
|
||||
cache.matches[2] = 0;
|
||||
cache.matches[3] = 3;
|
||||
|
||||
/* converted from prior sparse tests/mod-redirect.t and tests/mod-rewrite.t
|
||||
* (real-world use should prefer ${url.path} and ${qsa} in substitutions)
|
||||
*/
|
||||
|
||||
buffer_copy_string_len(url, CONST_STR_LEN("/foo"));
|
||||
buffer_copy_string_len(burl.path, CONST_STR_LEN("/foo"));
|
||||
buffer_clear(burl.query);
|
||||
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
|
||||
assert(HANDLER_FINISHED == rc);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/foo/")));
|
||||
|
||||
buffer_copy_string_len(url, CONST_STR_LEN("/foo?a=b"));
|
||||
buffer_copy_string_len(burl.path, CONST_STR_LEN("/foo"));
|
||||
buffer_copy_string_len(burl.query, CONST_STR_LEN("a=b"));
|
||||
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
|
||||
assert(HANDLER_FINISHED == rc);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/foo/?a=b")));
|
||||
|
||||
buffer_copy_string_len(url, CONST_STR_LEN("/bar?a=b"));
|
||||
buffer_copy_string_len(burl.path, CONST_STR_LEN("/bar"));
|
||||
buffer_copy_string_len(burl.query, CONST_STR_LEN("a=b"));
|
||||
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
|
||||
assert(HANDLER_FINISHED == rc);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/?bar&a=b")));
|
||||
|
||||
buffer_copy_string_len(url, CONST_STR_LEN("/nofile?a=b"));
|
||||
buffer_copy_string_len(burl.path, CONST_STR_LEN("/nofile"));
|
||||
buffer_copy_string_len(burl.query, CONST_STR_LEN("a=b"));
|
||||
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
|
||||
assert(HANDLER_FINISHED == rc);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/?file=/nofile&a=b")));
|
||||
|
||||
buffer_copy_string_len(url, CONST_STR_LEN("/redirect?a=b"));
|
||||
buffer_copy_string_len(burl.path, CONST_STR_LEN("/redirect"));
|
||||
buffer_copy_string_len(burl.query, CONST_STR_LEN("a=b"));
|
||||
rc = pcre_keyvalue_buffer_process(kvb, &ctx, url, result);
|
||||
assert(HANDLER_FINISHED == rc);
|
||||
assert(buffer_is_equal_string(result, CONST_STR_LEN("/?seg=www&a=b")));
|
||||
|
||||
buffer_free(url);
|
||||
buffer_free(result);
|
||||
buffer_free(burl.scheme);
|
||||
buffer_free(burl.authority);
|
||||
buffer_free(burl.path);
|
||||
buffer_free(burl.query);
|
||||
pcre_keyvalue_buffer_free(kvb);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main (void) {
|
||||
#ifdef HAVE_PCRE_H
|
||||
test_keyvalue_pcre_keyvalue_buffer_process();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
@ -1,59 +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();
|
||||
my $t;
|
||||
|
||||
ok($tf->start_proc == 0, "Starting lighttpd") or die();
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /redirect/ HTTP/1.0
|
||||
Host: vvv.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/' } ];
|
||||
ok($tf->handle_http($t) == 0, 'external redirect');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /redirect/ HTTP/1.0
|
||||
Host: vvv.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/', 'Content-Length' => '0' } ];
|
||||
ok($tf->handle_http($t) == 0, 'external redirect should have a Content-Length: 0');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /redirect/ HTTP/1.0
|
||||
Host: zzz.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/zzz' } ];
|
||||
ok($tf->handle_http($t) == 0, 'external redirect with cond regsub');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /redirect/ HTTP/1.0
|
||||
Host: remoteip.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/127.0.0.1' } ];
|
||||
ok($tf->handle_http($t) == 0, 'external redirect with cond regsub on remoteip');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /redirect/ HTTP/1.0
|
||||
Host: remoteip2.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://localhost:'.$tf->{PORT}.'/remoteip2' } ];
|
||||
ok($tf->handle_http($t) == 0, 'external redirect with cond regsub on remoteip2');
|
||||
|
||||
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
@ -1,76 +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 => 8;
|
||||
use LightyTest;
|
||||
|
||||
my $tf = LightyTest->new();
|
||||
my $t;
|
||||
my $php_child = -1;
|
||||
|
||||
SKIP: {
|
||||
skip "PHP already running on port 1026", 1 if $tf->listening_on(1026);
|
||||
skip "no php binary found", 1 unless $LightyTest::HAVE_PHP;
|
||||
ok(-1 != ($php_child = $tf->spawnfcgi($ENV{'PHP'}, 1026)), "Spawning php");
|
||||
}
|
||||
|
||||
SKIP: {
|
||||
skip "no PHP running on port 1026", 6 unless $tf->listening_on(1026);
|
||||
|
||||
ok($tf->start_proc == 0, "Starting lighttpd") or goto cleanup;
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /rewrite/foo HTTP/1.0
|
||||
Host: www.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => '' } ];
|
||||
ok($tf->handle_http($t) == 0, 'valid request');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /rewrite/foo?a=b HTTP/1.0
|
||||
Host: www.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'a=b' } ];
|
||||
ok($tf->handle_http($t) == 0, 'valid request');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /rewrite/bar?a=b HTTP/1.0
|
||||
Host: www.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'bar&a=b' } ];
|
||||
ok($tf->handle_http($t) == 0, 'valid request');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /rewrite/nofile?a=b HTTP/1.0
|
||||
Host: www.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => 'file=/rewrite/nofile&a=b' } ];
|
||||
ok($tf->handle_http($t) == 0, 'not existing file rewrite');
|
||||
|
||||
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
||||
}
|
||||
|
||||
SKIP: {
|
||||
skip "PHP not started, cannot stop it", 1 unless $php_child != -1;
|
||||
ok(0 == $tf->endspawnfcgi($php_child), "Stopping php");
|
||||
}
|
||||
|
||||
|
||||
exit 0;
|
||||
|
||||
cleanup: ;
|
||||
|
||||
$tf->endspawnfcgi($php_child) if $php_child != -1;
|
||||
|
||||
die();
|
Loading…
Reference in new issue