1use strict; 2use warnings FATAL => 'all'; 3 4use Apache::Test; 5use Apache::TestUtil; 6use Apache::TestConfig; 7use Apache::TestRequest qw(GET_BODY UPLOAD_BODY POST_BODY GET_RC GET_HEAD); 8use constant WIN32 => Apache::TestConfig::WIN32; 9 10my @key_len = (5, 100, 305); 11my @key_num = (5, 15, 26); 12my @keys = ('a'..'z'); 13 14my @big_key_len = (100, 500, 5000, 10000); 15my @big_key_num = (5, 15, 25); 16my @big_keys = ('a'..'z'); 17 18plan tests => 10 + @key_len * @key_num + @big_key_len * @big_key_num, 19 need_lwp && need_cgi; 20 21require HTTP::Cookies; 22 23my $location = '/cgi-bin'; 24my $script = $location . (WIN32 ? '/test_cgi.exe' : '/test_cgi'); 25my $line_end = "\n"; 26my $filler = "0123456789" x 20; # < 64K 27 28# GET 29for my $key_len (@key_len) { 30 for my $key_num (@key_num) { 31 my @query = (); 32 my $len = 0; 33 34 for my $key (@keys[0..($key_num-1)]) { 35 my $pair = "$key=" . 'd' x $key_len; 36 $len += length($pair) - 1; 37 push @query, $pair; 38 } 39 my $query = join ";", @query; 40 41 t_debug "# of keys : $key_num, key_len $key_len"; 42 my $body = GET_BODY "$script?$query"; 43 ok t_cmp($body, 44 $len, 45 "GET long query"); 46 } 47 48} 49 50# POST 51for my $big_key_len (@big_key_len) { 52 for my $big_key_num (@big_key_num) { 53 my @query = (); 54 my $len = 0; 55 56 for my $big_key (@big_keys[0..($big_key_num-1)]) { 57 my $pair = "$big_key=" . 'd' x $big_key_len; 58 $len += length($pair) - 1; 59 push @query, $pair; 60 } 61 my $query = join ";", @query; 62 63 t_debug "# of keys : $big_key_num, big_key_len $big_key_len"; 64 my $body = POST_BODY($script, content => $query); 65 ok t_cmp($body, 66 $len, 67 "POST big data"); 68 } 69 70} 71 72ok t_cmp(POST_BODY("$script?foo=1", Content => $filler), 73 "\tfoo => 1$line_end", "simple post"); 74 75ok t_cmp(GET_BODY("$script?foo=%3F&bar=hello+world"), 76 "\tfoo => ?$line_end\tbar => hello world$line_end", "simple get"); 77 78my $body = POST_BODY($script, content => 79 "aaa=$filler;foo=1;bar=2;filler=$filler"); 80ok t_cmp($body, "\tfoo => 1$line_end\tbar => 2$line_end", 81 "simple post"); 82 83$body = POST_BODY("$script?foo=1", content => 84 "intro=$filler&bar=2&conclusion=$filler"); 85ok t_cmp($body, "\tfoo => 1$line_end\tbar => 2$line_end", 86 "simple post"); 87 88$body = UPLOAD_BODY("$script?foo=0", content => $filler); 89ok t_cmp($body, "\tfoo => 0$line_end", 90 "simple upload"); 91 92 93{ 94 my $test = 'netscape'; 95 my $key = 'apache'; 96 my $value = 'ok'; 97 my $cookie = qq{$key=$value}; 98 ok t_cmp($value, 99 GET_BODY("$script?test=$test&key=$key", Cookie => $cookie), 100 $test); 101} 102{ 103 my $test = 'rfc'; 104 my $key = 'apache'; 105 my $value = 'ok'; 106 my $cookie = qq{\$Version="1"; $key="$value"; \$Path="$location"}; 107 ok t_cmp(qq{"$value"}, 108 GET_BODY("$script?test=$test&key=$key", Cookie => $cookie), 109 $test); 110} 111{ 112 my $test = 'encoded value with space'; 113 my $key = 'apache'; 114 my $value = 'okie dokie'; 115 my $cookie = "$key=" . join '', 116 map {/ / ? '+' : sprintf '%%%.2X', ord} split //, $value; 117 ok t_cmp($value, 118 GET_BODY("$script?test=$test&key=$key", Cookie => $cookie), 119 $test); 120} 121{ 122 my $test = 'bake'; 123 my $key = 'apache'; 124 my $value = 'ok'; 125 my $cookie = "$key=$value"; 126 my ($header) = GET_HEAD("$script?test=$test&key=$key", 127 Cookie => $cookie) =~ /^#Set-Cookie:\s+(.+)/m; 128 ok t_cmp($cookie, $header, $test); 129} 130{ 131 my $test = 'bake2'; 132 my $key = 'apache'; 133 my $value = 'ok'; 134 my $cookie = qq{\$Version="1"; $key="$value"; \$Path="$location"}; 135 my ($header) = GET_HEAD("$script?test=$test&key=$key", 136 Cookie => $cookie) =~ /^#Set-Cookie2:\s+(.+)/m; 137 ok t_cmp(qq{$key="$value"; Version=1; path="$location"}, $header, $test); 138} 139