xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/CGI/t/cookie.t (revision 6287:9a1f5d2c8dd8)
10Sstevel@tonic-gate#!/usr/local/bin/perl -w
20Sstevel@tonic-gate
30Sstevel@tonic-gateuse lib qw(t/lib);
40Sstevel@tonic-gateuse strict;
50Sstevel@tonic-gate
60Sstevel@tonic-gate# Due to a bug in older versions of MakeMaker & Test::Harness, we must
70Sstevel@tonic-gate# ensure the blib's are in @INC, else we might use the core CGI.pm
80Sstevel@tonic-gateuse lib qw(blib/lib blib/arch);
90Sstevel@tonic-gate
10*6287Sps156622use Test::More tests => 96;
110Sstevel@tonic-gateuse CGI::Util qw(escape unescape);
120Sstevel@tonic-gateuse POSIX qw(strftime);
130Sstevel@tonic-gate
140Sstevel@tonic-gate#-----------------------------------------------------------------------------
150Sstevel@tonic-gate# make sure module loaded
160Sstevel@tonic-gate#-----------------------------------------------------------------------------
170Sstevel@tonic-gate
180Sstevel@tonic-gateBEGIN {use_ok('CGI::Cookie');}
190Sstevel@tonic-gate
200Sstevel@tonic-gatemy @test_cookie = (
210Sstevel@tonic-gate		   'foo=123; bar=qwerty; baz=wibble; qux=a1',
220Sstevel@tonic-gate		   'foo=123; bar=qwerty; baz=wibble;',
230Sstevel@tonic-gate		   'foo=vixen; bar=cow; baz=bitch; qux=politician',
240Sstevel@tonic-gate		   'foo=a%20phrase; bar=yes%2C%20a%20phrase; baz=%5Ewibble; qux=%27',
250Sstevel@tonic-gate		   );
260Sstevel@tonic-gate
270Sstevel@tonic-gate#-----------------------------------------------------------------------------
280Sstevel@tonic-gate# Test parse
290Sstevel@tonic-gate#-----------------------------------------------------------------------------
300Sstevel@tonic-gate
310Sstevel@tonic-gate{
320Sstevel@tonic-gate  my $result = CGI::Cookie->parse($test_cookie[0]);
330Sstevel@tonic-gate
340Sstevel@tonic-gate  is(ref($result), 'HASH', "Hash ref returned in scalar context");
350Sstevel@tonic-gate
360Sstevel@tonic-gate  my @result = CGI::Cookie->parse($test_cookie[0]);
370Sstevel@tonic-gate
380Sstevel@tonic-gate  is(@result, 8, "returns correct number of fields");
390Sstevel@tonic-gate
400Sstevel@tonic-gate  @result = CGI::Cookie->parse($test_cookie[1]);
410Sstevel@tonic-gate
420Sstevel@tonic-gate  is(@result, 6, "returns correct number of fields");
430Sstevel@tonic-gate
440Sstevel@tonic-gate  my %result = CGI::Cookie->parse($test_cookie[0]);
450Sstevel@tonic-gate
460Sstevel@tonic-gate  is($result{foo}->value, '123', "cookie foo is correct");
470Sstevel@tonic-gate  is($result{bar}->value, 'qwerty', "cookie bar is correct");
480Sstevel@tonic-gate  is($result{baz}->value, 'wibble', "cookie baz is correct");
490Sstevel@tonic-gate  is($result{qux}->value, 'a1', "cookie qux is correct");
500Sstevel@tonic-gate}
510Sstevel@tonic-gate
520Sstevel@tonic-gate#-----------------------------------------------------------------------------
530Sstevel@tonic-gate# Test fetch
540Sstevel@tonic-gate#-----------------------------------------------------------------------------
550Sstevel@tonic-gate
560Sstevel@tonic-gate{
570Sstevel@tonic-gate  # make sure there are no cookies in the environment
580Sstevel@tonic-gate  delete $ENV{HTTP_COOKIE};
590Sstevel@tonic-gate  delete $ENV{COOKIE};
600Sstevel@tonic-gate
610Sstevel@tonic-gate  my %result = CGI::Cookie->fetch();
620Sstevel@tonic-gate  ok(keys %result == 0, "No cookies in environment, returns empty list");
630Sstevel@tonic-gate
640Sstevel@tonic-gate  # now set a cookie in the environment and try again
650Sstevel@tonic-gate  $ENV{HTTP_COOKIE} = $test_cookie[2];
660Sstevel@tonic-gate  %result = CGI::Cookie->fetch();
670Sstevel@tonic-gate  ok(eq_set([keys %result], [qw(foo bar baz qux)]),
680Sstevel@tonic-gate     "expected cookies extracted");
690Sstevel@tonic-gate
700Sstevel@tonic-gate  is(ref($result{foo}), 'CGI::Cookie', 'Type of objects returned is correct');
710Sstevel@tonic-gate  is($result{foo}->value, 'vixen',      "cookie foo is correct");
720Sstevel@tonic-gate  is($result{bar}->value, 'cow',        "cookie bar is correct");
730Sstevel@tonic-gate  is($result{baz}->value, 'bitch',      "cookie baz is correct");
740Sstevel@tonic-gate  is($result{qux}->value, 'politician', "cookie qux is correct");
750Sstevel@tonic-gate
760Sstevel@tonic-gate  # Delete that and make sure it goes away
770Sstevel@tonic-gate  delete $ENV{HTTP_COOKIE};
780Sstevel@tonic-gate  %result = CGI::Cookie->fetch();
790Sstevel@tonic-gate  ok(keys %result == 0, "No cookies in environment, returns empty list");
800Sstevel@tonic-gate
810Sstevel@tonic-gate  # try another cookie in the other environment variable thats supposed to work
820Sstevel@tonic-gate  $ENV{COOKIE} = $test_cookie[3];
830Sstevel@tonic-gate  %result = CGI::Cookie->fetch();
840Sstevel@tonic-gate  ok(eq_set([keys %result], [qw(foo bar baz qux)]),
850Sstevel@tonic-gate     "expected cookies extracted");
860Sstevel@tonic-gate
870Sstevel@tonic-gate  is(ref($result{foo}), 'CGI::Cookie', 'Type of objects returned is correct');
880Sstevel@tonic-gate  is($result{foo}->value, 'a phrase', "cookie foo is correct");
890Sstevel@tonic-gate  is($result{bar}->value, 'yes, a phrase', "cookie bar is correct");
900Sstevel@tonic-gate  is($result{baz}->value, '^wibble', "cookie baz is correct");
910Sstevel@tonic-gate  is($result{qux}->value, "'", "cookie qux is correct");
920Sstevel@tonic-gate}
930Sstevel@tonic-gate
940Sstevel@tonic-gate#-----------------------------------------------------------------------------
950Sstevel@tonic-gate# Test raw_fetch
960Sstevel@tonic-gate#-----------------------------------------------------------------------------
970Sstevel@tonic-gate
980Sstevel@tonic-gate{
990Sstevel@tonic-gate  # make sure there are no cookies in the environment
1000Sstevel@tonic-gate  delete $ENV{HTTP_COOKIE};
1010Sstevel@tonic-gate  delete $ENV{COOKIE};
1020Sstevel@tonic-gate
1030Sstevel@tonic-gate  my %result = CGI::Cookie->raw_fetch();
1040Sstevel@tonic-gate  ok(keys %result == 0, "No cookies in environment, returns empty list");
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate  # now set a cookie in the environment and try again
1070Sstevel@tonic-gate  $ENV{HTTP_COOKIE} = $test_cookie[2];
1080Sstevel@tonic-gate  %result = CGI::Cookie->raw_fetch();
1090Sstevel@tonic-gate  ok(eq_set([keys %result], [qw(foo bar baz qux)]),
1100Sstevel@tonic-gate     "expected cookies extracted");
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate  is(ref($result{foo}), '', 'Plain scalar returned');
1130Sstevel@tonic-gate  is($result{foo}, 'vixen',      "cookie foo is correct");
1140Sstevel@tonic-gate  is($result{bar}, 'cow',        "cookie bar is correct");
1150Sstevel@tonic-gate  is($result{baz}, 'bitch',      "cookie baz is correct");
1160Sstevel@tonic-gate  is($result{qux}, 'politician', "cookie qux is correct");
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate  # Delete that and make sure it goes away
1190Sstevel@tonic-gate  delete $ENV{HTTP_COOKIE};
1200Sstevel@tonic-gate  %result = CGI::Cookie->raw_fetch();
1210Sstevel@tonic-gate  ok(keys %result == 0, "No cookies in environment, returns empty list");
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate  # try another cookie in the other environment variable thats supposed to work
1240Sstevel@tonic-gate  $ENV{COOKIE} = $test_cookie[3];
1250Sstevel@tonic-gate  %result = CGI::Cookie->raw_fetch();
1260Sstevel@tonic-gate  ok(eq_set([keys %result], [qw(foo bar baz qux)]),
1270Sstevel@tonic-gate     "expected cookies extracted");
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate  is(ref($result{foo}), '', 'Plain scalar returned');
1300Sstevel@tonic-gate  is($result{foo}, 'a%20phrase', "cookie foo is correct");
1310Sstevel@tonic-gate  is($result{bar}, 'yes%2C%20a%20phrase', "cookie bar is correct");
1320Sstevel@tonic-gate  is($result{baz}, '%5Ewibble', "cookie baz is correct");
1330Sstevel@tonic-gate  is($result{qux}, '%27', "cookie qux is correct");
1340Sstevel@tonic-gate}
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate#-----------------------------------------------------------------------------
1370Sstevel@tonic-gate# Test new
1380Sstevel@tonic-gate#-----------------------------------------------------------------------------
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate{
1410Sstevel@tonic-gate  # Try new with full information provided
1420Sstevel@tonic-gate  my $c = CGI::Cookie->new(-name    => 'foo',
1430Sstevel@tonic-gate			   -value   => 'bar',
1440Sstevel@tonic-gate			   -expires => '+3M',
1450Sstevel@tonic-gate			   -domain  => '.capricorn.com',
1460Sstevel@tonic-gate			   -path    => '/cgi-bin/database',
1470Sstevel@tonic-gate			   -secure  => 1
1480Sstevel@tonic-gate			  );
1490Sstevel@tonic-gate  is(ref($c), 'CGI::Cookie', 'new returns objects of correct type');
1500Sstevel@tonic-gate  is($c->name   , 'foo',               'name is correct');
1510Sstevel@tonic-gate  is($c->value  , 'bar',               'value is correct');
1520Sstevel@tonic-gate  like($c->expires, '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires in correct format');
1530Sstevel@tonic-gate  is($c->domain , '.capricorn.com',    'domain is correct');
1540Sstevel@tonic-gate  is($c->path   , '/cgi-bin/database', 'path is correct');
1550Sstevel@tonic-gate  ok($c->secure , 'secure attribute is set');
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate  # now try it with the only two manditory values (should also set the default path)
1580Sstevel@tonic-gate  $c = CGI::Cookie->new(-name    =>  'baz',
1590Sstevel@tonic-gate			-value   =>  'qux',
1600Sstevel@tonic-gate		       );
1610Sstevel@tonic-gate  is(ref($c), 'CGI::Cookie', 'new returns objects of correct type');
1620Sstevel@tonic-gate  is($c->name   , 'baz', 'name is correct');
1630Sstevel@tonic-gate  is($c->value  , 'qux', 'value is correct');
1640Sstevel@tonic-gate  ok(!defined $c->expires,       'expires is not set');
1650Sstevel@tonic-gate  ok(!defined $c->domain ,       'domain attributeis not set');
1660Sstevel@tonic-gate  is($c->path, '/',      'path atribute is set to default');
1670Sstevel@tonic-gate  ok(!defined $c->secure ,       'secure attribute is set');
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate# I'm really not happy about the restults of this section.  You pass
1700Sstevel@tonic-gate# the new method invalid arguments and it just merilly creates a
1710Sstevel@tonic-gate# broken object :-)
1720Sstevel@tonic-gate# I've commented them out because they currently pass but I don't
1730Sstevel@tonic-gate# think they should.  I think this is testing broken behaviour :-(
1740Sstevel@tonic-gate
1750Sstevel@tonic-gate#    # This shouldn't work
1760Sstevel@tonic-gate#    $c = CGI::Cookie->new(-name => 'baz' );
1770Sstevel@tonic-gate#
1780Sstevel@tonic-gate#    is(ref($c), 'CGI::Cookie', 'new returns objects of correct type');
1790Sstevel@tonic-gate#    is($c->name   , 'baz',     'name is correct');
1800Sstevel@tonic-gate#    ok(!defined $c->value, "Value is undefined ");
1810Sstevel@tonic-gate#    ok(!defined $c->expires, 'expires is not set');
1820Sstevel@tonic-gate#    ok(!defined $c->domain , 'domain attributeis not set');
1830Sstevel@tonic-gate#    is($c->path   , '/', 'path atribute is set to default');
1840Sstevel@tonic-gate#    ok(!defined $c->secure , 'secure attribute is set');
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate}
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate#-----------------------------------------------------------------------------
1890Sstevel@tonic-gate# Test as_string
1900Sstevel@tonic-gate#-----------------------------------------------------------------------------
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate{
1930Sstevel@tonic-gate  my $c = CGI::Cookie->new(-name    => 'Jam',
1940Sstevel@tonic-gate			   -value   => 'Hamster',
1950Sstevel@tonic-gate			   -expires => '+3M',
1960Sstevel@tonic-gate			   -domain  => '.pie-shop.com',
1970Sstevel@tonic-gate			   -path    => '/',
1980Sstevel@tonic-gate			   -secure  => 1
1990Sstevel@tonic-gate			  );
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate  my $name = $c->name;
2020Sstevel@tonic-gate  like($c->as_string, "/$name/", "Stringified cookie contains name");
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate  my $value = $c->value;
2050Sstevel@tonic-gate  like($c->as_string, "/$value/", "Stringified cookie contains value");
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate  my $expires = $c->expires;
2080Sstevel@tonic-gate  like($c->as_string, "/$expires/", "Stringified cookie contains expires");
2090Sstevel@tonic-gate
2100Sstevel@tonic-gate  my $domain = $c->domain;
2110Sstevel@tonic-gate  like($c->as_string, "/$domain/", "Stringified cookie contains domain");
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate  my $path = $c->path;
2140Sstevel@tonic-gate  like($c->as_string, "/$path/", "Stringified cookie contains path");
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate  like($c->as_string, '/secure/', "Stringified cookie contains secure");
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate  $c = CGI::Cookie->new(-name    =>  'Hamster-Jam',
2190Sstevel@tonic-gate			-value   =>  'Tulip',
2200Sstevel@tonic-gate		       );
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate  $name = $c->name;
2230Sstevel@tonic-gate  like($c->as_string, "/$name/", "Stringified cookie contains name");
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate  $value = $c->value;
2260Sstevel@tonic-gate  like($c->as_string, "/$value/", "Stringified cookie contains value");
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate  ok($c->as_string !~ /expires/, "Stringified cookie has no expires field");
2290Sstevel@tonic-gate
2300Sstevel@tonic-gate  ok($c->as_string !~ /domain/, "Stringified cookie has no domain field");
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate  $path = $c->path;
2330Sstevel@tonic-gate  like($c->as_string, "/$path/", "Stringified cookie contains path");
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate  ok($c->as_string !~ /secure/, "Stringified cookie does not contain secure");
2360Sstevel@tonic-gate}
2370Sstevel@tonic-gate
2380Sstevel@tonic-gate#-----------------------------------------------------------------------------
2390Sstevel@tonic-gate# Test compare
2400Sstevel@tonic-gate#-----------------------------------------------------------------------------
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate{
2430Sstevel@tonic-gate  my $c1 = CGI::Cookie->new(-name    => 'Jam',
2440Sstevel@tonic-gate			    -value   => 'Hamster',
2450Sstevel@tonic-gate			    -expires => '+3M',
2460Sstevel@tonic-gate			    -domain  => '.pie-shop.com',
2470Sstevel@tonic-gate			    -path    => '/',
2480Sstevel@tonic-gate			    -secure  => 1
2490Sstevel@tonic-gate			   );
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate  # have to use $c1->expires because the time will occasionally be
2520Sstevel@tonic-gate  # different between the two creates causing spurious failures.
2530Sstevel@tonic-gate  my $c2 = CGI::Cookie->new(-name    => 'Jam',
2540Sstevel@tonic-gate			    -value   => 'Hamster',
2550Sstevel@tonic-gate			    -expires => $c1->expires,
2560Sstevel@tonic-gate			    -domain  => '.pie-shop.com',
2570Sstevel@tonic-gate			    -path    => '/',
2580Sstevel@tonic-gate			    -secure  => 1
2590Sstevel@tonic-gate			   );
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate  # This looks titally whacked, but it does the -1, 0, 1 comparison
2620Sstevel@tonic-gate  # thing so 0 means they match
2630Sstevel@tonic-gate  is($c1->compare("$c1"), 0, "Cookies are identical");
2640Sstevel@tonic-gate  is($c1->compare("$c2"), 0, "Cookies are identical");
2650Sstevel@tonic-gate
2660Sstevel@tonic-gate  $c1 = CGI::Cookie->new(-name   => 'Jam',
2670Sstevel@tonic-gate			 -value  => 'Hamster',
2680Sstevel@tonic-gate			 -domain => '.foo.bar.com'
2690Sstevel@tonic-gate			);
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate  # have to use $c1->expires because the time will occasionally be
2720Sstevel@tonic-gate  # different between the two creates causing spurious failures.
2730Sstevel@tonic-gate  $c2 = CGI::Cookie->new(-name    =>  'Jam',
2740Sstevel@tonic-gate			 -value   =>  'Hamster',
2750Sstevel@tonic-gate			);
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate  # This looks titally whacked, but it does the -1, 0, 1 comparison
2780Sstevel@tonic-gate  # thing so 0 (i.e. false) means they match
2790Sstevel@tonic-gate  is($c1->compare("$c1"), 0, "Cookies are identical");
2800Sstevel@tonic-gate  ok($c1->compare("$c2"), "Cookies are not identical");
2810Sstevel@tonic-gate
2820Sstevel@tonic-gate  $c2->domain('.foo.bar.com');
2830Sstevel@tonic-gate  is($c1->compare("$c2"), 0, "Cookies are identical");
2840Sstevel@tonic-gate}
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate#-----------------------------------------------------------------------------
2870Sstevel@tonic-gate# Test name, value, domain, secure, expires and path
2880Sstevel@tonic-gate#-----------------------------------------------------------------------------
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate{
2910Sstevel@tonic-gate  my $c = CGI::Cookie->new(-name    => 'Jam',
2920Sstevel@tonic-gate			   -value   => 'Hamster',
2930Sstevel@tonic-gate			   -expires => '+3M',
2940Sstevel@tonic-gate			   -domain  => '.pie-shop.com',
2950Sstevel@tonic-gate			   -path    => '/',
2960Sstevel@tonic-gate			   -secure  => 1
2970Sstevel@tonic-gate			   );
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate  is($c->name,          'Jam',   'name is correct');
3000Sstevel@tonic-gate  is($c->name('Clash'), 'Clash', 'name is set correctly');
3010Sstevel@tonic-gate  is($c->name,          'Clash', 'name now returns updated value');
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate  # this is insane!  it returns a simple scalar but can't accept one as
3040Sstevel@tonic-gate  # an argument, you have to give it an arrary ref.  It's totally
3050Sstevel@tonic-gate  # inconsitent with these other methods :-(
3060Sstevel@tonic-gate  is($c->value,           'Hamster', 'value is correct');
3070Sstevel@tonic-gate  is($c->value(['Gerbil']), 'Gerbil',  'value is set correctly');
3080Sstevel@tonic-gate  is($c->value,           'Gerbil',  'value now returns updated value');
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate  my $exp = $c->expires;
3110Sstevel@tonic-gate  like($c->expires,         '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires is correct');
3120Sstevel@tonic-gate  like($c->expires('+12h'), '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires is set correctly');
3130Sstevel@tonic-gate  like($c->expires,         '/^[a-z]{3},\s*\d{2}-[a-z]{3}-\d{4}/i', 'expires now returns updated value');
3140Sstevel@tonic-gate  isnt($c->expires, $exp, "Expiry time has changed");
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate  is($c->domain,                  '.pie-shop.com', 'domain is correct');
3170Sstevel@tonic-gate  is($c->domain('.wibble.co.uk'), '.wibble.co.uk', 'domain is set correctly');
3180Sstevel@tonic-gate  is($c->domain,                  '.wibble.co.uk', 'domain now returns updated value');
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate  is($c->path,             '/',        'path is correct');
3210Sstevel@tonic-gate  is($c->path('/basket/'), '/basket/', 'path is set correctly');
3220Sstevel@tonic-gate  is($c->path,             '/basket/', 'path now returns updated value');
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate  ok($c->secure,     'secure attribute is set');
3250Sstevel@tonic-gate  ok(!$c->secure(0), 'secure attribute is cleared');
3260Sstevel@tonic-gate  ok(!$c->secure,    'secure attribute is cleared');
3270Sstevel@tonic-gate}
328*6287Sps156622
329*6287Sps156622#-----------------------------------------------------------------------------
330*6287Sps156622# Apache2?::Cookie compatibility.
331*6287Sps156622#-----------------------------------------------------------------------------
332*6287Sps156622APACHEREQ: {
333*6287Sps156622    my $r = Apache::Faker->new;
334*6287Sps156622    isa_ok $r, 'Apache';
335*6287Sps156622    ok my $c = CGI::Cookie->new(
336*6287Sps156622        $r,
337*6287Sps156622        -name  => 'Foo',
338*6287Sps156622        -value => 'Bar',
339*6287Sps156622    ), 'Pass an Apache object to the CGI::Cookie constructor';
340*6287Sps156622    isa_ok $c, 'CGI::Cookie';
341*6287Sps156622    ok $c->bake($r), 'Bake the cookie';
342*6287Sps156622    ok eq_array( $r->{check}, [ 'Set-Cookie', $c->as_string ]),
343*6287Sps156622        'bake() should call headers_out->set()';
344*6287Sps156622
345*6287Sps156622    $r = Apache2::Faker->new;
346*6287Sps156622    isa_ok $r, 'Apache2::RequestReq';
347*6287Sps156622    ok $c = CGI::Cookie->new(
348*6287Sps156622        $r,
349*6287Sps156622        -name  => 'Foo',
350*6287Sps156622        -value => 'Bar',
351*6287Sps156622    ), 'Pass an Apache::RequestReq object to the CGI::Cookie constructor';
352*6287Sps156622    isa_ok $c, 'CGI::Cookie';
353*6287Sps156622    ok $c->bake($r), 'Bake the cookie';
354*6287Sps156622    ok eq_array( $r->{check}, [ 'Set-Cookie', $c->as_string ]),
355*6287Sps156622        'bake() should call headers_out->set()';
356*6287Sps156622}
357*6287Sps156622
358*6287Sps156622
359*6287Sps156622package Apache::Faker;
360*6287Sps156622sub new { bless {}, shift }
361*6287Sps156622sub isa {
362*6287Sps156622    my ($self, $pkg) = @_;
363*6287Sps156622    return $pkg eq 'Apache';
364*6287Sps156622}
365*6287Sps156622sub headers_out { shift }
366*6287Sps156622sub add { shift->{check} = \@_; }
367*6287Sps156622
368*6287Sps156622package Apache2::Faker;
369*6287Sps156622sub new { bless {}, shift }
370*6287Sps156622sub isa {
371*6287Sps156622    my ($self, $pkg) = @_;
372*6287Sps156622    return $pkg eq 'Apache2::RequestReq';
373*6287Sps156622}
374*6287Sps156622sub headers_out { shift }
375*6287Sps156622sub add { shift->{check} = \@_; }
376