2013-06-13 16:58:23 +04:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
|
|
|
# Test script for the ownCloud module of csync.
|
|
|
|
# This script requires a running ownCloud instance accessible via HTTP.
|
|
|
|
# It does quite some fancy tests and asserts the results.
|
|
|
|
#
|
|
|
|
# Copyright (C) by Olivier Goffart <ogoffart@woboq.com>
|
|
|
|
#
|
2014-02-24 14:08:58 +04:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
#
|
2013-06-13 16:58:23 +04:00
|
|
|
|
|
|
|
use lib ".";
|
|
|
|
|
2014-08-28 20:06:47 +04:00
|
|
|
|
2013-06-13 16:58:23 +04:00
|
|
|
use File::Copy;
|
|
|
|
use ownCloud::Test;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2013-07-26 14:37:54 +04:00
|
|
|
print "Hello, this is t4, a tester for A) files that cannot be stated and B) excluded files\n";
|
2013-06-13 16:58:23 +04:00
|
|
|
# stat error occours on windsows when the file is busy for example
|
|
|
|
|
|
|
|
initTesting();
|
|
|
|
|
2013-11-14 21:20:57 +04:00
|
|
|
printInfo( "Copy some files to the remote location" );
|
2013-06-13 16:58:23 +04:00
|
|
|
mkdir( localDir() . 'test_stat' );
|
|
|
|
system( "echo foobar > " . localDir() . 'test_stat/file.txt' );
|
|
|
|
|
2014-08-28 21:33:52 +04:00
|
|
|
mkdir( localDir() . 'test_ignored' );
|
|
|
|
mkdir( localDir() . 'test_ignored/sub' );
|
|
|
|
system( "echo foobarfoo > " . localDir() . 'test_ignored/sub/file.txt' );
|
|
|
|
|
2013-06-13 16:58:23 +04:00
|
|
|
# call csync, sync local t1 to remote t1
|
|
|
|
csync();
|
|
|
|
|
|
|
|
# Check if the files from toremote1 are now in t1/remoteToLocal1
|
|
|
|
# they should have taken the way via the ownCloud.
|
|
|
|
print "Assert the local file copy\n";
|
2013-07-26 14:37:54 +04:00
|
|
|
assertLocalAndRemoteDir( '', 0 );
|
2013-06-13 16:58:23 +04:00
|
|
|
|
|
|
|
|
2013-11-14 21:20:57 +04:00
|
|
|
printInfo( "Make a file not statable" );
|
|
|
|
|
|
|
|
|
2013-06-13 16:58:23 +04:00
|
|
|
system( "echo foobar2 >> " . localDir() . 'test_stat/file.txt' );
|
2013-11-14 21:20:57 +04:00
|
|
|
#make the file not statable by changing the directory right
|
|
|
|
system( "chmod 400 " . localDir() . 'test_stat' );
|
2013-06-13 16:58:23 +04:00
|
|
|
|
|
|
|
|
|
|
|
csync();
|
|
|
|
|
|
|
|
# TODO: some check here.
|
|
|
|
|
2013-07-26 14:37:54 +04:00
|
|
|
|
2013-11-14 21:20:57 +04:00
|
|
|
|
|
|
|
printInfo("Add a file in a read only directory");
|
|
|
|
|
|
|
|
system( "echo \"Hello World\" >> /tmp/kernelcrash.txt" );
|
|
|
|
put_to_dir( '/tmp/kernelcrash.txt', 'test_stat' );
|
|
|
|
|
|
|
|
csync();
|
|
|
|
|
|
|
|
assert( ! -e localDir().'test_stat/kernelcrash' );
|
|
|
|
|
|
|
|
|
|
|
|
printInfo("Restore the original rights");
|
2013-07-26 14:37:54 +04:00
|
|
|
|
2013-06-13 16:58:23 +04:00
|
|
|
system( "chmod 700 " . localDir() . 'test_stat' );
|
|
|
|
system( "echo foobar3 >> " . localDir() . 'test_stat/file.txt' );
|
|
|
|
|
|
|
|
csync();
|
|
|
|
|
|
|
|
print "Check if everything is still the same\n";
|
|
|
|
|
2013-07-26 14:37:54 +04:00
|
|
|
assertLocalAndRemoteDir( '', 0 );
|
2013-06-13 16:58:23 +04:00
|
|
|
|
|
|
|
# TODO: Check that the file content is fine on the server and that there was no conflict
|
2013-11-14 21:20:57 +04:00
|
|
|
assert( -e localDir().'test_stat/file.txt' );
|
|
|
|
assert( -e localDir().'test_stat/kernelcrash.txt' );
|
|
|
|
|
|
|
|
my $localMD5 = md5OfFile( localDir().'test_stat/kernelcrash.txt' );
|
|
|
|
my $realMD5 = md5OfFile( '/tmp/kernelcrash.txt' );
|
|
|
|
print "MD5 compare $localMD5 <-> $realMD5\n";
|
|
|
|
assert( $localMD5 eq $realMD5 );
|
2013-06-13 16:58:23 +04:00
|
|
|
|
2013-11-14 21:20:57 +04:00
|
|
|
printInfo("Added a file that is on the ignore list");
|
2013-07-26 14:37:54 +04:00
|
|
|
# (*.directory is in the ignored list that needs cleanup)
|
|
|
|
# (it is names with _conflict) because i want the conflicft detection of assertLocalAndRemoteDir to work
|
|
|
|
system( "echo dir >> " . localDir() . 'test_stat/file_conflict.directory' );
|
2014-08-28 21:33:52 +04:00
|
|
|
# this one should retain the directory
|
|
|
|
system( "echo foobarfoo > " . localDir() . 'test_ignored/sub/ignored_conflict.part' );
|
2013-07-26 14:37:54 +04:00
|
|
|
csync();
|
|
|
|
# The file_conflict.directory is seen as a conflict
|
|
|
|
assertLocalAndRemoteDir( '', 1 );
|
|
|
|
# TODO: check that the file_conflict.directory is indeed NOT on the server
|
2014-08-28 21:33:52 +04:00
|
|
|
# TODO: check that test_ignored/sub/ignored_conflict.part is NOT on the server
|
|
|
|
assert(-e localDir() . 'test_ignored/sub/ignored_conflict.part');
|
|
|
|
|
|
|
|
printInfo("Remove a directory containing an ignored file that should not be removed\n");
|
|
|
|
remoteCleanup('test_ignored');
|
|
|
|
csync();
|
|
|
|
assert(-e localDir() . 'test_ignored/sub/ignored_conflict.part');
|
|
|
|
#remove the file so next sync allow the directory to be removed
|
|
|
|
system( "rm " . localDir() . 'test_ignored/sub/ignored_conflict.part' );
|
2013-07-26 14:37:54 +04:00
|
|
|
|
2013-11-14 21:20:57 +04:00
|
|
|
printInfo("Remove a directory containing a local file\n");
|
2013-07-26 14:37:54 +04:00
|
|
|
remoteCleanup('test_stat');
|
2014-01-08 16:18:59 +04:00
|
|
|
|
|
|
|
#Add an executable file for next test
|
|
|
|
system( "echo echo hello >> " . localDir() . 'echo.sh' );
|
|
|
|
chmod 0751, localDir() . 'echo.sh';
|
|
|
|
|
2014-04-03 19:42:08 +04:00
|
|
|
#and add a file in anotherdir for the next test
|
|
|
|
mkdir( localDir() . 'anotherdir' );
|
|
|
|
mkdir( localDir() . 'anotherdir/sub' );
|
|
|
|
system( "echo foobar > " . localDir() . 'anotherdir/file1.txt' );
|
|
|
|
system( "echo foobar > " . localDir() . 'anotherdir/sub/file2.txt' );
|
|
|
|
|
2013-07-26 14:37:54 +04:00
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( '', 0 );
|
|
|
|
|
2014-01-08 16:18:59 +04:00
|
|
|
open(my $fh, "<", localDir() . 'echo.sh');
|
|
|
|
my $perm = (stat $fh)[2] & 07777;
|
|
|
|
assert( $perm eq 0751, "permissions not kept" );
|
|
|
|
|
2013-07-26 14:37:54 +04:00
|
|
|
|
2014-01-08 16:18:59 +04:00
|
|
|
printInfo("Modify a file in the remote and check its permission\n");
|
|
|
|
system( "echo \"echo bonjour\" > /tmp/echo.sh" );
|
|
|
|
put_to_dir( '/tmp/echo.sh', "" );
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( '', 0 );
|
2013-07-26 14:37:54 +04:00
|
|
|
|
2014-01-08 16:18:59 +04:00
|
|
|
open(my $fh, "<", localDir() . 'echo.sh');
|
|
|
|
my $perm = (stat $fh)[2] & 07777;
|
|
|
|
assert( $perm eq 0751, "permissions not kept" );
|
2013-11-14 21:20:57 +04:00
|
|
|
|
2014-04-03 19:42:08 +04:00
|
|
|
printInfo("Remove a directory and make it a symlink instead\n");
|
|
|
|
system( "rm -rf " . localDir() . 'anotherdir' );
|
|
|
|
system( "ln -s /bin " . localDir() . 'anotherdir' );
|
|
|
|
# remember the fileid of the file on the server
|
|
|
|
my $oldfileid1 = remoteFileId( 'anotherdir/', 'file1.txt' );
|
|
|
|
my $oldfileid2 = remoteFileId( 'anotherdir/sub', 'file2.txt' );
|
|
|
|
csync();
|
|
|
|
|
|
|
|
#check that the files in ignored directory has NOT been removed
|
|
|
|
my $newfileid1 = remoteFileId( 'anotherdir/', 'file1.txt' );
|
|
|
|
my $newfileid2 = remoteFileId( 'anotherdir/sub', 'file2.txt' );
|
|
|
|
assert( $oldfileid1 eq $newfileid1, "File removed (file1.txt)" );
|
|
|
|
assert( $oldfileid2 eq $newfileid2, "File removed (file2.txt)" );
|
|
|
|
|
|
|
|
printInfo("Now remove the symlink\n");
|
|
|
|
system( "rm -f " . localDir() . 'anotherdir' );
|
|
|
|
csync();
|
|
|
|
assertLocalAndRemoteDir( '', 0 );
|
2014-08-28 21:33:52 +04:00
|
|
|
assert(! -e localDir(). 'anotherdir' );
|
|
|
|
|
2013-11-14 21:20:57 +04:00
|
|
|
|
2013-06-13 16:58:23 +04:00
|
|
|
cleanup();
|
|
|
|
|
|
|
|
# --
|