From adbddf1f9e5fb73b64056a92e44500dfe52bb669 Mon Sep 17 00:00:00 2001 From: benrubson Date: Tue, 4 Jul 2017 08:25:52 +0200 Subject: [PATCH] Add extended attributes tests --- encfs/main.cpp | 5 ++++- tests/normal.t.pl | 35 +++++++++++++++++++++++++++++++++-- tests/reverse.t.pl | 9 +++++++-- 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/encfs/main.cpp b/encfs/main.cpp index 28e2f1c..cf58815 100644 --- a/encfs/main.cpp +++ b/encfs/main.cpp @@ -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; @@ -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': diff --git a/tests/normal.t.pl b/tests/normal.t.pl index 1f2d7f8..7a61eb3 100755 --- a/tests/normal.t.pl +++ b/tests/normal.t.pl @@ -2,7 +2,7 @@ # Test EncFS normal and paranoid mode -use Test::More tests => 106; +use Test::More tests => 112; use File::Path; use File::Copy; use File::Temp; @@ -12,6 +12,29 @@ require("tests/common.pl"); 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 &runTests('standard'); @@ -268,7 +291,7 @@ sub encName return $enc; } -# Test symlinks & hardlinks +# Test symlinks & hardlinks, and extended attributes sub links { my $hardlinkTests = shift; @@ -293,6 +316,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 diff --git a/tests/reverse.t.pl b/tests/reverse.t.pl index 66ff36e..d870a41 100755 --- a/tests/reverse.t.pl +++ b/tests/reverse.t.pl @@ -26,6 +26,12 @@ if(system("which lsextattr > /dev/null 2>&1") == 0) # 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 @@ -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"); }