-
Notifications
You must be signed in to change notification settings - Fork 75
/
dav.t
271 lines (187 loc) · 4.86 KB
/
dav.t
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/perl
# (C) Maxim Dounin
# Tests for nginx dav module.
###############################################################################
use warnings;
use strict;
use Test::More;
BEGIN { use FindBin; chdir($FindBin::Bin); }
use lib 'lib';
use Test::Nginx;
###############################################################################
select STDERR; $| = 1;
select STDOUT; $| = 1;
my $t = Test::Nginx->new()->has(qw/http dav/)->plan(28);
$t->write_file_expand('nginx.conf', <<'EOF');
%%TEST_GLOBALS%%
daemon off;
events {
}
http {
%%TEST_GLOBALS_HTTP%%
server {
listen 127.0.0.1:8080;
server_name localhost;
absolute_redirect off;
location / {
dav_methods PUT DELETE MKCOL COPY MOVE;
}
location /i/ {
alias %%TESTDIR%%/;
dav_methods PUT DELETE MKCOL COPY MOVE;
}
}
}
EOF
$t->run();
###############################################################################
my $r;
$r = http(<<EOF . '0123456789');
PUT /file HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF
like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'put file');
is(-s $t->testdir() . '/file', 10, 'put file size');
$r = http(<<EOF);
PUT /file HTTP/1.1
Host: localhost
Connection: close
Content-Length: 0
EOF
like($r, qr/204 No Content/, 'put file again');
unlike($r, qr/Content-Length|Transfer-Encoding/, 'no length in 204');
is(-s $t->testdir() . '/file', 0, 'put file again size');
$r = http(<<EOF);
DELETE /file HTTP/1.1
Host: localhost
Connection: close
Content-Length: 0
EOF
like($r, qr/204 No Content/, 'delete file');
unlike($r, qr/Content-Length|Transfer-Encoding/, 'no length in 204');
ok(!-f $t->testdir() . '/file', 'file deleted');
$r = http(<<EOF . '0123456789' . 'extra');
PUT /file HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF
like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms,
'put file extra data');
is(-s $t->testdir() . '/file', 10,
'put file extra data size');
$r = http(<<EOF . '0123456789');
PUT /file%20sp HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF
like($r, qr!Location: /file%20sp\x0d?$!ms, 'put file escaped');
# 201 replies contain body, response should indicate it's empty
$r = http(<<EOF);
MKCOL /test/ HTTP/1.1
Host: localhost
Connection: close
EOF
like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'mkcol');
SKIP: {
skip 'perl too old', 1 if !$^V or $^V lt v5.12.0;
like($r, qr!(?(?{ $r =~ /Location/ })Location: /test/)!, 'mkcol location');
}
$r = http(<<EOF);
COPY /test/ HTTP/1.1
Host: localhost
Destination: /test-moved/
Connection: close
EOF
like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'copy dir');
$r = http(<<EOF);
MOVE /test/ HTTP/1.1
Host: localhost
Destination: /test-moved/
Connection: close
EOF
like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'move dir');
$r = http(<<EOF);
COPY /file HTTP/1.1
Host: localhost
Destination: /file-moved%20escape
Connection: close
EOF
like($r, qr/204 No Content/, 'copy file escaped');
is(-s $t->testdir() . '/file-moved escape', 10, 'file copied unescaped');
$t->write_file('file.exist', join '', (1 .. 42));
$r = http(<<EOF);
COPY /file HTTP/1.1
Host: localhost
Destination: /file.exist
Connection: close
EOF
like($r, qr/204 No Content/, 'copy file overwrite');
is(-s $t->testdir() . '/file.exist', 10, 'target file truncated');
$r = http(<<EOF . '0123456789');
PUT /i/alias HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF
like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'put alias');
like($r, qr!Location: /i/alias\x0d?$!ms, 'location alias');
is(-s $t->testdir() . '/alias', 10, 'put alias size');
# request methods with unsupported request body
$r = http(<<EOF . '0123456789');
MKCOL /test/ HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF
like($r, qr/415 Unsupported/, 'mkcol body');
$r = http(<<EOF . '0123456789');
COPY /file HTTP/1.1
Host: localhost
Destination: /file.exist
Connection: close
Content-Length: 10
EOF
like($r, qr/415 Unsupported/, 'copy body');
$r = http(<<EOF . '0123456789');
DELETE /file HTTP/1.1
Host: localhost
Connection: close
Content-Length: 10
EOF
like($r, qr/415 Unsupported/, 'delete body');
$r = http(<<EOF);
MKCOL /test/ HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked
a
0123456789
0
EOF
like($r, qr/415 Unsupported/, 'mkcol body chunked');
$r = http(<<EOF);
COPY /file HTTP/1.1
Host: localhost
Destination: /file.exist
Connection: close
Transfer-Encoding: chunked
a
0123456789
0
EOF
like($r, qr/415 Unsupported/, 'copy body chunked');
$r = http(<<EOF);
DELETE /file HTTP/1.1
Host: localhost
Connection: close
Transfer-Encoding: chunked
a
0123456789
0
EOF
like($r, qr/415 Unsupported/, 'delete body chunked');
###############################################################################