Annotation of embedaddon/lighttpd/tests/symlink.t, revision 1.1.1.1

1.1       misho       1: #!/usr/bin/env perl
                      2: BEGIN {
                      3:        # add current source dir to the include-path
                      4:        # we need this for make distcheck
                      5:        (my $srcdir = $0) =~ s,/[^/]+$,/,;
                      6:        unshift @INC, $srcdir;
                      7: }
                      8: 
                      9: use strict;
                     10: use IO::Socket;
                     11: use Test::More tests => 10;
                     12: use LightyTest;
                     13: 
                     14: my $tf = LightyTest->new();
                     15: my $t;
                     16: my $docroot = $tf->{'TESTDIR'}."/tmp/lighttpd/servers/www.example.org/pages";
                     17: 
                     18: sub init_testbed {
                     19:     return 0 unless eval { symlink("",""); 1 };
                     20:     my $f = "$docroot/index.html";
                     21:     my $l = "$docroot/index.xhtml";
                     22:     my $rc = undef;
                     23:     unless (-l $l) {
                     24:         return 0 unless symlink($f,$l);
                     25:     };
                     26:     $f = "$docroot/expire";
                     27:     $l = "$docroot/symlinked";
                     28:     $rc = undef;
                     29:     unless (-l $l) {
                     30:         return 0 unless symlink($f,$l);
                     31:     }
                     32:     return 1;
                     33: };
                     34: 
                     35: SKIP: {
                     36:     skip "perl does not support symlinking or setting up the symlinks failed.", 10 unless init_testbed;
                     37:     ok($tf->start_proc == 0, "Starting lighttpd") or die();
                     38: 
                     39: # allow case
                     40: # simple file
                     41:        $t->{REQUEST} = ( <<EOF
                     42: GET /index.html HTTP/1.0
                     43: Host: symlink.example.org
                     44: EOF
                     45:  );
                     46:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     47:        ok($tf->handle_http($t) == 0, 'allow: simple file');
                     48: 
                     49: # symlinked file
                     50:        $t->{REQUEST} = ( <<EOF
                     51: GET /index.xhtml HTTP/1.0
                     52: Host: symlink.example.org
                     53: EOF
                     54:  );
                     55:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     56:        ok($tf->handle_http($t) == 0, 'allow: symlinked file');
                     57: 
                     58: # directly symlinked dir
                     59:        $t->{REQUEST} = ( <<EOF
                     60: GET /symlinked/ HTTP/1.0
                     61: Host: symlink.example.org
                     62: EOF
                     63:  );
                     64:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     65:        ok($tf->handle_http($t) == 0, 'allow: directly symlinked dir');
                     66: 
                     67: # symlinked dir in path
                     68:        $t->{REQUEST} = ( <<EOF
                     69: GET /symlinked/access.txt HTTP/1.0
                     70: Host: symlink.example.org
                     71: EOF
                     72:  );
                     73:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     74:        ok($tf->handle_http($t) == 0, 'allow: symlinked dir in path');
                     75: 
                     76: # deny case
                     77: # simple file
                     78:        $t->{REQUEST} = ( <<EOF
                     79: GET /index.html HTTP/1.0
                     80: Host: nosymlink.example.org
                     81: EOF
                     82:  );
                     83:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
                     84:        ok($tf->handle_http($t) == 0, 'deny: simple file');
                     85: 
                     86: # symlinked file
                     87:        $t->{REQUEST} = ( <<EOF
                     88: GET /index.xhtml HTTP/1.0
                     89: Host: nosymlink.example.org
                     90: EOF
                     91:  );
                     92:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
                     93:        ok($tf->handle_http($t) == 0, 'deny: symlinked file');
                     94: 
                     95: # directly symlinked dir
                     96:        $t->{REQUEST} = ( <<EOF
                     97: GET /symlinked/ HTTP/1.0
                     98: Host: nosymlink.example.org
                     99: EOF
                    100:  );
                    101:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
                    102:        ok($tf->handle_http($t) == 0, 'deny: directly symlinked dir');
                    103: 
                    104: # symlinked dir in path
                    105:        $t->{REQUEST} = ( <<EOF
                    106: GET /symlinked/access.txt HTTP/1.0
                    107: Host: nosymlink.example.org
                    108: EOF
                    109:  );
                    110:        $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
                    111:        ok($tf->handle_http($t) == 0, 'deny: symlinked dir in path');
                    112: 
                    113: # cleanup
                    114:     ok($tf->stop_proc == 0, "Stopping lighttpd");
                    115: };

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>