create t/test_mod_access to test mod_access basic logic remove tests/mod-access.tpersonal/stbuehler/fix-fdevent
parent
ddf95741b5
commit
5a32d0f72a
@ -0,0 +1,55 @@
|
||||
#include "first.h"
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mod_access.c"
|
||||
|
||||
static void test_mod_access_check(void) {
|
||||
array *allow = array_init();
|
||||
array *deny = array_init();
|
||||
buffer *urlpath = buffer_init();
|
||||
int lc = 0;
|
||||
|
||||
/* empty allow and deny lists */
|
||||
buffer_copy_string_len(urlpath, CONST_STR_LEN("/"));
|
||||
assert(1 == mod_access_check(allow, deny, urlpath, lc));
|
||||
|
||||
array_insert_value(deny, CONST_STR_LEN("~"));
|
||||
array_insert_value(deny, CONST_STR_LEN(".inc"));
|
||||
|
||||
/* deny */
|
||||
buffer_copy_string_len(urlpath, CONST_STR_LEN("/index.html~"));
|
||||
assert(0 == mod_access_check(allow, deny, urlpath, lc));
|
||||
lc = 1;
|
||||
buffer_copy_string_len(urlpath, CONST_STR_LEN("/index.INC"));
|
||||
assert(0 == mod_access_check(allow, deny, urlpath, lc));
|
||||
lc = 0;
|
||||
|
||||
array_insert_value(allow, CONST_STR_LEN(".txt"));
|
||||
array_insert_value(deny, CONST_STR_LEN(".txt"));/* allow takes precedence */
|
||||
|
||||
/* explicitly allowed */
|
||||
buffer_copy_string_len(urlpath, CONST_STR_LEN("/ssi-include.txt"));
|
||||
assert(1 == mod_access_check(allow, deny, urlpath, lc));
|
||||
lc = 1;
|
||||
buffer_copy_string_len(urlpath, CONST_STR_LEN("/ssi-include.TXT"));
|
||||
assert(1 == mod_access_check(allow, deny, urlpath, lc));
|
||||
lc = 0;
|
||||
|
||||
/* allow not empty and urlpath not explicitly allowed */
|
||||
buffer_copy_string_len(urlpath, CONST_STR_LEN("/cgi.pl"));
|
||||
assert(0 == mod_access_check(allow, deny, urlpath, lc));
|
||||
|
||||
array_free(allow);
|
||||
array_free(deny);
|
||||
buffer_free(urlpath);
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
test_mod_access_check();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,50 +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 => 6;
|
||||
use LightyTest;
|
||||
|
||||
my $tf = LightyTest->new();
|
||||
my $t;
|
||||
|
||||
ok($tf->start_proc == 0, "Starting lighttpd") or die();
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /index.html~ HTTP/1.0
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
||||
ok($tf->handle_http($t) == 0, 'forbid access to ...~');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /index.html~/ HTTP/1.0
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
||||
ok($tf->handle_http($t) == 0, '#1230 - forbid access to ...~ - trailing slash');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /ssi-include.txt HTTP/1.0
|
||||
Host: allow.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
|
||||
ok($tf->handle_http($t) == 0, 'explicitly allowed');
|
||||
|
||||
$t->{REQUEST} = ( <<EOF
|
||||
GET /cgi.pl HTTP/1.0
|
||||
Host: allow.example.org
|
||||
EOF
|
||||
);
|
||||
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
|
||||
ok($tf->handle_http($t) == 0, 'not explicitly allowed');
|
||||
|
||||
ok($tf->stop_proc == 0, "Stopping lighttpd");
|
||||
|
Loading…
Reference in new issue