Add extended attributes tests

This commit is contained in:
benrubson 2017-07-04 08:25:52 +02:00
parent 97d1b83d71
commit adbddf1f9e
3 changed files with 44 additions and 5 deletions

View File

@ -245,7 +245,7 @@ static bool processArgs(int argc, char *argv[],
// 'o' : arguments meant for fuse // 'o' : arguments meant for fuse
// 't' : syslog tag // 't' : syslog tag
int res = int res =
getopt_long(argc, argv, "HsSfvdmi:o:t:", long_options, &option_index); getopt_long(argc, argv, "HsSfvdmi:o:t:V", long_options, &option_index);
if (res == -1) break; if (res == -1) break;
@ -355,6 +355,9 @@ static bool processArgs(int argc, char *argv[],
case 'V': case 'V':
// xgroup(usage) // xgroup(usage)
cerr << autosprintf(_("encfs version %s"), VERSION) << endl; cerr << autosprintf(_("encfs version %s"), VERSION) << endl;
#if defined(HAVE_XATTR)
cerr << "Compiled with : HAVE_XATTR" << endl;
#endif
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;
case 'H': case 'H':

View File

@ -2,7 +2,7 @@
# Test EncFS normal and paranoid mode # Test EncFS normal and paranoid mode
use Test::More tests => 106; use Test::More tests => 112;
use File::Path; use File::Path;
use File::Copy; use File::Copy;
use File::Temp; use File::Temp;
@ -12,6 +12,29 @@ require("tests/common.pl");
my $tempDir = $ENV{'TMPDIR'} || "/tmp"; my $tempDir = $ENV{'TMPDIR'} || "/tmp";
# Find attr binary
# Linux
my @setattr = ("attr", "-s", "encfs", "-V", "hello");
my @getattr = ("attr", "-g", "encfs");
if(system("which xattr > /dev/null 2>&1") == 0)
{
# Mac OS X
@setattr = ("xattr", "-sw", "encfs", "hello");
@getattr = ("xattr", "-sp", "encfs");
}
if(system("which lsextattr > /dev/null 2>&1") == 0)
{
# FreeBSD
@setattr = ("setextattr", "-h", "user", "encfs", "hello");
@getattr = ("getextattr", "-h", "user", "encfs");
}
# Do we support xattr ?
my $have_xattr = 1;
if(system("./build/encfs -V 2>&1 | grep -q HAVE_XATTR") != 0)
{
$have_xattr = 0;
}
# test filesystem in standard config mode # test filesystem in standard config mode
&runTests('standard'); &runTests('standard');
@ -268,7 +291,7 @@ sub encName
return $enc; return $enc;
} }
# Test symlinks & hardlinks # Test symlinks & hardlinks, and extended attributes
sub links sub links
{ {
my $hardlinkTests = shift; my $hardlinkTests = shift;
@ -293,6 +316,14 @@ sub links
ok( link("$crypt/data", "$crypt/data.2"), "hard link"); ok( link("$crypt/data", "$crypt/data.2"), "hard link");
checkContents("$crypt/data.2", $contents, "hardlink read"); checkContents("$crypt/data.2", $contents, "hardlink read");
}; };
# extended attributes
my $return_code = ($have_xattr) ? system(@setattr, "$crypt/data") : 0;
is($return_code, 0, "extended attributes can be set (return code was $return_code)");
$return_code = ($have_xattr) ? system(@getattr, "$crypt/data") : 0;
is($return_code, 0, "extended attributes can be get (return code was $return_code)");
$return_code = ($have_xattr) ? system(@getattr, "$crypt/data-rel") : 1;
isnt($return_code, 0, "extended attributes operations do not follow symlinks (return code was $return_code)");
} }
# Test mount # Test mount

View File

@ -26,6 +26,12 @@ if(system("which lsextattr > /dev/null 2>&1") == 0)
# FreeBSD # FreeBSD
@binattr = ("lsextattr", "-h", "user"); @binattr = ("lsextattr", "-h", "user");
} }
# Do we support xattr ?
my $have_xattr = 1;
if(system("./build/encfs -V 2>&1 | grep -q HAVE_XATTR") != 0)
{
$have_xattr = 0;
}
# Helper function # Helper function
# Create a new empty working directory # Create a new empty working directory
@ -98,8 +104,7 @@ sub symlink_test
$dec = readlink("$decrypted/symlink"); $dec = readlink("$decrypted/symlink");
ok( $dec eq $target, "symlink to '$target'") or ok( $dec eq $target, "symlink to '$target'") or
print("# (original) $target' != '$dec' (decrypted)\n"); print("# (original) $target' != '$dec' (decrypted)\n");
system(@binattr, "$decrypted/symlink"); my $return_code = ($have_xattr) ? system(@binattr, "$decrypted/symlink") : 0;
my $return_code = $?;
is($return_code, 0, "symlink to '$target' extended attributes can be read (return code was $return_code)"); is($return_code, 0, "symlink to '$target' extended attributes can be read (return code was $return_code)");
unlink("$plain/symlink"); unlink("$plain/symlink");
} }