blob: 73046cda0c839bcb4900a39041e58dd7c0b819e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil;
use HTTP::Date;
##
## mod_dav tests
##
plan tests => 19, [qw(dav HTTP::DAV)];
require HTTP::DAV;
my $vars = Apache::Test::vars();
my $dav = HTTP::DAV->new;
my $server = "$vars->{servername}:$vars->{port}";
my $htdocs = Apache::Test::vars('documentroot');
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::t_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 ##
## Wait until none of the returned time
## properties equals "now"
sleep(2);
$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" );
my $now = HTTP::Date::time2str(time());
print "created: $createdate\n";
print "modified: $lastmodified\n";
print "now: $now\n";
ok $createdate ne $now;
ok $createdate eq $lastmodified;
## should be locked ##
print "resource lock status test:\n";
ok $resource->is_locked;
## unlock ##
print "resource unlock test:\n";
$response = $resource->unlock;
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 = $d2->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;
## client 2 should not be able to put because the resource is already locked by client 1 ##
$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;
## PR 49825 ##
my $user_agent = $dav->get_user_agent;
# invalid content-range header
$user_agent->default_header('Content-Range' => 'bytes 1-a/44' );
$response = $resource->put($body);
$actual = $response->code;
print "PR 49825: expect 400 bad request got: $actual\n";
ok $actual == 400;
$user_agent->default_header('Content-Range' => undef);
## 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: $!";
|