diff --git a/csync/tests/ownCloud/ownCloud/Test.pm b/csync/tests/ownCloud/ownCloud/Test.pm index 69468b4cb..84e509d85 100644 --- a/csync/tests/ownCloud/ownCloud/Test.pm +++ b/csync/tests/ownCloud/ownCloud/Test.pm @@ -32,7 +32,7 @@ use Digest::MD5; use Unicode::Normalize; use LWP::UserAgent; use LWP::Protocol::https; -use HTTP::Request::Common qw( POST DELETE ); +use HTTP::Request::Common qw( POST GET DELETE ); use File::Basename; use Encode qw(from_to); @@ -65,7 +65,7 @@ our %config; putToDirLWP localDir remoteDir localCleanup createLocalFile md5OfFile remoteCleanup server initLocalDir initRemoteDir moveRemoteFile printInfo remoteFileId createShare removeShare - configValue testDirUrl); + configValue testDirUrl getToFileLWP); sub server { @@ -530,6 +530,27 @@ sub putToDirLWP($$) } } +# does a simple GET of a file in the testdir to a local file. +sub getToFileLWP( $$ ) +{ + my ($file, $localFile) = @_; + my $geturl = testDirUrl() . $file; + print "GETting $geturl to $localFile\n"; + + my $ua = LWP::UserAgent->new(); + $ua->agent( "ownCloudTest_$localDir"); + # my $req = $ua->get($geturl, ":content_file" => $localFile); + my $req = HTTP::Request->new( GET => $geturl ); + $req->authorization_basic("$user", "$passwd"); + my $response = $ua->request($req); + + if ($response->is_success()) { + print "OK: ", $response->content; + } else { + die( "HTTP GET failed: " . $response->as_string ); + } +} + sub createLocalFile( $$ ) { my ($fname, $size) = @_; diff --git a/csync/tests/ownCloud/t1.pl b/csync/tests/ownCloud/t1.pl index f14860fa9..8a578a823 100755 --- a/csync/tests/ownCloud/t1.pl +++ b/csync/tests/ownCloud/t1.pl @@ -145,8 +145,6 @@ assertLocalAndRemoteDir( 'fromLocal1', 0); assert( -e localDir().'remoteToLocal1/rtlX' ); assert( -e localDir().'remoteToLocal1/rtlX/rtl11/file.txt' ); - - # ================================================================== cleanup(); diff --git a/csync/tests/ownCloud/t6.pl b/csync/tests/ownCloud/t6.pl new file mode 100755 index 000000000..73e9e1b46 --- /dev/null +++ b/csync/tests/ownCloud/t6.pl @@ -0,0 +1,61 @@ +#!/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 +# +# 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 +# + +use lib "."; + +use Carp::Assert; +use File::Copy; +use ownCloud::Test; + +use strict; + +print "Hello, this is t6, a tester for csync with ownCloud.\n"; + +initTesting(); + +# Big file chunking +printInfo( "Do a big file that is chunked"); +createLocalFile( localDir().'BIG.file', 22272592 ); +assert( -e localDir().'BIG.file' ); +my $bigMd5 = md5OfFile( localDir().'BIG.file' ); + +csync(); +my $newMd5 = md5OfFile( localDir().'BIG.file' ); +assert( $newMd5 eq $bigMd5 ); + +# download +my $ctrlFile = "/tmp/file.download"; +getToFileLWP( 'BIG.file', $ctrlFile ); + +assert( -e $ctrlFile, "File does not exist!" ); + +# assert files +my $dlMd5 = md5OfFile( $ctrlFile ); +assert( $dlMd5 eq $newMd5 ); + + +# ================================================================== + +cleanup(); + +# --