Mercurial > hg > nginx-tests
comparison h2_proxy_protocol.t @ 876:a6abbfed42c0
Tests: split HTTP/2 tests, HTTP2 package introduced.
author | Andrey Zelenkov <zelenkov@nginx.com> |
---|---|
date | Wed, 23 Mar 2016 17:23:08 +0300 |
parents | |
children | e309d9701007 |
comparison
equal
deleted
inserted
replaced
875:c380b4b7e2e4 | 876:a6abbfed42c0 |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 protocol with proxy_protocol. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 use Socket qw/ CRLF /; | |
16 | |
17 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
18 | |
19 use lib 'lib'; | |
20 use Test::Nginx; | |
21 use Test::Nginx::HTTP2; | |
22 | |
23 ############################################################################### | |
24 | |
25 select STDERR; $| = 1; | |
26 select STDOUT; $| = 1; | |
27 | |
28 my $t = Test::Nginx->new()->has(qw/http http_v2 realip/)->plan(4) | |
29 ->write_file_expand('nginx.conf', <<'EOF'); | |
30 | |
31 %%TEST_GLOBALS%% | |
32 | |
33 daemon off; | |
34 | |
35 events { | |
36 } | |
37 | |
38 http { | |
39 %%TEST_GLOBALS_HTTP%% | |
40 | |
41 server { | |
42 listen 127.0.0.1:8080 http2; | |
43 listen 127.0.0.1:8081 proxy_protocol http2; | |
44 server_name localhost; | |
45 | |
46 location /pp { | |
47 set_real_ip_from 127.0.0.1/32; | |
48 real_ip_header proxy_protocol; | |
49 alias %%TESTDIR%%/t.html; | |
50 add_header X-PP $remote_addr; | |
51 } | |
52 } | |
53 } | |
54 | |
55 EOF | |
56 | |
57 $t->write_file('t.html', 'SEE-THIS'); | |
58 $t->run(); | |
59 | |
60 ############################################################################### | |
61 | |
62 my $proxy = 'PROXY TCP4 192.0.2.1 192.0.2.2 1234 5678' . CRLF; | |
63 my $sess = new_session(8081, proxy => $proxy); | |
64 my $sid = new_stream($sess, { path => '/pp' }); | |
65 my $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); | |
66 | |
67 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; | |
68 ok($frame, 'PROXY HEADERS frame'); | |
69 is($frame->{headers}->{'x-pp'}, '192.0.2.1', 'PROXY remote addr'); | |
70 | |
71 # invalid PROXY protocol string | |
72 | |
73 $sess = new_session(8081, proxy => 'BOGUS TCP4 192.0.2.1 192.0.2.2 1234 5678', | |
74 pure => 1); | |
75 $frames = h2_read($sess, all => [{ type => 'GOAWAY' }]); | |
76 | |
77 ($frame) = grep { $_->{type} eq "GOAWAY" } @$frames; | |
78 ok($frame, 'invalid PROXY - GOAWAY frame'); | |
79 is($frame->{code}, 1, 'invalid PROXY - error code'); | |
80 | |
81 ############################################################################### |