mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 21:35:47 +03:00
tests: Added test script to test the ownCloud module of csync.
The script t1.pl is a perl based check script for the ownCloud module of csync. It requires a running ownCloud server and does a couple of blackbox tests with it. See README for more information how to operate. Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
parent
871dde4911
commit
8e64584c12
8 changed files with 287 additions and 0 deletions
30
tests/ownCloud/README
Normal file
30
tests/ownCloud/README
Normal file
|
@ -0,0 +1,30 @@
|
|||
t1 - a test script for csync syncing to ownCloud.
|
||||
|
||||
t1 uses a perl WebDAV client lib to sync to an existing instance of
|
||||
ownCloud. For that, various files are copied around, synced and the
|
||||
results are tested through their existance, the filesize and the
|
||||
modification times. All tests are asserts, which means that the
|
||||
scripts stops if a test fails.
|
||||
|
||||
How to call:
|
||||
|
||||
First, configure the script. For that, open it in an editor and
|
||||
edit the values for the owncloud-url and the credentials. Yeah,
|
||||
this test script is not secure, make sure to run it with a weak
|
||||
account and in a save environment.
|
||||
|
||||
Further down, in sub csync, you can configure the LD_LIBRARY_PATH
|
||||
and the binary for csync. That allows to adopt the test script to
|
||||
local development environments. Make sure to check these.
|
||||
|
||||
To start the script, call ./t1.pl on the commandline. A lot of
|
||||
output is generated. If the script does not fail, everything works.
|
||||
|
||||
Before it actually ends, it takes a four seconds break for you to
|
||||
interrupt with Ctrl-C. If you don't do that, it removes all its
|
||||
traces...
|
||||
|
||||
Have fun,
|
||||
Klaas Freitag <freitag@owncloud.com>
|
||||
|
||||
|
240
tests/ownCloud/t1.pl
Executable file
240
tests/ownCloud/t1.pl
Executable file
|
@ -0,0 +1,240 @@
|
|||
#!/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 Klaas Freitag <freitag@owncloud.com>
|
||||
#
|
||||
|
||||
use Carp::Assert;
|
||||
use HTTP::DAV;
|
||||
use Data::Dumper;
|
||||
use File::Copy;
|
||||
|
||||
use strict;
|
||||
|
||||
print "Hello, this is t1, a tester for csync with ownCloud.\n";
|
||||
|
||||
#
|
||||
# Adjust data as needed here or better us a t1.cfg file with the following
|
||||
# content:
|
||||
# user => "joe",
|
||||
# passwd => "XXXXXX",
|
||||
# url => "http://localhost/oc/files/webdav.php"
|
||||
|
||||
my $owncloud = "http://localhost/oc/files/webdav.php/";
|
||||
my $user = "joe";
|
||||
my $passwd = 'XXXXX'; # Mind to be secure.
|
||||
|
||||
if( -r "./t1.cfg" ) {
|
||||
my %config = do 't1.cfg';
|
||||
$user = $config{user} if( $config{user} );
|
||||
$passwd = $config{passwd} if( $config{passwd} );
|
||||
$owncloud = $config{url} if( $config{url} );
|
||||
print "Read t1.cfg\n";
|
||||
}
|
||||
|
||||
$owncloud .= "/" unless( $owncloud =~ /\/$/ );
|
||||
|
||||
|
||||
print "Connecting to ownCloud at ". $owncloud ."\n";
|
||||
|
||||
|
||||
sub remoteDir( $$ )
|
||||
{
|
||||
my ($d, $dir) = @_;
|
||||
|
||||
my $url = $owncloud . $dir ;
|
||||
|
||||
$d->open( -url => $owncloud );
|
||||
print $d->message . "\n";
|
||||
|
||||
my $re = $d->mkcol( $url );
|
||||
if( $re == 0 ) {
|
||||
print "Failed to create directory <$dir>\n";
|
||||
}
|
||||
return $re;
|
||||
}
|
||||
|
||||
sub createLocalDir( $ )
|
||||
{
|
||||
my ($dir) = (@_);
|
||||
|
||||
mkdir( $dir, 0777 );
|
||||
}
|
||||
|
||||
sub remoteCleanup( $;$ )
|
||||
{
|
||||
my ($d, $dir) = @_;
|
||||
|
||||
$dir = "t1" unless $dir;
|
||||
my $url = $owncloud . $dir;
|
||||
$d->open( -url => $owncloud );
|
||||
|
||||
print "Cleaning Remote!\n";
|
||||
|
||||
my $re = $d->delete( $dir );
|
||||
|
||||
if( $re == 0 ) {
|
||||
print "Failed to clenup directory <$dir>\n";
|
||||
}
|
||||
return $re;
|
||||
}
|
||||
|
||||
sub localCleanup( $ )
|
||||
{
|
||||
my ($dir) = @_;
|
||||
# don't play child games here:
|
||||
system( "rm -rf $dir" );
|
||||
}
|
||||
|
||||
sub csync( $$ )
|
||||
{
|
||||
my ($local, $remote) = @_;
|
||||
|
||||
my $ld_libpath = "/home/kf/owncloud.com/buildcsync/modules";
|
||||
my $csync = "/home/kf/owncloud.com/buildcsync/client/csync";
|
||||
|
||||
my $url = $owncloud;
|
||||
$url =~ s#^http://##; # Remove the leading http://
|
||||
$url = "owncloud://$user:$passwd@". $url . $remote;
|
||||
print "CSync URL: $url\n";
|
||||
|
||||
my $cmd = "LD_LIBRARY_PATH=$ld_libpath $csync $local $url";
|
||||
print "Starting: $cmd\n";
|
||||
|
||||
system( $cmd );
|
||||
}
|
||||
|
||||
#
|
||||
# Check local directories if they have the same content.
|
||||
#
|
||||
sub assertLocalDirs( $$ )
|
||||
{
|
||||
my ($dir1, $dir2) = @_;
|
||||
print "Asserting $dir1 <-> $dir2\n";
|
||||
|
||||
opendir(my $dh, $dir1 ) || die;
|
||||
while(readdir $dh) {
|
||||
assert( -e "$dir2/$_" );
|
||||
|
||||
my $s1 = -s "$dir1/$_";
|
||||
my $s2 = -s "$dir2/$_";
|
||||
assert( $s1 == $s2 );
|
||||
}
|
||||
closedir $dh;
|
||||
}
|
||||
|
||||
#
|
||||
# Check if a local and a remote dir have the same content
|
||||
#
|
||||
sub assertLocalAndRemoteDir( $$$ )
|
||||
{
|
||||
my ($d, $local, $remote) = @_;
|
||||
my %seen;
|
||||
|
||||
if( my $r = $d->propfind( -url => $owncloud . $remote, -depth => 1 ) ) {
|
||||
if( $r->is_collection ) {
|
||||
print "\nXX" . $r->get_resourcelist->as_string ."\n";
|
||||
|
||||
foreach my $res ( $r->get_resourcelist->get_resources() ) {
|
||||
print "Checking " . $res-> get_uri()->as_string ."\n";
|
||||
my $filename = $res->get_property("rel_uri");
|
||||
# check if the file exists.
|
||||
assert( -e "$local/$filename" );
|
||||
|
||||
# check for equal mod times
|
||||
my $remoteModTime = $res->get_property( "lastmodifiedepoch" ) ;
|
||||
my @info = stat( "$local/$filename" );
|
||||
my $localModTime = $info[8];
|
||||
assert( $remoteModTime == $localModTime, "Modfied-Times differ: $remoteModTime <-> $localModTime" );
|
||||
|
||||
# check for the same file size
|
||||
my $localSize = $info[7];
|
||||
my $remoteSize = $res->get_property( "getcontentlength" );
|
||||
assert( $localSize == $remoteSize );
|
||||
|
||||
# remember the files seen on the server.
|
||||
$seen{$filename} = 1;
|
||||
}
|
||||
}
|
||||
# Now loop over the local directory content and check if all files in the dir
|
||||
# were seen on the server.
|
||||
|
||||
print "\n* Cross checking with local dir: \n";
|
||||
|
||||
opendir(my $dh, $local ) || die;
|
||||
while( readdir $dh ) {
|
||||
next if( /^\.+$/ );
|
||||
assert( -e "$local/$_" );
|
||||
assert( $seen{$_} == 1, "Filename only local, but not remte: $_\n" );
|
||||
}
|
||||
closedir $dh;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
# ====================================================================
|
||||
|
||||
my $d = HTTP::DAV->new();
|
||||
|
||||
|
||||
$d->credentials( -url=> $owncloud, -realm=>"ownCloud",
|
||||
-user=> $user,
|
||||
-pass=> $passwd );
|
||||
$d->DebugLevel(1);
|
||||
|
||||
my $remoteDir = "t1/";
|
||||
|
||||
remoteDir( $d, $remoteDir );
|
||||
|
||||
# $d->open("localhost/oc/files/webdav.php/t1");
|
||||
remoteDir( $d, $remoteDir . "remoteToLocal1" );
|
||||
|
||||
# put some files remote.
|
||||
$d->put( -local=>"toremote1/*", -url=> $owncloud . $remoteDir . "remoteToLocal1" );
|
||||
|
||||
#
|
||||
my $localDir = "./t1";
|
||||
|
||||
createLocalDir( $localDir );
|
||||
|
||||
# call csync, sync local t1 to remote t1
|
||||
csync( $localDir, $remoteDir );
|
||||
|
||||
print "\nNow assertions:\n";
|
||||
|
||||
# Check if the files from toremote1 are now in t1/remoteToLocal1
|
||||
# they should have taken the way via the oncCloud.
|
||||
assertLocalDirs( "./toremote1", "$localDir/remoteToLocal1" );
|
||||
|
||||
# Check if the synced files from ownCloud have the same timestamp as the local ones.
|
||||
assertLocalAndRemoteDir( $d, "$localDir/remoteToLocal1", $remoteDir . "remoteToLocal1" );
|
||||
|
||||
# remove a local file.
|
||||
unlink( "$localDir/remoteToLocal1/kernelcrash.txt" );
|
||||
csync( $localDir, $remoteDir );
|
||||
assertLocalAndRemoteDir( $d, "$localDir/remoteToLocal1", $remoteDir . "remoteToLocal1" );
|
||||
|
||||
# add local files to a new dir1
|
||||
my $locDir = $localDir . "/fromLocal1";
|
||||
|
||||
mkdir( $locDir );
|
||||
assert( -d $locDir );
|
||||
foreach my $file ( <./tolocal1/*> ) {
|
||||
print "Copying $file to $locDir\n";
|
||||
copy( $file, $locDir );
|
||||
}
|
||||
csync( $localDir, $remoteDir );
|
||||
assertLocalAndRemoteDir( $d, $locDir, $remoteDir . "fromLocal1" );
|
||||
|
||||
|
||||
print "\nInterrupt before cleanup in 4 seconds...\n";
|
||||
sleep(4);
|
||||
|
||||
remoteCleanup( $d, $remoteDir );
|
||||
localCleanup( $localDir );
|
||||
|
||||
|
||||
# end.
|
BIN
tests/ownCloud/tolocal1/Blacksmith.png
Normal file
BIN
tests/ownCloud/tolocal1/Blacksmith.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
tests/ownCloud/tolocal1/kb1.png
Normal file
BIN
tests/ownCloud/tolocal1/kb1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 870 KiB |
BIN
tests/ownCloud/tolocal1/kramer.jpg
Normal file
BIN
tests/ownCloud/tolocal1/kramer.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 195 KiB |
1
tests/ownCloud/toremote1/My Document.doc
Normal file
1
tests/ownCloud/toremote1/My Document.doc
Normal file
|
@ -0,0 +1 @@
|
|||
A nice document.
|
16
tests/ownCloud/toremote1/kernelcrash.txt
Normal file
16
tests/ownCloud/toremote1/kernelcrash.txt
Normal file
|
@ -0,0 +1,16 @@
|
|||
freitag@zora:~>
|
||||
Message from syslogd@zora at Sep 20 21:35:41 ...
|
||||
kernel:[ 6702.458047] general protection fault: 0000 [#1] PREEMPT SMP
|
||||
|
||||
Message from syslogd@zora at Sep 20 21:35:41 ...
|
||||
kernel:[ 6702.458060] last sysfs file: /sys/devices/LNXSYSTM:00/device:00/PNP0A08:00/device:03/ATK0110:00/hwmon/hwmon0/temp1_label
|
||||
|
||||
Message from syslogd@zora at Sep 20 21:35:41 ...
|
||||
kernel:[ 6702.458232] Stack:
|
||||
|
||||
Message from syslogd@zora at Sep 20 21:35:41 ...
|
||||
kernel:[ 6702.458262] Call Trace:
|
||||
|
||||
Message from syslogd@zora at Sep 20 21:35:41 ...
|
||||
kernel:[ 6702.458375] Code: 00 00 80 00 00 00 48 b9 00 00 00 00 80 ff ff ff 4e 8d 34 30 49 21 ce 48 8b 4c 24 38 49 8d 56 ff 48 3b 54 24 48 4c 0f 43 74 24 40 <48> 8b 11 48 85 d2 0f 84 d4 01 00 00 48 b9 fb 0f 00 00 00 c0 ff
|
||||
|
BIN
tests/ownCloud/toremote1/kraft_logo.gif
Normal file
BIN
tests/ownCloud/toremote1/kraft_logo.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.9 KiB |
Loading…
Reference in a new issue