normal.t.pl (encfs-1.9.4) | : | normal.t.pl (encfs-1.9.5) | ||
---|---|---|---|---|
#!/usr/bin/perl -w | #!/usr/bin/perl -w | |||
# Test EncFS normal and paranoid mode | # Test EncFS normal and paranoid mode | |||
use Test::More tests => 132; | use Test::More tests => 136; | |||
use File::Path; | use File::Path; | |||
use File::Copy; | use File::Copy; | |||
use File::Temp; | use File::Temp; | |||
use IO::Handle; | use IO::Handle; | |||
require("integration/common.pl"); | require("integration/common.pl"); | |||
my $tempDir = $ENV{'TMPDIR'} || "/tmp"; | my $tempDir = $ENV{'TMPDIR'} || "/tmp"; | |||
if($^O eq "linux" and $tempDir eq "/tmp") { | if($^O eq "linux" and $tempDir eq "/tmp") { | |||
skipping to change at line 110 | skipping to change at line 110 | |||
# Helper function | # Helper function | |||
# Create a new empty working directory | # Create a new empty working directory | |||
sub newWorkingDir | sub newWorkingDir | |||
{ | { | |||
our $workingDir = mkdtemp("$tempDir/encfs-tests-XXXX") | our $workingDir = mkdtemp("$tempDir/encfs-tests-XXXX") | |||
|| BAIL_OUT("Could not create temporary directory"); | || BAIL_OUT("Could not create temporary directory"); | |||
our $raw = "$workingDir/raw"; | our $raw = "$workingDir/raw"; | |||
our $crypt = "$workingDir/crypt"; | our $crypt = "$workingDir/crypt"; | |||
if ($^O eq "cygwin") | ||||
{ | ||||
$crypt = "/cygdrive/x"; | ||||
} | ||||
} | } | |||
# Test Corruption | # Test Corruption | |||
# Modify the encrypted file and verify that the MAC check detects it | # Modify the encrypted file and verify that the MAC check detects it | |||
sub corruption | sub corruption | |||
{ | { | |||
ok( open(OUT, "+> $crypt/corrupt") && print(OUT "12345678901234567890") | ok( open(OUT, "+> $crypt/corrupt") && print(OUT "12345678901234567890") | |||
&& close(OUT), "create corruption-test file" ); | && close(OUT), "create corruption-test file" ); | |||
$e = encName("corrupt"); | $e = encName("corrupt"); | |||
ok( open(OUT, ">> $raw/$e") && print(OUT "garbage") && close(OUT), | ok( open(OUT, ">> $raw/$e") && print(OUT "garbage") && close(OUT), | |||
"corrupting raw file"); | "corrupting raw file"); | |||
ok( open(IN, "< $crypt/corrupt"), "open corrupted file"); | ok( open(IN, "< $crypt/corrupt"), "open corrupted file"); | |||
my $content; | my $content; | |||
$result = read(IN, $content, 20); | $result = read(IN, $content, 20); | |||
ok($!{EBADMSG} && (! defined $result), "corrupted file with MAC returns read | # Cygwin returns EINVAL for now | |||
error: $!"); | ok(($!{EBADMSG} || $!{EINVAL}) && (! defined $result), "corrupted file with | |||
MAC returns read error: $!"); | ||||
} | } | |||
# Test internal modification | # Test internal modification | |||
# Create a file of fixed size and overwrite data at different offsets | # Create a file of fixed size and overwrite data at different offsets | |||
# (like a database would do) | # (like a database would do) | |||
sub internalModification | sub internalModification | |||
{ | { | |||
$ofile = "$workingDir/crypt-internal-$$"; | $ofile = "$workingDir/crypt-internal-$$"; | |||
writeZeroes($ofile, 2*1024); | writeZeroes($ofile, 2*1024); | |||
ok(copy($ofile, "$crypt/internal"), "copying crypt-internal file"); | ok(copy($ofile, "$crypt/internal"), "copying crypt-internal file"); | |||
skipping to change at line 237 | skipping to change at line 242 | |||
truncate(OUT, 35); | truncate(OUT, 35); | |||
is( md5fh(*OUT), "5f170cc34b1944d75d86cc01496292df", | is( md5fh(*OUT), "5f170cc34b1944d75d86cc01496292df", | |||
"content digest"); | "content digest"); | |||
close OUT; | close OUT; | |||
} | } | |||
# Test file creation and removal | # Test file creation and removal | |||
sub fileCreation | sub fileCreation | |||
{ | { | |||
# first be sure .encfs6.xml does not show up | ||||
my $f = encName(".encfs6.xml"); | ||||
cmp_ok( length($f), '>', 8, "encrypted name ok" ); | ||||
ok( ! -f "$raw/$f", "configuration file .encfs6.xml not visible in $raw" ); | ||||
# create a file | # create a file | |||
qx(date > "$crypt/df.txt"); | qx(date > "$crypt/df.txt"); | |||
ok( -f "$crypt/df.txt", "file created" ) || BAIL_OUT("file create failed"); | ok( -f "$crypt/df.txt", "file created" ) || BAIL_OUT("file create failed"); | |||
# ensure there is an encrypted version. | # ensure there is an encrypted version. | |||
my $c = encName("df.txt"); | my $c = encName("df.txt"); | |||
cmp_ok( length($c), '>', 8, "encrypted name ok" ); | cmp_ok( length($c), '>', 8, "encrypted name ok" ); | |||
ok( -f "$raw/$c", "encrypted file $raw/$c created" ); | ok( -f "$raw/$c", "encrypted file $raw/$c created" ); | |||
# check contents | # check contents | |||
skipping to change at line 321 | skipping to change at line 331 | |||
my $enc = qx(./build/encfsctl encode --extpass="echo test" $raw $plain); | my $enc = qx(./build/encfsctl encode --extpass="echo test" $raw $plain); | |||
chomp($enc); | chomp($enc); | |||
return $enc; | return $enc; | |||
} | } | |||
# Test symlinks & hardlinks, and extended attributes | # Test symlinks & hardlinks, and extended attributes | |||
sub links | sub links | |||
{ | { | |||
my $hardlinkTests = shift; | my $hardlinkTests = shift; | |||
my $contents = "hello world\n"; | my $contents = "hello world"; | |||
ok( open(OUT, "> $crypt/data"), "create file for link test" ); | ok( open(OUT, "> $crypt/data"), "create file for link test" ); | |||
print OUT $contents; | print OUT $contents; | |||
close OUT; | close OUT; | |||
# symlinks | # symlinks | |||
ok( symlink("$crypt/data", "$crypt/data-fqn") , "fqn symlink"); | ok( symlink("$crypt/data", "$crypt/data-fqn") , "fqn symlink"); | |||
checkContents("$crypt/data-fqn", $contents, "fqn link traversal"); | checkContents("$crypt/data-fqn", $contents, "fqn link traversal"); | |||
is( readlink("$crypt/data-fqn"), "$crypt/data", "read fqn symlink"); | is( readlink("$crypt/data-fqn"), "$crypt/data", "read fqn symlink"); | |||
ok( symlink("data", "$crypt/data-rel"), "local symlink"); | ok( symlink("data", "$crypt/data-rel"), "local symlink"); | |||
skipping to change at line 360 | skipping to change at line 370 | |||
} | } | |||
# Test mount | # Test mount | |||
# Leaves the filesystem mounted - also used as a helper function | # Leaves the filesystem mounted - also used as a helper function | |||
sub mount | sub mount | |||
{ | { | |||
my $args = shift; | my $args = shift; | |||
# When these fail, the rest of the tests makes no sense | # When these fail, the rest of the tests makes no sense | |||
mkdir($raw) || BAIL_OUT("Could not create $raw: $!"); | mkdir($raw) || BAIL_OUT("Could not create $raw: $!"); | |||
mkdir($crypt) || BAIL_OUT("Could not create $crypt: $!"); | if ($^O ne "cygwin") | |||
{ | ||||
mkdir($crypt) || BAIL_OUT("Could not create $crypt: $!"); | ||||
} | ||||
delete $ENV{"ENCFS6_CONFIG"}; | delete $ENV{"ENCFS6_CONFIG"}; | |||
remount($args); | remount($args); | |||
ok( $? == 0, "encfs command returns 0") || BAIL_OUT(""); | ok( $? == 0, "encfs command returns 0") || BAIL_OUT(""); | |||
ok( -f "$raw/.encfs6.xml", "created control file") || BAIL_OUT(""); | ok( -f "$raw/.encfs6.xml", "created control file") || BAIL_OUT(""); | |||
} | } | |||
# Helper function | # Helper function | |||
# Mount without any prior checks | # Mount without any prior checks | |||
sub remount | sub remount | |||
skipping to change at line 422 | skipping to change at line 435 | |||
} | } | |||
system("cat $raw/.encfs6.xml.orig > $raw/.encfs6.xml"); | system("cat $raw/.encfs6.xml.orig > $raw/.encfs6.xml"); | |||
waitpid($child, 0); | waitpid($child, 0); | |||
ok( 0 == $?, "encfs mount with named pipe based config failed"); | ok( 0 == $?, "encfs mount with named pipe based config failed"); | |||
} | } | |||
sub create_unmount_remount | sub create_unmount_remount | |||
{ | { | |||
my $crypt = "$workingDir/create_remount.crypt"; | my $crypt = "$workingDir/create_remount.crypt"; | |||
my $mnt = "$workingDir/create_remount.mnt"; | my $mnt = "$workingDir/create_remount.mnt"; | |||
if ($^O eq "cygwin") | ||||
{ | ||||
$mnt = "/cygdrive/y"; | ||||
} | ||||
mkdir($crypt) || BAIL_OUT($!); | mkdir($crypt) || BAIL_OUT($!); | |||
mkdir($mnt) || BAIL_OUT($!); | if ($^O ne "cygwin") | |||
{ | ||||
mkdir($mnt) || BAIL_OUT($!); | ||||
} | ||||
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; | |||
ok( -f "$crypt/.encfs6.xml", "created control file") || return; | ok( -f "$crypt/.encfs6.xml", "created control file") || return; | |||
# Write some text | # Write some text | |||
my $contents = "hello world\n"; | my $contents = "hello world\n"; | |||
ok( open(OUT, "> $mnt/test_file_1"), "write content"); | ok( open(OUT, "> $mnt/test_file_1"), "write content"); | |||
print OUT $contents; | print OUT $contents; | |||
close OUT; | close OUT; | |||
# Unmount | # Unmount | |||
portable_unmount($mnt); | portable_unmount($mnt); | |||
# Mount again | # Mount again, testing -c at the same time | |||
system("./build/encfs --extpass=\"echo test\" $crypt $mnt 2>&1"); | rename("$crypt/.encfs6.xml", "$crypt/.encfs6_moved.xml"); | |||
system("./build/encfs -c $crypt/.encfs6_moved.xml --extpass=\"echo test\" $c | ||||
rypt $mnt 2>&1"); | ||||
ok( $? == 0, "encfs command returns 0") || return; | ok( $? == 0, "encfs command returns 0") || return; | |||
# Check if content is still there | # Check if content is still there | |||
checkContents("$mnt/test_file_1", $contents); | checkContents("$mnt/test_file_1", $contents); | |||
portable_unmount($mnt); | portable_unmount($mnt); | |||
} | } | |||
# Test that read errors are correctly thrown up to us | # Test that read errors are correctly thrown up to us | |||
sub checkReadError | sub checkReadError | |||
skipping to change at line 468 | skipping to change at line 489 | |||
# No OSX impl (for now, feel free to find how to), and requires "sudo". | # No OSX impl (for now, feel free to find how to), and requires "sudo". | |||
if($^O eq "darwin" || !defined($sudo_cmd)) { | 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"); | |||
ok(1, "write error"); | ok(1, "write error"); | |||
} | } | |||
else { | else { | |||
my $crypt = "$workingDir/checkWriteError.crypt"; | my $crypt = "$workingDir/checkWriteError.crypt"; | |||
my $mnt = "$workingDir/checkWriteError.mnt"; | my $mnt = "$workingDir/checkWriteError.mnt"; | |||
if ($^O eq "cygwin") | ||||
{ | ||||
$mnt = "/cygdrive/z"; | ||||
} | ||||
mkdir($crypt) || BAIL_OUT($!); | mkdir($crypt) || BAIL_OUT($!); | |||
mkdir($mnt) || BAIL_OUT($!); | if ($^O ne "cygwin") | |||
{ | ||||
mkdir($mnt) || BAIL_OUT($!); | ||||
} | ||||
system("$sudo_cmd 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; | |||
ok(open(OUT , "> $mnt/file"), "write content"); | ok(open(OUT , "> $mnt/file"), "write content"); | |||
while(print OUT "0123456789") {} | while(print OUT "0123456789") {} | |||
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_cmd umount $crypt"); | system("$sudo_cmd umount $crypt"); | |||
End of changes. 11 change blocks. | ||||
9 lines changed or deleted | 38 lines changed or added |