Run sudo tests also if user is root

This commit is contained in:
benrubson 2017-08-26 11:50:01 +02:00
parent 03d0ae793e
commit c7cea40ddc
2 changed files with 18 additions and 5 deletions

View File

@ -29,6 +29,7 @@ tests will run almost instantly:
Integration tests will take ~20 seconds to run and will mount an Integration tests will take ~20 seconds to run and will mount an
encrypted filesystem and run tests on it: encrypted filesystem and run tests on it:
*running integration tests from root (or with sudo) will run additional ones*
make integration make integration

View File

@ -34,6 +34,7 @@ if(system("which lsextattr > /dev/null 2>&1") == 0)
$setattr = "setextattr -h user encfs hello"; $setattr = "setextattr -h user encfs hello";
$getattr = "getextattr -h user encfs"; $getattr = "getextattr -h user encfs";
} }
# Do we support xattr ? # Do we support xattr ?
my $have_xattr = 1; my $have_xattr = 1;
if(system("./build/encfs --verbose --version 2>&1 | grep -q HAVE_XATTR") != 0) if(system("./build/encfs --verbose --version 2>&1 | grep -q HAVE_XATTR") != 0)
@ -41,6 +42,17 @@ if(system("./build/encfs --verbose --version 2>&1 | grep -q HAVE_XATTR") != 0)
$have_xattr = 0; $have_xattr = 0;
} }
# Did we ask, or are we simply able to run "sudo" tests ?
my $sudo_cmd;
if (! $<)
{
$sudo_cmd="";
}
elsif (defined($ENV{'SUDO_TESTS'}))
{
$sudo_cmd="sudo";
}
# test filesystem in standard config mode # test filesystem in standard config mode
&runTests('standard'); &runTests('standard');
@ -443,8 +455,8 @@ sub checkReadError
# Test that write errors are correctly thrown up to us # Test that write errors are correctly thrown up to us
sub checkWriteError sub checkWriteError
{ {
# No OSX impl, and requires sudo which is inconvenient outside of CI. # No OSX impl (for now, feel free to find how to), and requires "sudo".
if($^O eq "darwin" || !defined($ENV{'SUDO_TESTS'})) { if($^O eq "darwin" || !defined($sudo_cmd)) {
ok(1, "write error"); ok(1, "write error");
ok(1, "write error"); ok(1, "write error");
ok(1, "write error"); ok(1, "write error");
@ -455,7 +467,7 @@ sub checkWriteError
my $mnt = "$workingDir/checkWriteError.mnt"; my $mnt = "$workingDir/checkWriteError.mnt";
mkdir($crypt) || BAIL_OUT($!); mkdir($crypt) || BAIL_OUT($!);
mkdir($mnt) || BAIL_OUT($!); mkdir($mnt) || BAIL_OUT($!);
system("sudo mount -t tmpfs -o size=1m tmpfs $crypt"); system("$sudo_cmd mount -t tmpfs -o size=1m tmpfs $crypt");
ok( $? == 0, "mount command returns 0") || return; ok( $? == 0, "mount command returns 0") || return;
system("./build/encfs --standard --extpass=\"echo test\" $crypt $mnt 2>&1"); system("./build/encfs --standard --extpass=\"echo test\" $crypt $mnt 2>&1");
ok( $? == 0, "encfs command returns 0") || return; ok( $? == 0, "encfs command returns 0") || return;
@ -464,6 +476,6 @@ sub checkWriteError
ok ($!{ENOSPC}, "write returned $! instead of ENOSPC"); ok ($!{ENOSPC}, "write returned $! instead of ENOSPC");
close OUT; close OUT;
portable_unmount($mnt); portable_unmount($mnt);
system("sudo umount $crypt"); system("$sudo_cmd umount $crypt");
} }
} }