comparison dav_utf8.t @ 1828:835630547d35

Tests: dav tests with UTF-8.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 21 Mar 2023 14:20:54 +0400
parents
children a095b971fbcc
comparison
equal deleted inserted replaced
1827:1b53142f7fdc 1828:835630547d35
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for nginx dav module with utf8 encoded names.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 use Encode qw/ encode /;
16
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
18
19 use lib 'lib';
20 use Test::Nginx;
21
22 ###############################################################################
23
24 select STDERR; $| = 1;
25 select STDOUT; $| = 1;
26
27 eval { require Win32API::File if $^O eq 'MSWin32'; };
28 plan(skip_all => 'Win32API::File not installed') if $@;
29
30 my $t = Test::Nginx->new()->has(qw/http dav/)->plan(16);
31
32 $t->write_file_expand('nginx.conf', <<'EOF');
33
34 %%TEST_GLOBALS%%
35
36 daemon off;
37
38 events {
39 }
40
41 http {
42 %%TEST_GLOBALS_HTTP%%
43
44 server {
45 listen 127.0.0.1:8080;
46 server_name localhost;
47
48 location / {
49 dav_methods PUT DELETE MKCOL COPY MOVE;
50 }
51 }
52 }
53
54 EOF
55
56 $t->run();
57
58 ###############################################################################
59
60 local $TODO = 'not yet' if $^O eq 'MSWin32' and !$t->has_version('1.23.4');
61
62 my $d = $t->testdir();
63 my $r;
64
65 my $file = "file-%D0%BC%D0%B8";
66 my $file_path = "file-\x{043c}\x{0438}";
67
68 $r = http(<<EOF . '0123456789');
69 PUT /$file HTTP/1.1
70 Host: localhost
71 Connection: close
72 Content-Length: 10
73
74 EOF
75
76 like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'put file');
77 ok(fileexists("$d/$file_path"), 'put file exist');
78
79 $r = http(<<EOF);
80 COPY /$file HTTP/1.1
81 Host: localhost
82 Destination: /$file-moved
83 Connection: close
84
85 EOF
86
87 like($r, qr/204 No Content/, 'copy file');
88 ok(fileexists("$d/$file_path-moved"), 'copy file exist');
89
90 $r = http(<<EOF);
91 MOVE /$file HTTP/1.1
92 Host: localhost
93 Destination: /$file-moved
94 Connection: close
95
96 EOF
97
98 like($r, qr/204 No Content/, 'move file');
99 ok(!fileexists("$d/$file_path"), 'file moved');
100
101 $r = http(<<EOF);
102 DELETE /$file-moved HTTP/1.1
103 Host: localhost
104 Connection: close
105 Content-Length: 0
106
107 EOF
108
109 like($r, qr/204 No Content/, 'delete file');
110 ok(!fileexists("$d/$file_path-moved"), 'file deleted');
111
112 my $dir = "dir-%D0%BC%D0%B8";
113 my $dir_path = "dir-\x{043c}\x{0438}";
114
115 $r = http(<<EOF);
116 MKCOL /$dir/ HTTP/1.1
117 Host: localhost
118 Connection: close
119
120 EOF
121
122 like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'mkcol');
123 ok(fileexists("$d/$dir_path"), 'mkcol exist');
124
125 $r = http(<<EOF);
126 COPY /$dir/ HTTP/1.1
127 Host: localhost
128 Destination: /$dir-moved/
129 Connection: close
130
131 EOF
132
133 like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'copy dir');
134 ok(fileexists("$d/$dir_path-moved"), 'copy dir exist');
135
136 $r = http(<<EOF);
137 MOVE /$dir/ HTTP/1.1
138 Host: localhost
139 Destination: /$dir-moved/
140 Connection: close
141
142 EOF
143
144 like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'move dir');
145 ok(!fileexists("$d/$dir_path"), 'dir moved');
146
147 $r = http(<<EOF);
148 DELETE /$dir-moved/ HTTP/1.1
149 Host: localhost
150 Connection: close
151
152 EOF
153
154 unlike($r, qr/200 OK.*Content-Length|Transfer-Encoding/ms, 'delete dir');
155 ok(!fileexists("$d/$dir_path-moved"), 'dir deleted');
156
157 ###############################################################################
158
159 sub fileexists {
160 my ($path) = @_;
161
162 return -e $path if $^O ne 'MSWin32';
163
164 $path = encode("UTF-16LE", $path . "\0");
165 my $attr = Win32API::File::GetFileAttributesW($path);
166 return 0 if $attr == Win32API::File::INVALID_HANDLE_VALUE();
167 return $attr;
168 }
169
170 ###############################################################################