File: dav_ext.t

package info (click to toggle)
nginx 1.18.0-6.1%2Bdeb11u3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 19,344 kB
  • sloc: ansic: 250,653; perl: 7,548; sh: 1,408; ruby: 879; python: 358; makefile: 338; awk: 36; cpp: 18
file content (141 lines) | stat: -rw-r--r-- 3,296 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

# (C) Roman Arutyunyan

# Tests for nginx-dav-ext-module.

###############################################################################

use warnings;
use strict;

use Test::More;

BEGIN { use FindBin; chdir($FindBin::Bin); }

use lib 'lib';
use Test::Nginx;
use HTTP::DAV

###############################################################################

select STDERR; $| = 1;
select STDOUT; $| = 1;

my $t = Test::Nginx->new()->has(qw/http dav/)->plan(20);

$t->write_file_expand('nginx.conf', <<'EOF');

%%TEST_GLOBALS%%

daemon off;

events {
}

http {
    %%TEST_GLOBALS_HTTP%%

    dav_ext_lock_zone zone=foo:10m timeout=10s;

    server {
        listen       127.0.0.1:8080;
        server_name  localhost;

        location / {
            dav_methods PUT DELETE MKCOL COPY MOVE;
            dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
            dav_ext_lock zone=foo;
        }
    }
}

EOF

$t->write_file('foo', 'foo');

$t->run();

###############################################################################

my $url = "http://127.0.0.1:8080";

my $content;

my $d = HTTP::DAV->new();
$d->open($url);

my $d2 = HTTP::DAV->new();
$d2->open($url);

#debug:
#$d->DebugLevel(3);
#see /tmp/perldav_debug.txt.

my $p = $d->propfind('/', 1);
is($p->is_collection, 1, 'propfind dir collection');
is($p->get_property('displayname'), '/', 'propfind dir displayname');
is($p->get_uri(), 'http://127.0.0.1:8080/', 'propfind dir uri');

$p = $d->propfind('/foo');
is($p->is_collection, 0, 'propfind file collection');
is($p->get_property('displayname'), 'foo', 'propfind file displayname');
is($p->get_uri(), 'http://127.0.0.1:8080/foo', 'propfind file uri');
is($p->get_property('getcontentlength'), '3', 'propfind file size');

$d->lock('/foo');
is($d->lock('/foo'), 0, 'prevent double lock');

$d->unlock('/foo');
is($d->lock('/foo'), 1, 'relock');

$d->lock('/bar');
$p = $d->propfind('/bar');
is($p->get_property('displayname'), 'bar', 'lock creates a file');

$d->get('/bar', \$content) or $content = 'none';
is($content, '', 'lock creates an empty file');

$content = "bar";
$d->put(\$content, '/bar');
$d->get('/bar', \$content) or $content = '';
is($content, 'bar', 'put lock');

$content = "qux";
$d2->put(\$content, '/bar');
$d2->get('/bar', \$content) or $content = '';
isnt($content, 'qux', 'prevent put lock');

$d->mkcol('/d/');
$d->lock('/d/');
$d->copy('/bar', '/d/bar');
$d->get('/d/bar', \$content) or $content = '';
is($content, 'bar', 'copy lock');

$d2->copy('/bar', '/d/qux');
$d2->get('/d/qux', \$content) or $content = '';
isnt($content, 'bar', 'prevent copy lock');

$d2->delete('/d/bar');
$d2->get('/d/bar', \$content) or $content = '';
is($content, 'bar', 'prevent delete lock');

$d->delete('/d/bar');
$d->get('/d/bar', \$content) or $content = '';
is($content, '', 'delete lock');

$d->mkcol('/d/c/');
$p = $d->propfind('/d/c/');
is($p->is_collection, 1, 'mkcol lock');

$d2->mkcol('/d/e/');
is($d2->propfind('/d/e/'), 0, 'prevent mkcol lock');

$d->unlock('/d/');
$d->lock('/d/', -depth=>"0");
$content = 'qux';
$d2->put(\$content, '/d/c/qux');
$d2->get('/d/c/qux', \$content) or $content = '';
is($content, 'qux', 'put to a depth-0-locked subdirectory');

###############################################################################