mirror of
https://github.com/vgough/encfs.git
synced 2025-06-24 22:12:10 +02:00
tests: Move perl tests to tests/, make them callable from top-level Makefile
Use "make test" or "make test-verbose" to run. Note that "make test" seems to be more common than "make tests", hence the change. Also, use a new clean directory directory as a working area for each run Created using mkdtemp and deleted in cleanup()
This commit is contained in:
parent
38970c75bd
commit
0e8e1dd20c
@ -14,3 +14,11 @@ MAINTAINERCLEANFILES = aclocal.m4
|
|||||||
|
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test:
|
||||||
|
perl -MTest::Harness -e '$$Test::Harness::verbose=0; runtests @ARGV;' tests/*.pl
|
||||||
|
|
||||||
|
.PHONY: test-verbose
|
||||||
|
test-verbose:
|
||||||
|
perl -MTest::Harness -e '$$Test::Harness::verbose=1; runtests @ARGV;' tests/*.pl
|
||||||
|
@ -141,9 +141,3 @@ encfs-man.html: encfs.pod
|
|||||||
@POD2HTML@ encfs.pod > $@
|
@POD2HTML@ encfs.pod > $@
|
||||||
endif
|
endif
|
||||||
|
|
||||||
tests:
|
|
||||||
perl -MTest::Harness -e '$$Test::Harness::verbose=0; runtests @ARGV;' *.t
|
|
||||||
|
|
||||||
tests-verbose:
|
|
||||||
perl -MTest::Harness -e '$$Test::Harness::verbose=1; runtests @ARGV;' *.t
|
|
||||||
|
|
||||||
|
@ -3,26 +3,25 @@
|
|||||||
use Test::More qw( no_plan );
|
use Test::More qw( no_plan );
|
||||||
use File::Path;
|
use File::Path;
|
||||||
use File::Copy;
|
use File::Copy;
|
||||||
|
use File::Temp;
|
||||||
use IO::Handle;
|
use IO::Handle;
|
||||||
use Digest::MD5 qw(md5_hex);
|
use Digest::MD5 qw(md5_hex);
|
||||||
|
|
||||||
my $tempDir = $ENV{'TMPDIR'} || "/tmp";
|
my $tempDir = $ENV{'TMPDIR'} || "/tmp";
|
||||||
|
|
||||||
my $raw = "$tempDir/crypt-raw-$$";
|
|
||||||
my $crypt = "$tempDir/crypt-$$";
|
|
||||||
|
|
||||||
# test filesystem in standard config mode
|
# test filesystem in standard config mode
|
||||||
&runTests('standard');
|
&runTests('standard');
|
||||||
|
|
||||||
# test in paranoia mode
|
# test in paranoia mode
|
||||||
&runTests('paranoia');
|
&runTests('paranoia');
|
||||||
|
|
||||||
|
|
||||||
# Wrapper function - runs all tests in the specified mode
|
# Wrapper function - runs all tests in the specified mode
|
||||||
sub runTests
|
sub runTests
|
||||||
{
|
{
|
||||||
my $mode = shift;
|
my $mode = shift;
|
||||||
|
|
||||||
|
&newWorkingDir;
|
||||||
|
|
||||||
my $hardlinks = 1;
|
my $hardlinks = 1;
|
||||||
if($mode eq 'standard')
|
if($mode eq 'standard')
|
||||||
{
|
{
|
||||||
@ -48,6 +47,17 @@ sub runTests
|
|||||||
&cleanup;
|
&cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Helper function
|
||||||
|
# Create a new empty working directory
|
||||||
|
sub newWorkingDir
|
||||||
|
{
|
||||||
|
our $workingDir = mkdtemp("$tempDir/encfs-tests-XXXX")
|
||||||
|
|| BAIL_OUT("Could not create temporary directory");
|
||||||
|
|
||||||
|
our $raw = "$workingDir/raw";
|
||||||
|
our $crypt = "$workingDir/crypt";
|
||||||
|
}
|
||||||
|
|
||||||
# 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
|
||||||
@ -71,7 +81,7 @@ sub corruption
|
|||||||
# (like a database would do)
|
# (like a database would do)
|
||||||
sub internalModification
|
sub internalModification
|
||||||
{
|
{
|
||||||
$ofile = "$tempDir/crypt-internal-$$";
|
$ofile = "$workingDir/crypt-internal-$$";
|
||||||
qx(dd if=/dev/urandom of=$ofile bs=2k count=2 2> /dev/null);
|
qx(dd if=/dev/urandom of=$ofile bs=2k count=2 2> /dev/null);
|
||||||
ok(copy($ofile, "$crypt/internal"), "copying crypt-internal file");
|
ok(copy($ofile, "$crypt/internal"), "copying crypt-internal file");
|
||||||
|
|
||||||
@ -177,7 +187,7 @@ sub fileCreation
|
|||||||
# create a file
|
# create a file
|
||||||
qx(df -ah > "$crypt/df.txt");
|
qx(df -ah > "$crypt/df.txt");
|
||||||
ok( -f "$crypt/df.txt", "file created" );
|
ok( -f "$crypt/df.txt", "file created" );
|
||||||
|
|
||||||
# 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" );
|
||||||
@ -196,7 +206,7 @@ sub fileCreation
|
|||||||
sub grow
|
sub grow
|
||||||
{
|
{
|
||||||
open(my $fh_a, "+>$crypt/grow");
|
open(my $fh_a, "+>$crypt/grow");
|
||||||
open(my $fh_b, "+>$tempDir/grow");
|
open(my $fh_b, "+>$workingDir/grow");
|
||||||
|
|
||||||
my $d = "1234567"; # Length 7 so we are not aligned to the block size
|
my $d = "1234567"; # Length 7 so we are not aligned to the block size
|
||||||
my $len = 7;
|
my $len = 7;
|
||||||
@ -248,7 +258,7 @@ sub checkContents
|
|||||||
sub encName
|
sub encName
|
||||||
{
|
{
|
||||||
my $plain = shift;
|
my $plain = shift;
|
||||||
my $enc = qx(./encfsctl encode --extpass="echo test" $raw $plain);
|
my $enc = qx(./encfs/encfsctl encode --extpass="echo test" $raw $plain);
|
||||||
chomp($enc);
|
chomp($enc);
|
||||||
return $enc;
|
return $enc;
|
||||||
}
|
}
|
||||||
@ -285,7 +295,7 @@ sub links
|
|||||||
|
|
||||||
SKIP: {
|
SKIP: {
|
||||||
skip "No hardlink support" unless $hardlinkTests;
|
skip "No hardlink support" unless $hardlinkTests;
|
||||||
|
|
||||||
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");
|
||||||
};
|
};
|
||||||
@ -297,15 +307,11 @@ sub mount
|
|||||||
{
|
{
|
||||||
my $args = shift;
|
my $args = shift;
|
||||||
|
|
||||||
ok( ! -d $raw, "no existing dir");
|
# When these fail, the rest of the tests makes no sense
|
||||||
ok( ! -d $crypt, "no existing dir");
|
mkdir($raw) || BAIL_OUT("Could not create $raw: $!");
|
||||||
|
mkdir($crypt) || BAIL_OUT("Could not create $crypt: $!");
|
||||||
|
|
||||||
mkdir $raw;
|
qx(./encfs/encfs --extpass="echo test" $args $raw $crypt);
|
||||||
ok( -d $raw, "created dir" );
|
|
||||||
mkdir $crypt;
|
|
||||||
ok( -d $crypt, "created dir" );
|
|
||||||
|
|
||||||
qx(./encfs --extpass="echo test" $args $raw $crypt);
|
|
||||||
|
|
||||||
ok( -f "$raw/.encfs6.xml", "created control file");
|
ok( -f "$raw/.encfs6.xml", "created control file");
|
||||||
}
|
}
|
||||||
@ -327,10 +333,7 @@ sub cleanup
|
|||||||
rmdir $crypt;
|
rmdir $crypt;
|
||||||
ok( ! -d $crypt, "unmount ok, mount point removed");
|
ok( ! -d $crypt, "unmount ok, mount point removed");
|
||||||
|
|
||||||
if(-d $raw)
|
rmtree($workingDir);
|
||||||
{
|
ok( ! -d $workingDir, "working dir removed");
|
||||||
rmtree($raw);
|
|
||||||
}
|
|
||||||
ok( ! -d $raw, "encrypted directory removed");
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user