changeset 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
files http_disable_symlinks.t
diffstat 1 files changed, 15 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/http_disable_symlinks.t
+++ b/http_disable_symlinks.t
@@ -11,6 +11,7 @@ use strict;
 
 use Test::More;
 use POSIX;
+use Cwd qw/ realpath /;
 
 BEGIN { use FindBin; chdir($FindBin::Bin); }
 
@@ -112,25 +113,19 @@ eval {
 plan(skip_all => 'no disable_symlinks') if $@;
 
 my $uid = getuid();
-
-my @extfiles = ('/etc/resolv.conf', '/etc/protocols', '/etc/host.conf');
-my $extfile = undef;
+my ($extfile) = grep { -f "$_" && $uid != (stat($_))[4] }
+	('/etc/resolv.conf', '/etc/protocols', '/etc/host.conf');
 
-foreach (@extfiles) {
-	if (-f "$_" && $uid != (stat($_))[4]) {
-		$extfile = $_;
-		last;
-	}
-}
-
-if (defined($extfile)) {
-	$t->plan(17);
-} else {
-	plan(skip_all => 'external suitable object not found');
-}
+plan(skip_all => 'no external file found')
+	if !defined $extfile;
 
 my $d = $t->testdir();
 
+plan(skip_all => 'cannot test under symlink')
+	if $d ne realpath($d);
+
+$t->plan(17);
+
 mkdir("$d/on");
 mkdir("$d/not_owner");
 mkdir("$d/try_on");
@@ -199,15 +194,15 @@ like(http_get_host('s1', '/if_not_owner/
 	'if (if_not_owner, other uid)');
 
 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!,
-	'open_file_cache (pass #1)');
+	'open_file_cache (pass 1)');
 like(http_get_host('s2', '/cached-on/link'), qr!403 Forbidden!,
-	'open_file_cache (pass #2)');
+	'open_file_cache (pass 2)');
 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!,
-	'open_file_cache (pass #3)');
+	'open_file_cache (pass 3)');
 like(http_get_host('s2', '/cached-if-not-owner/link'), qr!403 Forbidden!,
-	'open_file_cache (pass #4)');
+	'open_file_cache (pass 4)');
 like(http_get_host('s2', '/cached-off/link'), qr!200 OK!,
-	'open_file_cache (pass #5)');
+	'open_file_cache (pass 5)');
 
 ###############################################################################