1*0Sstevel@tonic-gate#!/usr/local/bin/perl -w 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gate# Test ability to retrieve HTTP request info 4*0Sstevel@tonic-gate######################### We start with some black magic to print on failure. 5*0Sstevel@tonic-gateuse lib '.','../blib/lib','../blib/arch'; 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gateBEGIN {$| = 1; print "1..33\n"; } 8*0Sstevel@tonic-gateEND {print "not ok 1\n" unless $loaded;} 9*0Sstevel@tonic-gateuse CGI (); 10*0Sstevel@tonic-gateuse Config; 11*0Sstevel@tonic-gate$loaded = 1; 12*0Sstevel@tonic-gateprint "ok 1\n"; 13*0Sstevel@tonic-gate 14*0Sstevel@tonic-gate######################### End of black magic. 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gate# util 17*0Sstevel@tonic-gatesub test { 18*0Sstevel@tonic-gate local($^W) = 0; 19*0Sstevel@tonic-gate my($num, $true,$msg) = @_; 20*0Sstevel@tonic-gate print($true ? "ok $num\n" : "not ok $num $msg\n"); 21*0Sstevel@tonic-gate} 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gate# Set up a CGI environment 24*0Sstevel@tonic-gate$ENV{REQUEST_METHOD} = 'GET'; 25*0Sstevel@tonic-gate$ENV{QUERY_STRING} = 'game=chess&game=checkers&weather=dull'; 26*0Sstevel@tonic-gate$ENV{PATH_INFO} = '/somewhere/else'; 27*0Sstevel@tonic-gate$ENV{PATH_TRANSLATED} = '/usr/local/somewhere/else'; 28*0Sstevel@tonic-gate$ENV{SCRIPT_NAME} = '/cgi-bin/foo.cgi'; 29*0Sstevel@tonic-gate$ENV{SERVER_PROTOCOL} = 'HTTP/1.0'; 30*0Sstevel@tonic-gate$ENV{SERVER_PORT} = 8080; 31*0Sstevel@tonic-gate$ENV{SERVER_NAME} = 'the.good.ship.lollypop.com'; 32*0Sstevel@tonic-gate$ENV{REQUEST_URI} = "$ENV{SCRIPT_NAME}$ENV{PATH_INFO}?$ENV{QUERY_STRING}"; 33*0Sstevel@tonic-gate$ENV{HTTP_LOVE} = 'true'; 34*0Sstevel@tonic-gate 35*0Sstevel@tonic-gate$q = new CGI; 36*0Sstevel@tonic-gatetest(2,$q,"CGI::new()"); 37*0Sstevel@tonic-gatetest(3,$q->request_method eq 'GET',"CGI::request_method()"); 38*0Sstevel@tonic-gatetest(4,$q->query_string eq 'game=chess;game=checkers;weather=dull',"CGI::query_string()"); 39*0Sstevel@tonic-gatetest(5,$q->param() == 2,"CGI::param()"); 40*0Sstevel@tonic-gatetest(6,join(' ',sort $q->param()) eq 'game weather',"CGI::param()"); 41*0Sstevel@tonic-gatetest(7,$q->param('game') eq 'chess',"CGI::param()"); 42*0Sstevel@tonic-gatetest(8,$q->param('weather') eq 'dull',"CGI::param()"); 43*0Sstevel@tonic-gatetest(9,join(' ',$q->param('game')) eq 'chess checkers',"CGI::param()"); 44*0Sstevel@tonic-gatetest(10,$q->param(-name=>'foo',-value=>'bar'),'CGI::param() put'); 45*0Sstevel@tonic-gatetest(11,$q->param(-name=>'foo') eq 'bar','CGI::param() get'); 46*0Sstevel@tonic-gatetest(12,$q->query_string eq 'game=chess;game=checkers;weather=dull;foo=bar',"CGI::query_string() redux"); 47*0Sstevel@tonic-gatetest(13,$q->http('love') eq 'true',"CGI::http()"); 48*0Sstevel@tonic-gatetest(14,$q->script_name eq '/cgi-bin/foo.cgi',"CGI::script_name()"); 49*0Sstevel@tonic-gatetest(15,$q->url eq 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi',"CGI::url()"); 50*0Sstevel@tonic-gatetest(16,$q->self_url eq 51*0Sstevel@tonic-gate 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', 52*0Sstevel@tonic-gate "CGI::url()"); 53*0Sstevel@tonic-gatetest(17,$q->url(-absolute=>1) eq '/cgi-bin/foo.cgi','CGI::url(-absolute=>1)'); 54*0Sstevel@tonic-gatetest(18,$q->url(-relative=>1) eq 'foo.cgi','CGI::url(-relative=>1)'); 55*0Sstevel@tonic-gatetest(19,$q->url(-relative=>1,-path=>1) eq 'foo.cgi/somewhere/else','CGI::url(-relative=>1,-path=>1)'); 56*0Sstevel@tonic-gatetest(20,$q->url(-relative=>1,-path=>1,-query=>1) eq 57*0Sstevel@tonic-gate 'foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', 58*0Sstevel@tonic-gate 'CGI::url(-relative=>1,-path=>1,-query=>1)'); 59*0Sstevel@tonic-gate$q->delete('foo'); 60*0Sstevel@tonic-gatetest(21,!$q->param('foo'),'CGI::delete()'); 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate$q->_reset_globals; 63*0Sstevel@tonic-gate$ENV{QUERY_STRING}='mary+had+a+little+lamb'; 64*0Sstevel@tonic-gatetest(22,$q=new CGI,"CGI::new() redux"); 65*0Sstevel@tonic-gatetest(23,join(' ',$q->keywords) eq 'mary had a little lamb','CGI::keywords'); 66*0Sstevel@tonic-gatetest(24,join(' ',$q->param('keywords')) eq 'mary had a little lamb','CGI::keywords'); 67*0Sstevel@tonic-gatetest(25,$q=new CGI('foo=bar&foo=baz'),"CGI::new() redux"); 68*0Sstevel@tonic-gatetest(26,$q->param('foo') eq 'bar','CGI::param() redux'); 69*0Sstevel@tonic-gatetest(27,$q=new CGI({'foo'=>'bar','bar'=>'froz'}),"CGI::new() redux 2"); 70*0Sstevel@tonic-gatetest(28,$q->param('bar') eq 'froz',"CGI::param() redux 2"); 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate# test tied interface 73*0Sstevel@tonic-gatemy $p = $q->Vars; 74*0Sstevel@tonic-gatetest(29,$p->{bar} eq 'froz',"tied interface fetch"); 75*0Sstevel@tonic-gate$p->{bar} = join("\0",qw(foo bar baz)); 76*0Sstevel@tonic-gatetest(30,join(' ',$q->param('bar')) eq 'foo bar baz','tied interface store'); 77*0Sstevel@tonic-gate 78*0Sstevel@tonic-gate# test posting 79*0Sstevel@tonic-gate$q->_reset_globals; 80*0Sstevel@tonic-gateif ($Config{d_fork}) { 81*0Sstevel@tonic-gate $test_string = 'game=soccer&game=baseball&weather=nice'; 82*0Sstevel@tonic-gate $ENV{REQUEST_METHOD}='POST'; 83*0Sstevel@tonic-gate $ENV{CONTENT_LENGTH}=length($test_string); 84*0Sstevel@tonic-gate $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; 85*0Sstevel@tonic-gate if (open(CHILD,"|-")) { # cparent 86*0Sstevel@tonic-gate print CHILD $test_string; 87*0Sstevel@tonic-gate close CHILD; 88*0Sstevel@tonic-gate exit 0; 89*0Sstevel@tonic-gate } 90*0Sstevel@tonic-gate # at this point, we're in a new (child) process 91*0Sstevel@tonic-gate test(31,$q=new CGI,"CGI::new() from POST"); 92*0Sstevel@tonic-gate test(32,$q->param('weather') eq 'nice',"CGI::param() from POST"); 93*0Sstevel@tonic-gate test(33,$q->url_param('big_balls') eq 'basketball',"CGI::url_param()"); 94*0Sstevel@tonic-gate} else { 95*0Sstevel@tonic-gate print "ok 31 # Skip\n"; 96*0Sstevel@tonic-gate print "ok 32 # Skip\n"; 97*0Sstevel@tonic-gate print "ok 33 # Skip\n"; 98*0Sstevel@tonic-gate} 99