Check if test_rehash is run as root
authorRichard Levitte <levitte@openssl.org>
Fri, 18 Sep 2015 19:27:29 +0000 (21:27 +0200)
committerRichard Levitte <levitte@openssl.org>
Fri, 18 Sep 2015 19:32:29 +0000 (21:32 +0200)
If test/recipes/40-test_rehash.t is executed as root, the last test
will fail, since the created directory will remain writable no matter
what.  Make sure it complains loudly about being run as root.

Reviewed-by: Rich Salz <rsalz@openssl.org>
test/recipes/40-test_rehash.t

index 514d0d3df3bc7241f06bed771f46659fba0b9429..4f0d71fbd25decb4ea7afad4e2f26acdd6592cce 100644 (file)
@@ -10,7 +10,7 @@ use OpenSSL::Test qw/:DEFAULT top_file/;
 
 setup("test_rehash");
 
 
 setup("test_rehash");
 
-plan tests => 4;
+plan tests => 5;
 
 indir "rehash.$$" => sub {
     prepare();
 
 indir "rehash.$$" => sub {
     prepare();
@@ -32,8 +32,15 @@ indir "rehash.$$" => sub {
 indir "rehash.$$" => sub {
     prepare();
     chmod 0500, curdir();
 indir "rehash.$$" => sub {
     prepare();
     chmod 0500, curdir();
-    isnt(run(app(["openssl", "rehash", curdir()])), 1,
-         'Testing rehash operations on readonly directory');
+  SKIP: {
+      if (!ok(!open(FOO, ">unwritable.txt"),
+              "Testing that we aren't running as a priviledged user, such as root")) {
+          close FOO;
+          skip "It's pointless to run the next test as root", 1;
+      }
+      isnt(run(app(["openssl", "rehash", curdir()])), 1,
+           'Testing rehash operations on readonly directory');
+    }
     chmod 0700, curdir();       # make it writable again, so cleanup works
 }, create => 1, cleanup => 1;
 
     chmod 0700, curdir();       # make it writable again, so cleanup works
 }, create => 1, cleanup => 1;