Mercurial > hg > nginx-tests
comparison http_disable_symlinks.t @ 202:067b6cb4793d
Tests: cleanup disable_symlinks tests.
In particular, make it correcly skip tests if run under symbolic link.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 13 Feb 2012 23:53:23 +0400 |
parents | fc297a64142e |
children | b6a4770e47ea |
comparison
equal
deleted
inserted
replaced
201:fc297a64142e | 202:067b6cb4793d |
---|---|
9 use warnings; | 9 use warnings; |
10 use strict; | 10 use strict; |
11 | 11 |
12 use Test::More; | 12 use Test::More; |
13 use POSIX; | 13 use POSIX; |
14 use Cwd qw/ realpath /; | |
14 | 15 |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | 16 BEGIN { use FindBin; chdir($FindBin::Bin); } |
16 | 17 |
17 use lib 'lib'; | 18 use lib 'lib'; |
18 use Test::Nginx; | 19 use Test::Nginx; |
110 open STDERR, ">&", \*OLDERR; | 111 open STDERR, ">&", \*OLDERR; |
111 }; | 112 }; |
112 plan(skip_all => 'no disable_symlinks') if $@; | 113 plan(skip_all => 'no disable_symlinks') if $@; |
113 | 114 |
114 my $uid = getuid(); | 115 my $uid = getuid(); |
115 | 116 my ($extfile) = grep { -f "$_" && $uid != (stat($_))[4] } |
116 my @extfiles = ('/etc/resolv.conf', '/etc/protocols', '/etc/host.conf'); | 117 ('/etc/resolv.conf', '/etc/protocols', '/etc/host.conf'); |
117 my $extfile = undef; | 118 |
118 | 119 plan(skip_all => 'no external file found') |
119 foreach (@extfiles) { | 120 if !defined $extfile; |
120 if (-f "$_" && $uid != (stat($_))[4]) { | |
121 $extfile = $_; | |
122 last; | |
123 } | |
124 } | |
125 | |
126 if (defined($extfile)) { | |
127 $t->plan(17); | |
128 } else { | |
129 plan(skip_all => 'external suitable object not found'); | |
130 } | |
131 | 121 |
132 my $d = $t->testdir(); | 122 my $d = $t->testdir(); |
123 | |
124 plan(skip_all => 'cannot test under symlink') | |
125 if $d ne realpath($d); | |
126 | |
127 $t->plan(17); | |
133 | 128 |
134 mkdir("$d/on"); | 129 mkdir("$d/on"); |
135 mkdir("$d/not_owner"); | 130 mkdir("$d/not_owner"); |
136 mkdir("$d/try_on"); | 131 mkdir("$d/try_on"); |
137 mkdir("$d/try_not_owner"); | 132 mkdir("$d/try_not_owner"); |
197 'if (if_not_owner, same uid)'); | 192 'if (if_not_owner, same uid)'); |
198 like(http_get_host('s1', '/if_not_owner/link2'), qr!403 Forbidden!, | 193 like(http_get_host('s1', '/if_not_owner/link2'), qr!403 Forbidden!, |
199 'if (if_not_owner, other uid)'); | 194 'if (if_not_owner, other uid)'); |
200 | 195 |
201 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!, | 196 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!, |
202 'open_file_cache (pass #1)'); | 197 'open_file_cache (pass 1)'); |
203 like(http_get_host('s2', '/cached-on/link'), qr!403 Forbidden!, | 198 like(http_get_host('s2', '/cached-on/link'), qr!403 Forbidden!, |
204 'open_file_cache (pass #2)'); | 199 'open_file_cache (pass 2)'); |
205 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!, | 200 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!, |
206 'open_file_cache (pass #3)'); | 201 'open_file_cache (pass 3)'); |
207 like(http_get_host('s2', '/cached-if-not-owner/link'), qr!403 Forbidden!, | 202 like(http_get_host('s2', '/cached-if-not-owner/link'), qr!403 Forbidden!, |
208 'open_file_cache (pass #4)'); | 203 'open_file_cache (pass 4)'); |
209 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!, | 204 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!, |
210 'open_file_cache (pass #5)'); | 205 'open_file_cache (pass 5)'); |
211 | 206 |
212 ############################################################################### | 207 ############################################################################### |
213 | 208 |
214 sub http_get_host { | 209 sub http_get_host { |
215 my ($host, $url) = @_; | 210 my ($host, $url) = @_; |