Skip to content

Commit

Permalink
Add extended attributes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benrubson authored and rfjakob committed Jul 29, 2017
1 parent c425bf9 commit 9a169bf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
5 changes: 4 additions & 1 deletion encfs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static bool processArgs(int argc, char *argv[],
// 'o' : arguments meant for fuse
// 't' : syslog tag
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;

Expand Down Expand Up @@ -355,6 +355,9 @@ static bool processArgs(int argc, char *argv[],
case 'V':
// xgroup(usage)
cerr << autosprintf(_("encfs version %s"), VERSION) << endl;
#if defined(HAVE_XATTR)
cerr << "Compiled with : HAVE_XATTR" << endl;
#endif
exit(EXIT_SUCCESS);
break;
case 'H':
Expand Down
41 changes: 39 additions & 2 deletions tests/normal.t.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Test EncFS normal and paranoid mode

use Test::More tests => 116;
use Test::More tests => 122;
use File::Path;
use File::Copy;
use File::Temp;
Expand All @@ -12,6 +12,35 @@

my $tempDir = $ENV{'TMPDIR'} || "/tmp";

if($^O eq "linux" and $tempDir eq "/tmp") {
# On Linux, /tmp is often a tmpfs mount that does not support
# extended attributes. Use /var/tmp instead.
$tempDir = "/var/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
&runTests('standard');

Expand Down Expand Up @@ -270,7 +299,7 @@ sub encName
return $enc;
}

# Test symlinks & hardlinks
# Test symlinks & hardlinks, and extended attributes
sub links
{
my $hardlinkTests = shift;
Expand All @@ -295,6 +324,14 @@ sub links
ok( link("$crypt/data", "$crypt/data.2"), "hard link");
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
Expand Down
9 changes: 7 additions & 2 deletions tests/reverse.t.pl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
# FreeBSD
@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
# Create a new empty working directory
Expand Down Expand Up @@ -98,8 +104,7 @@ sub symlink_test
$dec = readlink("$decrypted/symlink");
ok( $dec eq $target, "symlink to '$target'") or
print("# (original) $target' != '$dec' (decrypted)\n");
system(@binattr, "$decrypted/symlink");
my $return_code = $?;
my $return_code = ($have_xattr) ? system(@binattr, "$decrypted/symlink") : 0;
is($return_code, 0, "symlink to '$target' extended attributes can be read (return code was $return_code)");
unlink("$plain/symlink");
}
Expand Down

0 comments on commit 9a169bf

Please sign in to comment.