Mercurial > hg > nginx-tests
annotate server_tokens.t @ 1614:bc0990ea2e5b
Tests: js TODO adjusted up to 0.4.0.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Tue, 17 Nov 2020 17:49:16 +0000 |
parents | 766bcbb632ee |
children | 5f46af4707e7 |
rev | line source |
---|---|
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for server_tokens directive. |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
1121
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite/) |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 events { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 http { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
39 listen 127.0.0.1:8080; |
881
56ed4be9ff41
Tests: added server_name and fixed indentation in server_tokens.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
878
diff
changeset
|
40 server_name localhost; |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
41 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 location /200 { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 return 200; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 location /404 { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 return 404; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 location /off { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 server_tokens off; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 location /off/200 { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 return 200; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 location /off/404 { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 return 404; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 location /on { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 server_tokens on; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
64 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 location /on/200 { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 return 200; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 location /on/404 { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 return 404; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 } |
1121
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
73 |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
74 location /b { |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
75 server_tokens build; |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
76 |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
77 location /b/200 { |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
78 return 200; |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
79 } |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
80 |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
81 location /b/404 { |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
82 return 404; |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
83 } |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
84 } |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 EOF |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1123
diff
changeset
|
90 $t->run()->plan(12); |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 ############################################################################### |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 |
1120
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
94 my $re = qr/nginx\/\d+\.\d+\.\d+/; |
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
95 |
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
96 like(http_get_server('/200'), $re, 'tokens default 200'); |
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
97 like(http_get_server('/404'), $re, 'tokens default 404'); |
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
98 like(http_body('/404'), $re, 'tokens default 404 body'); |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 |
878
327044615c87
Tests: added http_get_server subroutine in server_tokens.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
877
diff
changeset
|
100 is(http_get_server('/off/200'), 'nginx', 'tokens off 200'); |
327044615c87
Tests: added http_get_server subroutine in server_tokens.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
877
diff
changeset
|
101 is(http_get_server('/off/404'), 'nginx', 'tokens off 404'); |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 like(http_body('/off/404'), qr/nginx(?!\/)/, 'tokens off 404 body'); |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 |
1120
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
104 like(http_get_server('/on/200'), $re, 'tokens on 200'); |
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
105 like(http_get_server('/on/404'), $re, 'tokens on 404'); |
a6ffc722dfcb
Tests: refactored server_tokens tests, no functional changes.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1119
diff
changeset
|
106 like(http_body('/on/404'), $re, 'tokens on 404 body'); |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
107 |
1121
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
108 $re = qr/$re \Q($1)\E/ if $t->{_configure_args} =~ /--build=(\S+)/; |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
109 |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
110 like(http_get_server('/b/200'), $re, 'tokens build 200'); |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
111 like(http_get_server('/b/404'), $re, 'tokens build 404'); |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
112 like(http_body('/b/404'), $re, 'tokens build 404 body'); |
c883d3d3a3ab
Tests: server_tokens build tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1120
diff
changeset
|
113 |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
114 ############################################################################### |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
115 |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
116 sub http_body { |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
117 my ($uri) = shift; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
118 return http_get($uri) =~ /.*?\x0d\x0a?\x0d\x0a?(.*)/ms && $1; |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
119 } |
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
120 |
878
327044615c87
Tests: added http_get_server subroutine in server_tokens.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
877
diff
changeset
|
121 sub http_get_server { |
327044615c87
Tests: added http_get_server subroutine in server_tokens.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
877
diff
changeset
|
122 my ($url) = @_; |
1119
cfe1bc3162f9
Tests: fixed capturing Server header in server_tokens.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
123 return http_get($url) =~ /^Server:\s(.+?)\x0d?$/mi && $1 || undef; |
878
327044615c87
Tests: added http_get_server subroutine in server_tokens.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
877
diff
changeset
|
124 } |
327044615c87
Tests: added http_get_server subroutine in server_tokens.t.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
877
diff
changeset
|
125 |
869
f528369414aa
Tests: added tests for server_tokens directive.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
126 ############################################################################### |