comparison http_include.t @ 1470:ed2be714a3af

Tests: http include tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 24 Apr 2019 14:57:13 +0300
parents
children 5ac6efbe5552
comparison
equal deleted inserted replaced
1469:30284bd9ab18 1470:ed2be714a3af
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for include directive.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19
20 ###############################################################################
21
22 select STDERR; $| = 1;
23 select STDOUT; $| = 1;
24
25 my $t = Test::Nginx->new()->has(qw/http rewrite proxy access/)
26 ->write_file_expand('nginx.conf', <<'EOF');
27
28 %%TEST_GLOBALS%%
29
30 daemon off;
31
32 events {
33 }
34
35 http {
36 %%TEST_GLOBALS_HTTP%%
37
38 upstream u {
39 include ups.conf;
40 }
41
42 server {
43 listen 127.0.0.1:8080;
44 server_name localhost;
45
46 if ($arg_s) {
47 include sif.conf;
48 }
49
50 location / {
51 if ($arg_l) {
52 include lif.conf;
53 }
54 }
55
56 location /lmt {
57 limit_except GET {
58 include lmt.conf;
59 }
60 }
61
62 location /proxy {
63 add_header X-IP $upstream_addr always;
64 proxy_pass http://u/backend;
65 }
66
67 location /backend { }
68 }
69 }
70
71 EOF
72
73 my $p = port(8080);
74
75 $t->write_file('sif.conf', 'return 200 SIF;');
76 $t->write_file('lif.conf', 'return 200 LIF;');
77 $t->write_file('lmt.conf', 'deny all;');
78 $t->write_file('ups.conf', "server 127.0.0.1:$p;");
79
80 $t->try_run('no include in any context')->plan(5);
81
82 ###############################################################################
83
84 like(http_get('/?s=1'), qr/SIF/, 'include in server if');
85 like(http_get('/?l=1'), qr/LIF/, 'include in location if');
86 like(http_post('/lmt'), qr/ 403 /, 'include in limit_except');
87 like(http_get('/proxy'), qr/X-IP: 127.0.0.1:$p/, 'include in upstream');
88
89 unlike(http_get('/'), qr/ 200 /, 'no include');
90
91 ###############################################################################
92
93 sub http_post {
94 my ($uri) = @_;
95 http(<<EOF);
96 POST $uri HTTP/1.0
97 Host: localhost
98
99 EOF
100 }
101
102 ###############################################################################