reverse.t.pl (encfs-1.9.4) | : | reverse.t.pl (encfs-1.9.5) | ||
---|---|---|---|---|
#!/usr/bin/perl -w | #!/usr/bin/perl -w | |||
# Test EncFS --reverse mode | # Test EncFS --reverse mode | |||
use warnings; | use warnings; | |||
use Test::More tests => 31; | use Test::More tests => 46; | |||
use File::Path; | use File::Path; | |||
use File::Temp; | use File::Temp; | |||
use IO::Handle; | use IO::Handle; | |||
use Errno qw(EROFS); | use Errno qw(EROFS); | |||
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 52 | skipping to change at line 52 | |||
# 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-reverse-tests-XXXX") | our $workingDir = mkdtemp("$tempDir/encfs-reverse-tests-XXXX") | |||
|| BAIL_OUT("Could not create temporary directory"); | || BAIL_OUT("Could not create temporary directory"); | |||
our $plain = "$workingDir/plain"; | our $plain = "$workingDir/plain"; | |||
mkdir($plain); | mkdir($plain); | |||
our $ciphertext = "$workingDir/ciphertext"; | our $ciphertext = "$workingDir/ciphertext"; | |||
mkdir($ciphertext); | if ($^O ne "cygwin") | |||
{ | ||||
mkdir($ciphertext); | ||||
} | ||||
else | ||||
{ | ||||
$ciphertext = "/cygdrive/x"; | ||||
} | ||||
our $decrypted = "$workingDir/decrypted"; | our $decrypted = "$workingDir/decrypted"; | |||
mkdir($decrypted); | if ($^O ne "cygwin") | |||
{ | ||||
mkdir($decrypted); | ||||
} | ||||
else | ||||
{ | ||||
$decrypted = "/cygdrive/y"; | ||||
} | ||||
} | } | |||
# Helper function | # Helper function | |||
# Unmount and delete mountpoint | # Unmount and delete mountpoint | |||
sub cleanup | sub cleanup | |||
{ | { | |||
portable_unmount($decrypted); | portable_unmount($decrypted); | |||
portable_unmount($ciphertext); | portable_unmount($ciphertext); | |||
our $workingDir; | our $workingDir; | |||
rmtree($workingDir); | rmtree($workingDir); | |||
skipping to change at line 79 | skipping to change at line 93 | |||
# Mount encryption-decryption chain | # Mount encryption-decryption chain | |||
# | # | |||
# Directory structure: plain -[encrypt]-> ciphertext -[decrypt]-> decrypted | # Directory structure: plain -[encrypt]-> ciphertext -[decrypt]-> decrypted | |||
sub mount | sub mount | |||
{ | { | |||
delete $ENV{"ENCFS6_CONFIG"}; | delete $ENV{"ENCFS6_CONFIG"}; | |||
system("./build/encfs --extpass=\"echo test\" --standard $plain $ciphertext --reverse --nocache"); | system("./build/encfs --extpass=\"echo test\" --standard $plain $ciphertext --reverse --nocache"); | |||
ok(waitForFile("$plain/.encfs6.xml"), "plain .encfs6.xml exists") or BAIL_OU T("'$plain/.encfs6.xml'"); | ok(waitForFile("$plain/.encfs6.xml"), "plain .encfs6.xml exists") or BAIL_OU T("'$plain/.encfs6.xml'"); | |||
my $e = encName(".encfs6.xml"); | my $e = encName(".encfs6.xml"); | |||
ok(waitForFile("$ciphertext/$e"), "encrypted .encfs6.xml exists") or BAIL_OU T("'$ciphertext/$e'"); | ok(waitForFile("$ciphertext/$e"), "encrypted .encfs6.xml exists") or BAIL_OU T("'$ciphertext/$e'"); | |||
system("ENCFS6_CONFIG=$plain/.encfs6.xml ./build/encfs --nocache --extpass=\ "echo test\" $ciphertext $decrypted"); | system("ENCFS6_CONFIG=$plain/.encfs6.xml ./build/encfs --noattrcache --nodat acache --extpass=\"echo test\" $ciphertext $decrypted"); | |||
ok(waitForFile("$decrypted/.encfs6.xml"), "decrypted .encfs6.xml exists") or BAIL_OUT("'$decrypted/.encfs6.xml'"); | ok(waitForFile("$decrypted/.encfs6.xml"), "decrypted .encfs6.xml exists") or BAIL_OUT("'$decrypted/.encfs6.xml'"); | |||
} | } | |||
# Helper function | # Helper function | |||
# | # | |||
# Get encrypted name for file | # Get encrypted name for file | |||
sub encName | sub encName | |||
{ | { | |||
my $name = shift; | my $name = shift; | |||
my $enc = qx(ENCFS6_CONFIG=$plain/.encfs6.xml ./build/encfsctl encode --e xtpass="echo test" $ciphertext $name); | my $enc = qx(ENCFS6_CONFIG=$plain/.encfs6.xml ./build/encfsctl encode --e xtpass="echo test" $ciphertext $name); | |||
chomp($enc); | chomp($enc); | |||
return $enc; | return $enc; | |||
} | } | |||
# Copy a directory tree and verify that the decrypted data is identical | # Copy a directory tree and verify that the decrypted data is identical, we also create a foo/.encfs6.xml file, to be sure it correctly shows-up | |||
sub copy_test | sub copy_test | |||
{ | { | |||
ok(system("cp -a encfs $plain")==0, "copying files to plain"); | # first be sure .encfs6.xml does not show up | |||
ok(system("diff -r -q $plain $decrypted")==0, "decrypted files are identical | # We does not use -f for this test, as it would succeed, .encfs6.xml is only | |||
"); | hidden from readdir. | |||
my $f = encName(".encfs6.xml"); | ||||
cmp_ok( length($f), '>', 8, "encrypted name ok" ); | ||||
ok(system("ls -1 $ciphertext | grep -qwF -- $f") != 0, "configuration file . | ||||
encfs6.xml not visible in $ciphertext"); | ||||
# copy test | ||||
ok(system("cp -a encfs $plain && mkdir $plain/foo && touch $plain/foo/.encfs | ||||
6.xml")==0, "copying files to plain"); | ||||
ok(system("diff -r -q --exclude='.encfs6.xml' $plain $decrypted")==0, "decry | ||||
pted files are identical"); | ||||
ok(-f "$plain/encfs/encfs.cpp", "file exists"); | ok(-f "$plain/encfs/encfs.cpp", "file exists"); | |||
unlink("$plain/encfs/encfs.cpp"); | unlink("$plain/encfs/encfs.cpp"); | |||
ok(! -f "$decrypted/encfs.cpp", "file deleted"); | ok(! -f "$decrypted/encfs.cpp", "file deleted"); | |||
} | } | |||
# Encfsctl cat test | ||||
sub encfsctl_cat_test | ||||
{ | ||||
my $contents = "hello world\n"; | ||||
ok(open(OUT, "> $plain/hello.txt"), "create file for encfsctl cat test"); | ||||
print OUT $contents; | ||||
close OUT; | ||||
qx(ENCFS6_CONFIG=$plain/.encfs6.xml ./build/encfsctl cat --extpass="echo tes | ||||
t" $ciphertext hello.txt > $plain/hellodec.txt); | ||||
qx(ENCFS6_CONFIG=$plain/.encfs6.xml ./build/encfsctl cat --extpass="echo tes | ||||
t" --reverse $plain hello.txt > $plain/helloenc.txt); | ||||
my $cname = encName("hello.txt"); | ||||
ok(system("diff -q $plain/helloenc.txt $ciphertext/$cname")==0, "encfsctl co | ||||
rrectly encrypts"); | ||||
ok(system("diff -q $plain/hello.txt $plain/hellodec.txt")==0, "encfsctl corr | ||||
ectly decrypts"); | ||||
} | ||||
# Create symlinks and verify they are correctly decrypted | # Create symlinks and verify they are correctly decrypted | |||
# Parameter: symlink target | # Parameter: symlink target | |||
sub symlink_test | sub symlink_test | |||
{ | { | |||
my $target = shift; | my $target = shift; | |||
symlink($target, "$plain/symlink"); | ok(symlink($target, "$plain/symlink"), "Symlink create, $plain/symlink -> $t | |||
$dec = readlink("$decrypted/symlink"); | arget"); | |||
ok( $dec eq $target, "symlink to '$target'") or | ok(my $dec = readlink("$decrypted/symlink"), "Symlink read, $decrypted/symli | |||
print("# (original) $target' != '$dec' (decrypted)\n"); | nk -> $target"); | |||
$dec.=""; | ||||
ok($dec eq $target, "Symlink compare, '$target' != '$dec'"); | ||||
my $return_code = ($have_xattr) ? system(@binattr, "$decrypted/symlink") : 0 ; | my $return_code = ($have_xattr) ? system(@binattr, "$decrypted/symlink") : 0 ; | |||
is($return_code, 0, "symlink to '$target' extended attributes can be read (r eturn code was $return_code)"); | is($return_code, 0, "Symlink xattr, $plain/symlink -> $target, extended attr ibutes can be read (return code was $return_code)"); | |||
unlink("$plain/symlink"); | unlink("$plain/symlink"); | |||
} | } | |||
# Grow a file from 0 to x kB and | # Grow a file from 0 to x kB and | |||
# * check the ciphertext length is correct (stat + read) | # * check the ciphertext length is correct (stat + read) | |||
# * check that the decrypted length is correct (stat + read) | # * check that the decrypted length is correct (stat + read) | |||
# * check that plaintext and decrypted are identical | # * check that plaintext and decrypted are identical | |||
sub grow { | sub grow { | |||
# pfh ... plaintext file handle | # pfh ... plaintext file handle | |||
open(my $pfh, ">", "$plain/grow"); | open(my $pfh, ">", "$plain/grow"); | |||
skipping to change at line 210 | skipping to change at line 244 | |||
} | } | |||
# Setup mounts | # Setup mounts | |||
newWorkingDir(); | newWorkingDir(); | |||
mount(); | mount(); | |||
# Actual tests | # Actual tests | |||
grow(); | grow(); | |||
largeRead(); | largeRead(); | |||
copy_test(); | copy_test(); | |||
encfsctl_cat_test(); | ||||
symlink_test("/"); # absolute | symlink_test("/"); # absolute | |||
symlink_test("foo"); # relative | symlink_test("foo"); # relative | |||
symlink_test("/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/15/17/18"); # long | symlink_test("/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/15/17/18"); # long | |||
symlink_test("!§\$%&/()\\<>#+="); # special characters | if ($^O ne "cygwin") | |||
{ | ||||
symlink_test("!§\$%&/()\\<>#+="); # special characters | ||||
} | ||||
else | ||||
{ | ||||
symlink_test("!§\$%&/()//<>#+="); # special characters but without \ which i | ||||
s not Windows compliant | ||||
} # Absolute symlinks may failed on Windows | ||||
: https://github.com/billziss-gh/winfsp/issues/153 | ||||
symlink_test("$plain/foo"); | symlink_test("$plain/foo"); | |||
writesDenied(); | writesDenied(); | |||
# Umount and delete files | # Umount and delete files | |||
cleanup(); | cleanup(); | |||
End of changes. 11 change blocks. | ||||
14 lines changed or deleted | 67 lines changed or added |