[build_cmake] clock_gettime() -lrt w/ glibc < 2.17 (fixes #2737)
[lighttpd.git] / tests / symlink.t
blob9b275bd75eb1d30e1cc294b6de72eaf2b6b4f47d
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;
9 use strict;
10 use IO::Socket;
11 use Test::More tests => 10;
12 use LightyTest;
14 my $tf = LightyTest->new();
15 my $t;
16 my $docroot = $tf->{'TESTDIR'}."/tmp/lighttpd/servers/www.example.org/pages";
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);
26 $f = "$docroot/expire";
27 $l = "$docroot/symlinked";
28 $rc = undef;
29 unless (-l $l) {
30 return 0 unless symlink($f,$l);
32 return 1;
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();
39 # allow case
40 # simple file
41 $t->{REQUEST} = ( <<EOF
42 GET /index.html HTTP/1.0
43 Host: symlink.example.org
44 EOF
46 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
47 ok($tf->handle_http($t) == 0, 'allow: simple file');
49 # symlinked file
50 $t->{REQUEST} = ( <<EOF
51 GET /index.xhtml HTTP/1.0
52 Host: symlink.example.org
53 EOF
55 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
56 ok($tf->handle_http($t) == 0, 'allow: symlinked file');
58 # directly symlinked dir
59 $t->{REQUEST} = ( <<EOF
60 GET /symlinked/ HTTP/1.0
61 Host: symlink.example.org
62 EOF
64 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
65 ok($tf->handle_http($t) == 0, 'allow: directly symlinked dir');
67 # symlinked dir in path
68 $t->{REQUEST} = ( <<EOF
69 GET /symlinked/access.txt HTTP/1.0
70 Host: symlink.example.org
71 EOF
73 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
74 ok($tf->handle_http($t) == 0, 'allow: symlinked dir in path');
76 # deny case
77 # simple file
78 $t->{REQUEST} = ( <<EOF
79 GET /index.html HTTP/1.0
80 Host: nosymlink.example.org
81 EOF
83 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
84 ok($tf->handle_http($t) == 0, 'deny: simple file');
86 # symlinked file
87 $t->{REQUEST} = ( <<EOF
88 GET /index.xhtml HTTP/1.0
89 Host: nosymlink.example.org
90 EOF
92 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
93 ok($tf->handle_http($t) == 0, 'deny: symlinked file');
95 # directly symlinked dir
96 $t->{REQUEST} = ( <<EOF
97 GET /symlinked/ HTTP/1.0
98 Host: nosymlink.example.org
99 EOF
101 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
102 ok($tf->handle_http($t) == 0, 'deny: directly symlinked dir');
104 # symlinked dir in path
105 $t->{REQUEST} = ( <<EOF
106 GET /symlinked/access.txt HTTP/1.0
107 Host: nosymlink.example.org
110 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 403 } ];
111 ok($tf->handle_http($t) == 0, 'deny: symlinked dir in path');
113 # cleanup
114 ok($tf->stop_proc == 0, "Stopping lighttpd");