Mercurial > hg > nginx-tests
annotate request_id.t @ 1990:85d88cd5091c
Tests: SSI include stub tests.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:42:55 +0300 |
parents | 766bcbb632ee |
children |
rev | line source |
---|---|
916
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
2 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
3 # (C) Andrey Zelenkov |
920
943a5952ee5e
Tests: fixed typo in copyright.
Sergey Kandaurov <pluknet@nginx.com>
parents:
916
diff
changeset
|
4 # (C) Nginx, Inc. |
916
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
5 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
6 # Tests for request_id variable. |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
7 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
9 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
11 use strict; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
12 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
14 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
16 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
19 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
21 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
24 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite ssi/) |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
27 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
29 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
31 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
32 events { |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
33 } |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
34 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
35 http { |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
37 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
38 log_format id $request_id; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
39 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
40 server { |
974
882267679006
Tests: simplified parallel modifications in tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
952
diff
changeset
|
41 listen 127.0.0.1:8080; |
916
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
42 server_name localhost; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
43 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
44 add_header X-Request-Id $request_id; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
45 add_header X-blah blah; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
46 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
47 location / { |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
48 ssi on; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
49 } |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
50 location /body { |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
51 return 200 $request_id; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
52 } |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
53 location /log { |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
54 access_log %%TESTDIR%%/id.log id; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
55 return 200; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
56 } |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
57 } |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
58 } |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
59 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
60 EOF |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
61 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
62 $t->write_file('index.html', ''); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
63 $t->write_file('add.html', '<!--#include virtual="/body" -->'); |
1251
766bcbb632ee
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
974
diff
changeset
|
64 $t->run()->plan(12); |
916
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
65 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
66 ############################################################################### |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
67 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
68 my ($id1) = http_get('/') =~ qr/^X-Request-Id: (.*)\x0d/m; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
69 my ($id2) = http_get('/') =~ qr/^X-Request-Id: (.*)\x0d/m; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
70 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
71 like($id1, qr/^[a-z0-9]{32}$/, 'format id 1'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
72 like($id2, qr/^[a-z0-9]{32}$/, 'format id 2'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
73 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
74 isnt($id1, $id2, 'different id'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
75 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
76 # same request |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
77 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
78 ($id1, $id2) = http_get('/body') |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
79 =~ qr/^X-Request-Id: (.*?)\x0d.*\x0d\x0a(.*)/ms; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
80 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
81 like($id1, qr/^[a-z0-9]{32}$/, 'format id 1 - same'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
82 like($id2, qr/^[a-z0-9]{32}$/, 'format id 2 - same'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
83 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
84 is($id1, $id2, 'equal id - same'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
85 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
86 # subrequest |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
87 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
88 ($id1, $id2) = http_get('/add.html') |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
89 =~ qr/^X-Request-Id: (.*?)\x0d.*\x0d\x0a(.*)/ms; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
90 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
91 like($id1, qr/^[a-z0-9]{32}$/, 'format id 1 - sub'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
92 like($id2, qr/^[a-z0-9]{32}$/, 'format id 2 - sub'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
93 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
94 is($id1, $id2, 'equal id - sub'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
95 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
96 # log |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
97 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
98 ($id1) = http_get('/log') =~ qr/^X-Request-Id: (.*)\x0d/m; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
99 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
100 $t->stop(); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
101 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
102 $id2 = $t->read_file('/id.log'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
103 chomp $id2; |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
104 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
105 like($id1, qr/^[a-z0-9]{32}$/, 'format id 1 - log'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
106 like($id2, qr/^[a-z0-9]{32}$/, 'format id 2 - log'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
107 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
108 is($id1, $id2, 'equal id - log'); |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
109 |
f2b2633a3fc1
Tests: added tests for request_id variable.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff
changeset
|
110 ############################################################################### |