blob: 2362f95afc39d5709e5cf136cde44e5d4d6ed4ef [file] [log] [blame]
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil;
##
## mod_dav tests
##
plan tests => 14, [qw(dav HTTP::DAV)];
require HTTP::DAV;
my $vars = Apache::Test::vars();
my $dav = HTTP::DAV->new;
my $server = "$vars->{servername}:$vars->{port}";
my $response;
my $dir = "modules/dav";
my $uri = "/$dir/dav.html";
my $body = <<CONTENT;
<html>
<body>
<center>
<h1>mod_dav test page</h1>
this is a page generated by<br>
the mod_dav test in the Apache<br>
perl test suite.<br>
</center>
</body>
</html>
CONTENT
## make sure its clean before we begin ##
unlink "htdocs$uri" if -e "htdocs$uri";
mkdir "htdocs/$dir", oct('755') unless -e "htdocs/$dir";
Apache::TestUtil::chown("htdocs/$dir");
## set up resource and lock it ##
my $resource = $dav->new_resource( -uri => "http://$server$uri");
$response = $resource->lock;
print "resource lock test:\n";
ok $response->is_success;
## write new resource ##
$response = $resource->put($body);
print "DAV put test:\n";
ok $response->is_success;
## get properties ##
$response = $resource->propfind;
print "getting DAV resource properties:\n";
ok $response->is_success;
my $createdate = $resource->get_property( "creationdate" );
my $lastmodified = $resource->get_property( "getlastmodified" );
print "created: $createdate\n";
print "modified: $lastmodified\n";
ok $createdate eq $lastmodified;
## should be locked ##
print "resource lock status test:\n";
ok $resource->is_locked;
## unlock ##
## for some reason $resource->unlock is not working for me...
## even $resource->unlock( -force => 1 ) did not do it...
## nothing unlocked it except $resource->forcefully_unlock_all
print "resource unlock test:\n";
$response = $resource->forcefully_unlock_all;
ok $response->is_success;
## should be unlocked ##
print "resource lock status test:\n";
$response = $resource->is_locked;
ok !$resource->is_locked;
## verify new resource using regular http get ##
my $actual = GET_BODY $uri;
print "getting uri...\nexpect:\n->$body<-\ngot:\n->$actual<-\n";
ok $actual eq $body;
## testing with second dav client ##
my $d2 = HTTP::DAV->new;
my $r2 = $dav->new_resource( -uri => "http://$server$uri");
## put an unlocked resource (will work) ##
$response = $r2->get;
my $b2 = $r2->get_content;
$b2 =~ s#<h1>mod_dav test page</h1>#<h1>mod_dav test page take two</h1>#;
print "putting with 2nd dav client (on unlocked resource)\n";
$response = $r2->put($b2);
ok $response->is_success;
$actual = GET_BODY $uri;
print "getting new uri...\nexpect:\n->$b2<-\ngot:\n->$actual<-\n";
ok $actual eq $b2;
## client 1 locks, client 2 should not be able to lock ##
print "client 1 locking resource\n";
$response = $resource->lock
(
-owner => 'mod_dav test client 1',
-depth => 'Infinity',
-scope => 'exclusive',
-type => 'write',
-timeout => 120
);
ok $response->is_success;
print "client 2 attempting to lock same resource\n";
$response = $r2->lock
(
-owner => 'mod_dav test client 2',
-depth => 'Infinity',
-scope => 'exclusive',
-type => 'write',
-timeout => 120
);
ok !$response->is_success;
##############################################################################
## this should work, but does not. i'm thinking probably a bug in HTTP::DAV
## so i'm commenting it out. the second client (without the lock) can put
## the resource locked by client 1... that is no good. look into this later.
## it's also entirely possible, i'm doing something totally wrong.
##############################################################################
#$response = $r2->get;
#my $b3 = $r2->get_content;
#$b3 =~ s#mod_dav#f00#g;
#
#print "client 2 attempting to put resource locked by client 1\n";
#$response = $r2->put($b3);
#ok !$response->is_success;
#
#print "verifying all is well through http\n";
#$actual = GET_BODY $uri;
#print "getting new uri...\nexpect:\n->$b2<-\ngot:\n->$actual<-\n";
#ok $actual ne $b3;
#ok $actual eq $b2;
###############################################################################
## delete resource ##
$response = $resource->forcefully_unlock_all; ## trusing this will work
$response = $resource->delete;
print "resource delete test:\n";
ok $response->is_success;
$actual = GET_RC $uri;
print "expect 404 not found got: $actual\n";
ok $actual == 404;
## clean up ##
rmdir "htdocs/$dir/.DAV" or print "warning: could not remove .DAV dir: $!";
rmdir "htdocs/$dir" or print "warning: could not remove dav dir: $!";