|
| 1 | +#!/usr/bin/perl |
| 2 | + |
| 3 | +# (C) Sergey Kandaurov |
| 4 | +# (C) Nginx, Inc. |
| 5 | + |
| 6 | +# Tests for autoindex module on win32. |
| 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; }; |
| 28 | +plan(skip_all => 'Win32API::File not installed') if $@; |
| 29 | + |
| 30 | +my $t = Test::Nginx->new()->has(qw/http autoindex charset/)->plan(9) |
| 31 | + ->write_file_expand('nginx.conf', <<'EOF'); |
| 32 | +
|
| 33 | +%%TEST_GLOBALS%% |
| 34 | +
|
| 35 | +daemon off; |
| 36 | +
|
| 37 | +events { |
| 38 | +} |
| 39 | +
|
| 40 | +http { |
| 41 | + %%TEST_GLOBALS_HTTP%% |
| 42 | +
|
| 43 | + server { |
| 44 | + listen 127.0.0.1:8080; |
| 45 | + server_name localhost; |
| 46 | +
|
| 47 | + location / { |
| 48 | + autoindex on; |
| 49 | + charset utf-8; |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | +
|
| 54 | +EOF |
| 55 | + |
| 56 | +my $d = $t->testdir(); |
| 57 | + |
| 58 | +mkdir("$d/test-dir"); |
| 59 | +$t->write_file('test-file', ''); |
| 60 | + |
| 61 | +my $file = "$d/test-file-" . ("\x{043c}\x{0438}") x 3; |
| 62 | +win32_write_file($file, ''); |
| 63 | + |
| 64 | +my $dir = "$d/test-dir-" . ("\x{043c}\x{0438}") x 3; |
| 65 | +win32_mkdir($dir); |
| 66 | + |
| 67 | +my $subfile = "$dir/test-subfile-" . ("\x{043c}\x{0438}") x 3; |
| 68 | +win32_write_file($subfile, ''); |
| 69 | + |
| 70 | +$t->run(); |
| 71 | + |
| 72 | +############################################################################### |
| 73 | + |
| 74 | +my $r = http_get('/'); |
| 75 | + |
| 76 | +like($r, qr!href="test-file"!ms, 'file'); |
| 77 | +like($r, qr!href="test-dir/"!ms, 'directory'); |
| 78 | + |
| 79 | +TODO: { |
| 80 | +local $TODO = 'not yet' unless $t->has_version('1.23.4'); |
| 81 | + |
| 82 | +like($r, qr!href="test-file-(%d0%bc%d0%b8){3}"!msi, 'utf file link'); |
| 83 | +like($r, qr!test-file-(\xd0\xbc\xd0\xb8){3}</a>!ms, 'utf file name'); |
| 84 | + |
| 85 | +like($r, qr!href="test-dir-(%d0%bc%d0%b8){3}/"!msi, 'utf dir link'); |
| 86 | +like($r, qr!test-dir-(\xd0\xbc\xd0\xb8){3}/</a>!ms, 'utf dir name'); |
| 87 | + |
| 88 | +$r = http_get('/test-dir-' . "\xd0\xbc\xd0\xb8" x 3 . '/'); |
| 89 | + |
| 90 | +like($r, qr!Index of /test-dir-(\xd0\xbc\xd0\xb8){3}/!msi, 'utf subdir index'); |
| 91 | + |
| 92 | +like($r, qr!href="test-subfile-(%d0%bc%d0%b8){3}"!msi, 'utf subdir link'); |
| 93 | +like($r, qr!test-subfile-(\xd0\xbc\xd0\xb8){3}</a>!msi, 'utf subdir name'); |
| 94 | + |
| 95 | +} |
| 96 | + |
| 97 | +############################################################################### |
| 98 | + |
| 99 | +sub win32_mkdir { |
| 100 | + my ($name) = @_; |
| 101 | + |
| 102 | + mkdir("$d/test-dir-tmp"); |
| 103 | + Win32API::File::MoveFileW(encode("UTF-16LE","$d/test-dir-tmp\0"), |
| 104 | + encode("UTF-16LE", $name . "\0")) or die "$^E"; |
| 105 | +} |
| 106 | + |
| 107 | +sub win32_write_file { |
| 108 | + my ($name, $data) = @_; |
| 109 | + |
| 110 | + my $h = Win32API::File::CreateFileW(encode("UTF-16LE", $name . "\0"), |
| 111 | + Win32API::File::FILE_READ_DATA() |
| 112 | + | Win32API::File::FILE_WRITE_DATA(), 0, [], |
| 113 | + Win32API::File::CREATE_NEW(), 0, []) or die $^E; |
| 114 | + |
| 115 | + Win32API::File::WriteFile($h, $data, 0, [], []) or die $^E; |
| 116 | + Win32API::File::CloseHandle($h) or die $^E; |
| 117 | +} |
| 118 | + |
| 119 | +############################################################################### |
0 commit comments