Proper cleanup of the shared directory.

This commit is contained in:
Klaas Freitag 2014-03-28 16:15:32 +01:00
parent 9822002480
commit ab439f8f0f
2 changed files with 51 additions and 3 deletions

View file

@ -31,7 +31,7 @@ use Carp::Assert;
use Digest::MD5; use Digest::MD5;
use Unicode::Normalize; use Unicode::Normalize;
use LWP::UserAgent; use LWP::UserAgent;
use HTTP::Request::Common; use HTTP::Request::Common qw( POST DELETE );
use File::Basename; use File::Basename;
use Encode qw(from_to); use Encode qw(from_to);
@ -63,7 +63,7 @@ our %config;
assertLocalDirs assertLocalAndRemoteDir glob_put put_to_dir assertLocalDirs assertLocalAndRemoteDir glob_put put_to_dir
putToDirLWP localDir remoteDir localCleanup createLocalFile md5OfFile putToDirLWP localDir remoteDir localCleanup createLocalFile md5OfFile
remoteCleanup server initLocalDir initRemoteDir moveRemoteFile remoteCleanup server initLocalDir initRemoteDir moveRemoteFile
printInfo remoteFileId createShare printInfo remoteFileId createShare removeShare
configValue testDirUrl); configValue testDirUrl);
sub server sub server
@ -634,11 +634,54 @@ sub createShare($$)
$req->authorization_basic($share_user, $share_passwd); $req->authorization_basic($share_user, $share_passwd);
my $response = $ua->request($req); my $response = $ua->request($req);
my $id = 0;
if ($response->is_success()) { if ($response->is_success()) {
# print "OK: ", $response->content; # print "OK: ", $response->content;
print $response->decoded_content;
if( $response->decoded_content =~ /<id>(\d+)<\/id>/m) {
$id = $1;
}
} else { } else {
die( "Create sharing failed: " . $response->as_string ); die( "Create sharing failed: " . $response->as_string );
} }
return $id;
}
sub removeShare($$)
{
my ($shareId, $dir) = @_;
my $dd = HTTP::DAV->new();
$dd->credentials( -url => $owncloud, -realm=>"ownCloud",
-user => $share_user,
-pass => $share_passwd );
$dd->open( $owncloud);
my $ua = LWP::UserAgent->new();
$ua->agent( "ownCloudTest_sharing");
# http://localhost/ocm/ocs/v1.php/apps/files_sharing/api/v1/shares
my $url = $ocs_url . "apps/files_sharing/api/v1/shares/" . $shareId;
my $req = DELETE $url;
$req->authorization_basic($share_user, $share_passwd);
my $response = $ua->request($req);
if ($response->is_success()) {
# print "OK: ", $response->content;
print $response->decoded_content;
if( $response->decoded_content =~ /<status_code>(\d+)<\/status_code>/m) {
my $code = $1;
assert( $code == 100 );
}
} else {
die( "Create sharing failed: " . $response->as_string );
}
# remove the share dir
my $req = DELETE $owncloud . $dir;
$req->authorization_basic($share_user, $share_passwd);
my $response = $ua->request($req);
} }
# #

View file

@ -37,7 +37,10 @@ initTesting();
my $share_dir = "share_source"; my $share_dir = "share_source";
printInfo( "Create a share." ); printInfo( "Create a share." );
createShare( $share_dir, 31 ); my $shareId = createShare( $share_dir, 31 );
print "Created share with id <$shareId>\n";
assert( $shareId > 0 );
# put a couple of files into the shared directory in the sharer account # put a couple of files into the shared directory in the sharer account
glob_put( 'sharing/*', $share_dir, { user => configValue('share_user'), glob_put( 'sharing/*', $share_dir, { user => configValue('share_user'),
@ -56,6 +59,8 @@ createLocalFile( localDir(). $share_dir . "/foobar.txt", 8094 );
csync( server()."Shared" ); csync( server()."Shared" );
assertLocalAndRemoteDir( 'Shared', 0, server() ); assertLocalAndRemoteDir( 'Shared', 0, server() );
printInfo("Remove a Share.");
removeShare($shareId, $share_dir);
cleanup(); cleanup();
# -- # --