comparison h2.t @ 652:5a85ad9382a3

Tests: more Cookie tests for HTTP/2. Specifically, it ensures that multiple Cookie header fields are properly reconstructed before beeing passed into a non-HTTP/2 context.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 19 Aug 2015 23:50:00 +0300
parents 9f66f0029dca
children 5ad620022234
comparison
equal deleted inserted replaced
651:9f66f0029dca 652:5a85ad9382a3
30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); }; 30 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
31 plan(skip_all => 'IO::Socket::SSL too old') if $@; 31 plan(skip_all => 'IO::Socket::SSL too old') if $@;
32 32
33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/) 33 my $t = Test::Nginx->new()->has(qw/http http_ssl http_v2 proxy cache/)
34 ->has(qw/limit_conn rewrite realip shmem/) 34 ->has(qw/limit_conn rewrite realip shmem/)
35 ->has_daemon('openssl')->plan(145); 35 ->has_daemon('openssl')->plan(148);
36 36
37 $t->write_file_expand('nginx.conf', <<'EOF'); 37 $t->write_file_expand('nginx.conf', <<'EOF');
38 38
39 %%TEST_GLOBALS%% 39 %%TEST_GLOBALS%%
40 40
106 add_header X-UC-a $upstream_cookie_a; 106 add_header X-UC-a $upstream_cookie_a;
107 add_header X-UC-c $upstream_cookie_c; 107 add_header X-UC-c $upstream_cookie_c;
108 proxy_pass http://127.0.0.1:8083/; 108 proxy_pass http://127.0.0.1:8083/;
109 proxy_cache NAME; 109 proxy_cache NAME;
110 proxy_cache_valid 1m; 110 proxy_cache_valid 1m;
111 proxy_set_header X-Cookie-a $cookie_a;
112 proxy_set_header X-Cookie-c $cookie_c;
111 } 113 }
112 location /proxy2/ { 114 location /proxy2/ {
113 add_header X-Body "$request_body"; 115 add_header X-Body "$request_body";
114 proxy_pass http://127.0.0.1:8081/; 116 proxy_pass http://127.0.0.1:8081/;
115 proxy_cache NAME; 117 proxy_cache NAME;
663 { name => 'cookie', value => 'a=b', mode => 2 }, 665 { name => 'cookie', value => 'a=b', mode => 2 },
664 { name => 'cookie', value => 'c=d', mode => 2 }]}); 666 { name => 'cookie', value => 'c=d', mode => 2 }]});
665 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]); 667 $frames = h2_read($sess, all => [{ sid => $sid, fin => 1 }]);
666 668
667 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames; 669 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
668 is($frame->{headers}->{'x-cookie'}, 'a=b; c=d', 670 is($frame->{headers}->{'x-sent-cookie'}, 'a=b; c=d',
669 'multiple request header fields proxied - semi-colon'); 671 'multiple request header fields proxied - semi-colon');
672 is($frame->{headers}->{'x-sent-cookie2'}, '',
673 'multiple request header fields proxied - dublicate cookie');
674 is($frame->{headers}->{'x-sent-cookie-a'}, 'b',
675 'multiple request header fields proxied - cookie 1');
676 is($frame->{headers}->{'x-sent-cookie-c'}, 'd',
677 'multiple request header fields proxied - cookie 2');
670 678
671 # response header field with multiple values 679 # response header field with multiple values
672 680
673 $sess = new_session(); 681 $sess = new_session();
674 $sid = new_stream($sess, { path => '/set-cookie' }); 682 $sid = new_stream($sess, { path => '/set-cookie' });
2343 while (my $client = $server->accept()) { 2351 while (my $client = $server->accept()) {
2344 $client->autoflush(1); 2352 $client->autoflush(1);
2345 2353
2346 my $headers = ''; 2354 my $headers = '';
2347 my $uri = ''; 2355 my $uri = '';
2348 my $cookie = '';
2349 2356
2350 while (<$client>) { 2357 while (<$client>) {
2351 $headers .= $_; 2358 $headers .= $_;
2352 last if (/^\x0d?\x0a?$/); 2359 last if (/^\x0d?\x0a?$/);
2353 } 2360 }
2354 2361
2355 next if $headers eq ''; 2362 next if $headers eq '';
2356 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i; 2363 $uri = $1 if $headers =~ /^\S+\s+([^ ]+)\s+HTTP/i;
2357 $cookie = $1 if $headers =~ /Cookie: (.+)/i;
2358 2364
2359 if ($uri eq '/cookie') { 2365 if ($uri eq '/cookie') {
2366
2367 my ($cookie, $cookie2) = $headers =~ /Cookie: (.+)/ig;
2368 $cookie2 = '' unless defined $cookie2;
2369
2370 my ($cookie_a, $cookie_c) = ('', '');
2371 $cookie_a = $1 if $headers =~ /X-Cookie-a: (.+)/i;
2372 $cookie_c = $1 if $headers =~ /X-Cookie-c: (.+)/i;
2360 2373
2361 print $client <<EOF; 2374 print $client <<EOF;
2362 HTTP/1.1 200 OK 2375 HTTP/1.1 200 OK
2363 Connection: close 2376 Connection: close
2364 X-Cookie: $cookie 2377 X-Sent-Cookie: $cookie
2378 X-Sent-Cookie2: $cookie2
2379 X-Sent-Cookie-a: $cookie_a
2380 X-Sent-Cookie-c: $cookie_c
2365 2381
2366 EOF 2382 EOF
2367 2383
2368 } elsif ($uri eq '/set-cookie') { 2384 } elsif ($uri eq '/set-cookie') {
2369 2385