Commit 9a23ea298c0c2154c9bfdd4b37677a4bbbe34c46

Make tests use Test.pm
  
1print "1..45\n";
1#!perl -w
22
3use Test;
4plan tests => 62;
5
36#use LWP::Debug '+';
47use HTTP::Cookies;
58use HTTP::Request;
6060$req = HTTP::Request->new(GET => "http://www.acme.com/");
6161$c->add_cookie_header($req);
6262
63print "not " unless $req->header("Cookie") eq "CUSTOMER=WILE_E_COYOTE" &&
64 $req->header("Cookie2") eq "\$Version=\"1\"";
65print "ok 1\n";
63ok($req->header("Cookie"), "CUSTOMER=WILE_E_COYOTE");
64ok($req->header("Cookie2"), "\$Version=\"1\"");
6665
6766$res->request($req);
6867$res->header("Set-Cookie" => "PART_NUMBER=ROCKET_LAUNCHER_0001; path=/");
7171$c->add_cookie_header($req);
7272
7373$h = $req->header("Cookie");
74print "not " unless $h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/ &&
75 $h =~ /CUSTOMER=WILE_E_COYOTE/;
76print "ok 2\n";
74ok($h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/);
75ok($h =~ /CUSTOMER=WILE_E_COYOTE/);
7776
7877$res->request($req);
7978$res->header("Set-Cookie", "SHIPPING=FEDEX; path=/foo");
8282$c->add_cookie_header($req);
8383
8484$h = $req->header("Cookie");
85print "not " unless $h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/ &&
86 $h =~ /CUSTOMER=WILE_E_COYOTE/ &&
87 $h !~ /SHIPPING=FEDEX/;
88print "ok 3\n";
85ok($h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/);
86ok($h =~ /CUSTOMER=WILE_E_COYOTE/);
87ok($h !~ /SHIPPING=FEDEX/);
8988
9089
9190$req = HTTP::Request->new(GET => "http://www.acme.com/foo/");
9291$c->add_cookie_header($req);
9392
9493$h = $req->header("Cookie");
95print "not " unless $h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/ &&
96 $h =~ /CUSTOMER=WILE_E_COYOTE/ &&
97 $h =~ /^SHIPPING=FEDEX;/;
98print "ok 4\n";
94ok($h =~ /PART_NUMBER=ROCKET_LAUNCHER_0001/);
95ok($h =~ /CUSTOMER=WILE_E_COYOTE/);
96ok($h =~ /^SHIPPING=FEDEX;/);
9997
10098print $c->as_string;
10199
133133$req = HTTP::Request->new(GET => "http://www.acme.com/");
134134$c->add_cookie_header($req);
135135
136print "not " unless $req->header("Cookie") eq "PART_NUMBER=ROCKET_LAUNCHER_0001";
137print "ok 5\n";
136ok($req->header("Cookie"), "PART_NUMBER=ROCKET_LAUNCHER_0001");
138137
139138$res->request($req);
140139$res->header("Set-Cookie", "PART_NUMBER=RIDING_ROCKET_0023; path=/ammo");
142142$req = HTTP::Request->new(GET => "http://www.acme.com/ammo");
143143$c->add_cookie_header($req);
144144
145print "not " unless $req->header("Cookie") =~
146 /^PART_NUMBER=RIDING_ROCKET_0023;\s*PART_NUMBER=ROCKET_LAUNCHER_0001/;
147print "ok 6\n";
145ok($req->header("Cookie") =~
146 /^PART_NUMBER=RIDING_ROCKET_0023;\s*PART_NUMBER=ROCKET_LAUNCHER_0001/);
148147
149148print $c->as_string;
150149undef($c);
155155
156156$c = HTTP::Cookies->new;
157157$c->extract_cookies(HTTP::Response->new("200", "OK"));
158print "not " if count_cookies($c) != 0;
159print "ok 7\n";
158ok(count_cookies($c), 0);
160159
161160
162161#-------------------------------------------------------------------
187187
188188$cookie = interact($c, 'http://www.acme.com/acme/login',
189189 'Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"');
190print "not " if $cookie;
191print "ok 8\n";
190ok(!$cookie);
192191
193192#
194193# 3. User Agent -> Server
208208
209209$cookie = interact($c, 'http://www.acme.com/acme/pickitem',
210210 'Part_Number="Rocket_Launcher_0001"; Version="1"; Path="/acme"');
211print "not " unless $cookie =~ m(^\$Version="?1"?; Customer="?WILE_E_COYOTE"?; \$Path="/acme"$);
212print "ok 9\n";
211ok($cookie =~ m(^\$Version="?1"?; Customer="?WILE_E_COYOTE"?; \$Path="/acme"$));
213212
214213#
215214# 5. User Agent -> Server
231231$cookie = interact($c, "http://www.acme.com/acme/shipping",
232232 'Shipping="FedEx"; Version="1"; Path="/acme"');
233233
234print "not " unless $cookie =~ /^\$Version="?1"?;/ &&
235 $cookie =~ /Part_Number="?Rocket_Launcher_0001"?;\s*\$Path="\/acme"/ &&
236 $cookie =~ /Customer="?WILE_E_COYOTE"?;\s*\$Path="\/acme"/;
237print "ok 10\n";
234ok($cookie =~ /^\$Version="?1"?;/);
235ok($cookie =~ /Part_Number="?Rocket_Launcher_0001"?;\s*\$Path="\/acme"/);
236ok($cookie =~ /Customer="?WILE_E_COYOTE"?;\s*\$Path="\/acme"/);
238237
239238#
240239# 7. User Agent -> Server
255255
256256$cookie = interact($c, "http://www.acme.com/acme/process");
257257print "FINAL COOKIE: $cookie\n";
258print "not " unless $cookie =~ /Shipping="?FedEx"?;\s*\$Path="\/acme"/ &&
259 $cookie =~ /WILE_E_COYOTE/;
260print "ok 11\n";
258ok($cookie =~ /Shipping="?FedEx"?;\s*\$Path="\/acme"/);
259ok($cookie =~ /WILE_E_COYOTE/);
261260
262261#
263262# The user agent makes a series of requests on the origin server, after
304304# than once.
305305
306306$cookie = interact($c, "http://www.acme.com/acme/ammo/...");
307print "not " unless $cookie =~ /Riding_Rocket_0023.*Rocket_Launcher_0001/;
308print "ok 12\n";
307ok($cookie =~ /Riding_Rocket_0023.*Rocket_Launcher_0001/);
309308
310309# A subsequent request by the user agent to the (same) server for a URL of
311310# the form /acme/parts/ would include the following request header:
316316# the server.
317317
318318$cookie = interact($c, "http://www.acme.com/acme/parts/");
319print "not " unless $cookie =~ /Rocket_Launcher_0001/ &&
320 $cookie !~ /Riding_Rocket_0023/;
321print "ok 13\n";
319ok($cookie =~ /Rocket_Launcher_0001/);
320ok($cookie !~ /Riding_Rocket_0023/);
322321
323322print $c->as_string;
324323
329329
330330# illegal domain (no embedded dots)
331331$cookie = interact($c, "http://www.acme.com", 'foo=bar; domain=".com"');
332print "not " if count_cookies($c) > 0;
333print "ok 14\n";
332ok(count_cookies($c), 0);
334333
335334# legal domain
336335$cookie = interact($c, "http://www.acme.com", 'foo=bar; domain="acme.com"');
337print "not " if count_cookies($c) != 1;
338print "ok 15\n";
336ok(count_cookies($c), 1);
339337
340338# illegal domain (host prefix "www.a" contains a dot)
341339$cookie = interact($c, "http://www.a.acme.com", 'foo=bar; domain="acme.com"');
342print "not " if count_cookies($c) != 1;
343print "ok 16\n";
340ok(count_cookies($c), 1);
344341
345342# legal domain
346343$cookie = interact($c, "http://www.a.acme.com", 'foo=bar; domain=".a.acme.com"');
347print "not " if count_cookies($c) != 2;
348print "ok 17\n";
344ok(count_cookies($c), 2);
349345
350346# can't use a IP-address as domain
351347$cookie = interact($c, "http://125.125.125.125", 'foo=bar; domain="125.125.125"');
352print "not " if count_cookies($c) != 2;
353print "ok 18\n";
348ok(count_cookies($c), 2);
354349
355350# illegal path (must be prefix of request path)
356351$cookie = interact($c, "http://www.sol.no", 'foo=bar; domain=".sol.no"; path="/foo"');
357print "not " if count_cookies($c) != 2;
358print "ok 19\n";
352ok(count_cookies($c), 2);
359353
360354# legal path
361355$cookie = interact($c, "http://www.sol.no/foo/bar", 'foo=bar; domain=".sol.no"; path="/foo"');
362print "not " if count_cookies($c) != 3;
363print "ok 20\n";
356ok(count_cookies($c), 3);
364357
365358# illegal port (request-port not in list)
366359$cookie = interact($c, "http://www.sol.no", 'foo=bar; domain=".sol.no"; port="90,100"');
367print "not " if count_cookies($c) != 3;
368print "ok 21\n";
360ok(count_cookies($c), 3);
369361
370362# legal port
371363$cookie = interact($c, "http://www.sol.no", 'foo=bar; domain=".sol.no"; port="90,100, 80,8080"; max-age=100; Comment = "Just kidding! (\"|\\\\) "');
372print "not " if count_cookies($c) != 4;
373print "ok 22\n";
364ok(count_cookies($c), 4);
374365
375366# port attribute without any value (current port)
376367$cookie = interact($c, "http://www.sol.no", 'foo9=bar; domain=".sol.no"; port; max-age=100;');
377print "not " if count_cookies($c) != 5;
378print "ok 23\n";
368ok(count_cookies($c), 5);
379369
380370# encoded path
381371$cookie = interact($c, "http://www.sol.no/foo/", 'foo8=bar; path="/%66oo"');
382print "not " if count_cookies($c) != 6;
383print "ok 24\n";
372ok(count_cookies($c), 6);
384373
385374my $file = "lwp-cookies-$$.txt";
386375$c->save($file);
380380$c->load($file);
381381unlink($file) || warn "Can't unlink $file: $!";
382382
383print "not " unless $old eq $c->as_string;
384print "ok 25\n";
383ok($old, $c->as_string);
385384
386385undef($c);
387386
392392print $c->as_string;
393393
394394$cookie = interact($c, "http://www.acme.com/foo%2f%25/@@%0anewå/æøå", "bar=baz; path=\"/foo/\"; version=1");
395print "not " unless $cookie =~ /foo=bar/ && $cookie =~ /^\$version=\"?1\"?/i;
396print "ok 26\n";
395ok($cookie =~ /foo=bar/);
396ok($cookie =~ /^\$version=\"?1\"?/i);
397397
398398$cookie = interact($c, "http://www.acme.com/foo/%25/@@%0anewå/æøå");
399print "not " if $cookie;
400print "ok 27\n";
399ok(!$cookie);
401400
402401undef($c);
403402
412412undef($c);
413413
414414$c = HTTP::Cookies::Netscape->new(file => $file);
415print "not " unless count_cookies($c) == 1; # 2 of them discarded on save
416print "ok 28\n";
415ok(count_cookies($c), 1); # 2 of them discarded on save
417416
418print "not " unless $c->as_string =~ /foo1=bar/;
419print "ok 29\n";
417ok($c->as_string =~ /foo1=bar/);
420418undef($c);
421419unlink($file);
422420
445445$req = HTTP::Request->new(POST => URI->new("http://foo.bar.acme.com/foo"));
446446$c->add_cookie_header($req);
447447#print $req->as_string;
448print "not " unless $req->header("Cookie") =~ /PART_NUMBER=3,4/ &&
449 $req->header("Cookie") =~ /Customer=WILE_E_COYOTE/;
450print "ok 30\n";
448ok($req->header("Cookie") =~ /PART_NUMBER=3,4/);
449ok($req->header("Cookie") =~ /Customer=WILE_E_COYOTE/);
451450
452451
453
454452# Test handling of local intranet hostnames without a dot
455453$c->clear;
456454print "---\n";
457457
458458interact($c, "http://example/", "foo1=bar; PORT; Discard;");
459459$_=interact($c, "http://example/", 'foo2=bar; domain=".local"');
460print "not " unless /foo1=bar/;
461print "ok 31\n";
460ok(/foo1=bar/);
462461
463462$_=interact($c, "http://example/", 'foo3=bar');
464463$_=interact($c, "http://example/");
465464print "Cookie: $_\n";
466print "not " unless /foo2=bar/ && count_cookies($c) == 3;
467print "ok 32\n";
465ok(/foo2=bar/);
466ok(count_cookies($c), 3);
468467print $c->as_string;
469468
470469# Test for empty path
490490$c->add_cookie_header($req);
491491#print $req->as_string;
492492
493print "not " unless $req->header("Cookie") eq "JSESSIONID=ABCDERANDOM123" &&
494 $req->header("Cookie2") eq "\$Version=\"1\"";
495print "ok 33\n";
493ok($req->header("Cookie"), "JSESSIONID=ABCDERANDOM123");
494ok($req->header("Cookie2"), "\$Version=\"1\"");
496495
497496
498497# missing path in the request URI
499499$c->add_cookie_header($req);
500500#print $req->as_string;
501501
502print "not " unless $req->header("Cookie") eq "JSESSIONID=ABCDERANDOM123" &&
503 $req->header("Cookie2") eq "\$Version=\"1\"";
504print "ok 34\n";
502ok($req->header("Cookie"), "JSESSIONID=ABCDERANDOM123");
503ok($req->header("Cookie2"), "\$Version=\"1\"");
505504
506505# test mixing of Set-Cookie and Set-Cookie2 headers.
507506# Example from http://www.trip.com/trs/trip/flighttracker/flight_tracker_home.xsl
532532$c = HTTP::Cookies->new; # clear it
533533$c->extract_cookies($res);
534534print $c->as_string;
535print "not " unless $c->as_string eq <<'EOT'; print "ok 35\n";
535ok($c->as_string, <<'EOT');
536536Set-Cookie3: trip.appServer=1111-0000-x-024; path="/"; domain=.trip.com; path_spec; discard; version=0
537537Set-Cookie3: JSESSIONID=fkumjm7nt1.JS24; path="/trs"; domain=www.trip.com; path_spec; discard; version=1
538538EOT
560560$c->clear_temporary_cookies();
561561# How many now?
562562$c->scan( sub { $counter{"${_[2]}_after"}++ } );
563print "not " if # a permanent cookie got lost accidently
564 $counter{"perm_after"} != $counter{"perm_before"} or
565 # a session cookie hasn't been cleared
566 $counter{"session_after"} != 0 or
567 # we didn't have session cookies in the first place
568 $counter{"session_before"} == 0;
563ok($counter{"perm_after"}, $counter{"perm_before"}); # a permanent cookie got lost accidently
564ok($counter{"session_after"}, 0); # a session cookie hasn't been cleared
565ok($counter{"session_before"}, 3); # we didn't have session cookies in the first place
569566#print $c->as_string;
570print "ok 36\n";
571567
572568
573569# Test handling of 'secure ' attribute for classic cookies
580580$req = HTTP::Request->new(GET => "http://www.acme.com/");
581581$c->add_cookie_header($req);
582582
583print "not " if $req->header("Cookie");
584print "ok 37\n";
583ok(!$req->header("Cookie"));
585584
586585$req->uri->scheme("https");
587586$c->add_cookie_header($req);
588587
589print "not " unless $req->header("Cookie") eq "CUSTOMER=WILE_E_COYOTE";
590print "ok 38\n";
588ok($req->header("Cookie"), "CUSTOMER=WILE_E_COYOTE");
591589
592590#print $req->as_string;
593591#print $c->as_string;
593593
594594$req = HTTP::Request->new(GET => "ftp://ftp.activestate.com/");
595595$c->add_cookie_header($req);
596ok(!$req->header("Cookie"));
596597
597print "not " if $req->header("Cookie");
598print "ok 39\n";
599
600598$req = HTTP::Request->new(GET => "file:/etc/motd");
601599$c->add_cookie_header($req);
600ok(!$req->header("Cookie"));
602601
603print "not " if $req->header("Cookie");
604print "ok 40\n";
605
606602$req = HTTP::Request->new(GET => "mailto:gisle\@aas.no");
607603$c->add_cookie_header($req);
604ok(!$req->header("Cookie"));
608605
609print "not " if $req->header("Cookie");
610print "ok 41\n";
611606
612
613607# Test cookie called 'exipres' <https://rt.cpan.org/Ticket/Display.html?id=8108>
614608$c = HTTP::Cookies->new;
615609$req = HTTP::Request->new("GET" => "http://example.com");
612612$res->header("Set-Cookie" => "Expires=10101");
613613$c->extract_cookies($res);
614614#print $c->as_string;
615print "not " unless $c->as_string eq <<'EOT'; print "ok 42\n";
615ok($c->as_string, <<'EOT');
616616Set-Cookie3: Expires=10101; path="/"; domain=example.com; discard; version=0
617617EOT
618618
622622#print $res->as_string;
623623$c->extract_cookies($res);
624624#print $c->as_string;
625print "not " unless $c->as_string eq <<'EOT'; print "ok 43\n";
625ok($c->as_string, <<'EOT');
626626Set-Cookie3: CUSTOMER=WILE_E_COYOTE; path="/"; domain=example.com; path_spec; discard; version=0
627627EOT
628628
632632#print $res->as_string;
633633$c->extract_cookies($res);
634634#print $c->as_string;
635print "not " unless $c->as_string eq <<'EOT'; print "ok 44\n";
635ok($c->as_string, <<'EOT');
636636Set-Cookie3: CUSTOMER=WILE_E_COYOTE; path="/"; domain=example.com; path_spec; discard; version=0
637637EOT
638638
645645$req = HTTP::Request->new(GET => "http://www.example.com/foo");
646646$c->add_cookie_header($req);
647647#print $req->as_string;
648print "not " unless $req->header("Cookie") eq "foo=\"bar\"";
649print "ok 45\n";
648ok($req->header("Cookie"), "foo=\"bar\"");
650649
651650#-------------------------------------------------------------------
652651
t/base/date.t
(46 / 59)
  
1#!perl -w
2
3use strict;
4use Test;
5
6plan tests => 133;
7
18use HTTP::Date;
29
310require Time::Local if $^O eq "MacOS";
411my $offset = ($^O eq "MacOS") ? Time::Local::timegm(0,0,0,1,0,70) : 0;
512
6print "1..59\n";
7
8$no = 1;
9$| = 1;
10sub ok {
11 print "not " if $_[0];
12 print "ok $no\n";
13 $no++;
14}
15
1613# test str2time for supported dates. Test cases with 2 digit year
1714# will probably break in year 2044.
1815my(@tests) =
6969 my $t2 = str2time(lc($_), "GMT");
7070 my $t3 = str2time(uc($_), "GMT");
7171
72 $t = "UNDEF" unless defined $t;
73 print "'$_' => $t\n";
74 print $@ if $@;
75 print "not " if $t eq 'UNDEF' || $t != $time
76 || $t2 != $time
77 || $t3 != $time;
78 ok;
72 print "\n# '$_'\n";
73
74 ok($t, $time);
75 ok($t2, $time);
76 ok($t3, $time);
7977}
8078
8179# test time2str
82die "time2str failed"
83 unless time2str($time) eq 'Thu, 03 Feb 1994 00:00:00 GMT';
80ok(time2str($time), 'Thu, 03 Feb 1994 00:00:00 GMT');
8481
8582# test the 'ls -l' format with missing year$
8683# round to nearest minute 3 days ago.
8784$time = int((time - 3 * 24*60*60) /60)*60;
88($min, $hr, $mday, $mon) = (localtime $time)[1,2,3,4];
85my ($min, $hr, $mday, $mon) = (localtime $time)[1,2,3,4];
8986$mon = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon];
90$str = sprintf("$mon %02d %02d:%02d", $mday, $hr, $min);
91$t = str2time($str);
92$t = "UNDEF" unless defined $t;
93print "'$str' => $t ($time)\n";
94print "not " if $t != $time;
95ok;
87my $str = sprintf("$mon %02d %02d:%02d", $mday, $hr, $min);
88my $t = str2time($str);
89ok($t, $time);
9690
9791# try some garbage.
9892for (undef, '', 'Garbage',
112112 $bad++;
113113 }
114114 };
115 print defined($_) ? "'$_'\n" : "undef\n";
116 print $@ if $@;
117 print "not " if $bad;
118 ok;
115 print defined($_) ? "\n# '$_'\n" : "\n# undef\n";
116 ok(!$@);
117 ok(!$bad);
119118}
120119
121120print "Testing AM/PM gruff...\n";
124124
125125print "Testing time2iso functions\n";
126126
127$t = time2iso(str2time("11-12-96 0:00AM"));print "$t\n";
128ok($t ne "1996-11-12 00:00:00");
127$t = time2iso(str2time("11-12-96 0:00AM"));
128ok($t, "1996-11-12 00:00:00");
129129
130$t = time2iso(str2time("11-12-96 12:00AM"));print "$t\n";
131ok($t ne "1996-11-12 00:00:00");
130$t = time2iso(str2time("11-12-96 12:00AM"));
131ok($t, "1996-11-12 00:00:00");
132132
133$t = time2iso(str2time("11-12-96 0:00PM"));print "$t\n";
134ok($t ne "1996-11-12 12:00:00");
133$t = time2iso(str2time("11-12-96 0:00PM"));
134ok($t, "1996-11-12 12:00:00");
135135
136$t = time2iso(str2time("11-12-96 12:00PM"));print "$t\n";
137ok($t ne "1996-11-12 12:00:00");
136$t = time2iso(str2time("11-12-96 12:00PM"));
137ok($t, "1996-11-12 12:00:00");
138138
139139
140$t = time2iso(str2time("11-12-96 1:05AM"));print "$t\n";
141ok($t ne "1996-11-12 01:05:00");
140$t = time2iso(str2time("11-12-96 1:05AM"));
141ok($t, "1996-11-12 01:05:00");
142142
143$t = time2iso(str2time("11-12-96 12:05AM"));print "$t\n";
144ok($t ne "1996-11-12 00:05:00");
143$t = time2iso(str2time("11-12-96 12:05AM"));
144ok($t, "1996-11-12 00:05:00");
145145
146$t = time2iso(str2time("11-12-96 1:05PM"));print "$t\n";
147ok($t ne "1996-11-12 13:05:00");
146$t = time2iso(str2time("11-12-96 1:05PM"));
147ok($t, "1996-11-12 13:05:00");
148148
149$t = time2iso(str2time("11-12-96 12:05PM"));print "$t\n";
150ok($t ne "1996-11-12 12:05:00");
149$t = time2iso(str2time("11-12-96 12:05PM"));
150ok($t, "1996-11-12 12:05:00");
151151
152152$t = str2time("2000-01-01 00:00:01.234");
153153print "FRAC $t = ", time2iso($t), "\n";
154ok(abs(($t - int($t)) - 0.234) > 0.000001);
154ok(abs(($t - int($t)) - 0.234) < 0.000001);
155155
156156$a = time2iso;
157157$b = time2iso(500000);
158158print "LOCAL $a $b\n";
159$az = time2isoz;
160$bz = time2isoz(500000);
159my $az = time2isoz;
160my $bz = time2isoz(500000);
161161print "GMT $az $bz\n";
162162
163for ($a, $b) { ok if /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/; }
164for ($az, $bz) { ok if /^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$/; }
163for ($a, $b) { ok(/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d$/); }
164for ($az, $bz) { ok(/^\d{4}-\d\d-\d\d \d\d:\d\d:\d\dZ$/); }
165165
166166# Test the parse_date interface
167167use HTTP::Date qw(parse_date);
168168
169@d = parse_date("Jan 1 2001");
169my @d = parse_date("Jan 1 2001");
170170
171print "not " if defined(pop(@d)) ||
172 "@d" ne "2001 1 1 0 0 0";
173ok;
171ok(!defined(pop(@d)));
172ok("@d", "2001 1 1 0 0 0");
174173
175174# This test will break around year 2070
176print "not " unless parse_date("03-Feb-20") eq "2020-02-03 00:00:00";
177ok;
175ok(parse_date("03-Feb-20"), "2020-02-03 00:00:00");
178176
179177# This test will break around year 2048
180print "not " unless parse_date("03-Feb-98") eq "1998-02-03 00:00:00";
181ok;
178ok(parse_date("03-Feb-98"), "1998-02-03 00:00:00");
182179
183180print "HTTP::Date $HTTP::Date::VERSION\n";
  
1print "1..4\n";
1#!perl -w
22
3use strict;
4use Test;
5
6plan tests => 6;
7
38use HTTP::Response;
49use HTTP::Headers::Auth;
510
6$res = HTTP::Response->new(401);
11my $res = HTTP::Response->new(401);
712$res->push_header(WWW_Authenticate => qq(Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2"));
813$res->push_header(WWW_Authenticate => qq(Basic Realm="WallyWorld", foo=bar, bar=baz));
914
1015print $res->as_string;
1116
12%auth = $res->www_authenticate;
17my %auth = $res->www_authenticate;
1318
14print "not " unless keys(%auth) == 3;
15print "ok 1\n";
19ok(keys(%auth), 3);
1620
17print "not " unless $auth{basic}{realm} eq "WallyWorld" &&
18 $auth{bar}{realm} eq "WallyWorld2";
19print "ok 2\n";
21ok($auth{basic}{realm}, "WallyWorld");
22ok($auth{bar}{realm}, "WallyWorld2");
2023
2124$a = $res->www_authenticate;
22print "not " unless $a eq 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz';
23print "ok 3\n";
25ok($a, 'Foo realm="WallyWorld", foo=bar, Bar realm="WallyWorld2", Basic Realm="WallyWorld", foo=bar, bar=baz');
2426
2527$res->www_authenticate("Basic realm=foo1");
2628print $res->as_string;
2729
28$res->www_authenticate(Basic => {realm => foo2});
30$res->www_authenticate(Basic => {realm => "foo2"});
2931print $res->as_string;
3032
31$res->www_authenticate(Basic => [realm => foo3, foo=>33],
33$res->www_authenticate(Basic => [realm => "foo3", foo=>33],
3234 Digest => {nonce=>"bar", foo=>'foo'});
3335print $res->as_string;
3436
3537$_ = $res->as_string;
3638
37print "not " unless /WWW-Authenticate: Basic realm="foo3", foo=33/ &&
38 (/WWW-Authenticate: Digest nonce=bar, foo=foo/ ||
39 /WWW-Authenticate: Digest foo=foo, nonce=bar/);
40print "ok 4\n";
39ok(/WWW-Authenticate: Basic realm="foo3", foo=33/);
40ok(/WWW-Authenticate: Digest nonce=bar, foo=foo/ ||
41 /WWW-Authenticate: Digest foo=foo, nonce=bar/);
  
1print "1..4\n";
1#!perl -w
22
3use strict;
4use Test;
5
6plan tests => 4;
7
38require HTTP::Headers::ETag;
49
5$h = HTTP::Headers->new;
10my $h = HTTP::Headers->new;
11
612$h->etag("tag1");
7print "not " unless $h->etag eq qq("tag1");
8print "ok 1\n";
13ok($h->etag, qq("tag1"));
914
1015$h->etag("w/tag2");
11print "not " unless $h->etag eq qq(W/"tag2");
12print "ok 2\n";
16ok($h->etag, qq(W/"tag2"));
1317
1418$h->if_match(qq(W/"foo", bar, baz), "bar");
1519$h->if_none_match(333);
1620
1721$h->if_range("tag3");
18print "not " unless $h->if_range eq qq("tag3");
19print "ok 3\n";
22ok($h->if_range, qq("tag3"));
2023
21$t = time;
24my $t = time;
2225$h->if_range($t);
23print "not " unless $h->if_range == $t;
24print "ok 4\n";
25
26ok($h->if_range, $t);
2627
2728print $h->as_string;
  
1#!perl -w
2
13use strict;
4use Test;
5
26use HTTP::Headers::Util qw(split_header_words join_header_words);
37
4my $extra_tests = 2;
5
68my @s_tests = (
79
810 ["foo" => "foo"],
2828 'Basic; realm="\"foo\\\\bar\""'],
2929);
3030
31print "1..", @s_tests + $extra_tests, "\n";
31plan tests => @s_tests + 2;
3232
33my $testno = 1;
34
35print "split_header_words() tests\n";
3633for (@s_tests) {
3734 my($arg, $expect) = @$_;
3835 my @arg = ref($arg) ? @$arg : $arg;
3936
4037 my $res = join_header_words(split_header_words(@arg));
41 if ($res ne $expect) {
42 print "\nUnexpected result: '$res'\n";
43 print " Expected: '$expect'\n";
44 print " when parsing '", join(", ", @arg), "'\n";
45 eval {
46 require Data::Dumper;
47 my @p = split_header_words(@arg);
48 print Data::Dumper::Dumper(\@p);
49 };
50 print "not ";
51 }
52 print "ok ", $testno++, "\n";
38 ok($res, $expect);
5339}
5440
5541
56print "Extra tests\n";
42print "# Extra tests\n";
5743# some extra tests
58print "not " unless join_header_words("foo" => undef, "bar" => "baz")
59 eq "foo; bar=baz";
60print "ok ", $testno++, "\n";
61
62print "not " unless join_header_words() eq "";
63print "ok ", $testno++, "\n";
44ok(join_header_words("foo" => undef, "bar" => "baz"), "foo; bar=baz");
45ok(join_header_words(), "");
t/base/http.t
(38 / 46)
  
1#!./perl -w
1#!perl -w
22
3print "1..16\n";
4
53use strict;
4use Test;
5
6plan tests => 34;
67#use Data::Dump ();
78
89my $CRLF = "\015\012";
120120
121121#Data::Dump::dump($res);
122122
123print "not " unless $res->{code} eq "200" && $res->{content} eq "Hello\n";
124print "ok 1\n";
123ok($res->{code}, 200);
124ok($res->{content}, "Hello\n");
125125
126126$res = $h->request(GET => "/404");
127print "not " unless $res->{code} eq "404";
128print "ok 2\n";
127ok($res->{code}, 404);
129128
130129$res = $h->request(TRACE => "/foo");
131print "not " unless $res->{code} eq "200" &&
132 $res->{content} eq "TRACE /foo HTTP/1.1${CRLF}Keep-Alive: 300${CRLF}Connection: Keep-Alive${CRLF}Host: a${CRLF}${CRLF}";
133print "ok 3\n";
130ok($res->{code}, 200);
131ok($res->{content}, "TRACE /foo HTTP/1.1${CRLF}Keep-Alive: 300${CRLF}Connection: Keep-Alive${CRLF}Host: a${CRLF}${CRLF}");
134132
135133# try to turn off keep alive
136134$h->keep_alive(0);
137135$res = $h->request(TRACE => "/foo");
138print "not " unless $res->{code} eq "200" &&
139 $res->{content} eq "TRACE /foo HTTP/1.1${CRLF}Connection: close${CRLF}Host: a${CRLF}${CRLF}";
140print "ok 4\n";
136ok($res->{code}, "200");
137ok($res->{content}, "TRACE /foo HTTP/1.1${CRLF}Connection: close${CRLF}Host: a${CRLF}${CRLF}");
141138
142139# try a bad one
143140$res = $h->request(GET => "/bad1", [], {laxed => 1});
144print "not " unless $res->{code} eq "200" && $res->{message} eq "OK" &&
145 "@{$res->{headers}}" eq "Server foo Content-type text/foo" &&
146 $res->{content} eq "abc\n";
147print "ok 5\n";
141ok($res->{code}, "200");
142ok($res->{message}, "OK");
143ok("@{$res->{headers}}", "Server foo Content-type text/foo");
144ok($res->{content}, "abc\n");
148145
149146$res = $h->request(GET => "/bad1");
150print "not " unless $res->{error} =~ /Bad header/ && !$res->{code};
151print "ok 6\n";
147ok($res->{error} =~ /Bad header/);
148ok(!$res->{code});
152149$h = undef; # it is in a bad state now
153150
154151$h = HTTP->new("a") || die; # reconnect
155152$res = $h->request(GET => "/09", [], {laxed => 1});
156print "not " unless $res->{code} eq "200" && $res->{message} eq "Assumed OK" &&
157 $res->{content} eq "Hello${CRLF}World!${CRLF}" &&
158 $h->peer_http_version eq "0.9";
159print "ok 7\n";
153ok($res->{code}, "200");
154ok($res->{message}, "Assumed OK");
155ok($res->{content}, "Hello${CRLF}World!${CRLF}");
156ok($h->peer_http_version, "0.9");
160157
161158$res = $h->request(GET => "/09");
162print "not " unless $res->{error} =~ /^Bad response status line: 'Hello'/;
163print "ok 8\n";
159ok($res->{error} =~ /^Bad response status line: 'Hello'/);
164160$h = undef; # it's in a bad state again
165161
166162$h = HTTP->new(Host => "a", KeepAlive => 1, ReadChunkSize => 1) || die; # reconnect
167163$res = $h->request(GET => "/chunked");
168print "not " unless $res->{code} eq "200" && $res->{content} eq "Hello" &&
169 "@{$res->{headers}}" eq "Transfer-Encoding chunked Content-MD5 xxx";
170print "ok 9\n";
164ok($res->{code}, 200);
165ok($res->{content}, "Hello");
166ok("@{$res->{headers}}", "Transfer-Encoding chunked Content-MD5 xxx");
171167
172168# once more
173169$res = $h->request(GET => "/chunked");
174print "not " unless $res->{code} eq "200" && $res->{content} eq "Hello" &&
175 "@{$res->{headers}}" eq "Transfer-Encoding chunked Content-MD5 xxx";
176print "ok 10\n";
170ok($res->{code}, "200");
171ok($res->{content}, "Hello");
172ok("@{$res->{headers}}", "Transfer-Encoding chunked Content-MD5 xxx");
177173
178174# test head
179175$res = $h->request(HEAD => "/head");
180print "not " unless $res->{code} eq "200" && $res->{content} eq "" &&
181 "@{$res->{headers}}" eq "Content-Length 16 Content-Type text/plain";
182print "ok 11\n";
176ok($res->{code}, "200");
177ok($res->{content}, "");
178ok("@{$res->{headers}}", "Content-Length 16 Content-Type text/plain");
183179
184180$res = $h->request(GET => "/");
185print "not " unless $res->{code} eq "200" && $res->{content} eq "Hello\n";
186print "ok 12\n";
187#use Data::Dump; Data::Dump::dump($res);
181ok($res->{code}, "200");
182ok($res->{content}, "Hello\n");
188183
189
190184$h = HTTP->new(Host => undef, PeerAddr => "a", );
191185$h->http_version("1.0");
192print "not " if defined $h->host;
193print "ok 13\n";
186ok(!defined $h->host);
194187$res = $h->request(TRACE => "/");
195print "not " unless $res->{code} eq "200" && $res->{content} eq "TRACE / HTTP/1.0\r\n\r\n";
196print "ok 14\n";
188ok($res->{code}, "200");
189ok($res->{content}, "TRACE / HTTP/1.0\r\n\r\n");
197190
198191# check that headers with colons at the start of values don't break
199192$res = $h->request(GET => '/colon-header');
200print "not " unless "@{$res->{headers}}" eq "Content-Type text/plain Content-Length 6 Bad-Header :foo";
201print "ok 15\n";
193ok("@{$res->{headers}}", "Content-Type text/plain Content-Length 6 Bad-Header :foo");
202194
203195require Net::HTTP;
204196eval {
205197 $h = Net::HTTP->new;
206198};
207199print "# $@";
208print "not " unless $@;
209print "ok 16\n";
200ok($@);
  
1print "1..10\n";
1#!perl -w
22
3use Test;
4plan tests => 10;
35
46use File::Listing;
57
5353
5454@dir = parse_dir($dir, undef, 'unix');
5555
56print int(@dir) ." lines found\n";
57@dir != 25 && print "not ";
58print "ok 1\n";
56ok(@dir, 25);
5957
6058for (@dir) {
6159 ($name, $type, $size, $mtime, $mode) = @$_;
6260 $size ||= 0; # ensure that it is defined
63 printf "%-25s $type %6d ", $name, $size;
61 printf "# %-25s $type %6d ", $name, $size;
6462 print scalar(localtime($mtime));
6563 printf " %06o", $mode;
6664 print "\n";
6767# Pick out the Socket.pm line as the sample we check carefully
6868($name, $type, $size, $mtime, $mode) = @{$dir[9]};
6969
70$name eq "Socket.pm" || print "not ";
71print "ok 2\n";
70ok($name, "Socket.pm");
71ok($type, "f");
72ok($size, 8817);
7273
73$type eq "f" || print "not ";
74print "ok 3\n";
75
76$size == 8817 || print "not ";
77print "ok 4\n";
78
7974# Must be careful when checking the time stamps because we don't know
8075# which year if this script lives for a long time.
8176$timestring = scalar(localtime($mtime));
82$timestring =~ /Mar\s+15\s+18:05/ or print "not ";
83print "ok 5\n";
77ok($timestring =~ /Mar\s+15\s+18:05/);
8478
85$mode == 0100644 || print "not ";
86print "ok 6\n";
79ok($mode, 0100644);
8780
8881@dir = parse_dir(<<'EOT');
8982drwxr-xr-x 21 root root 704 2007-03-22 21:48 dir
9083EOT
9184
92print "not " unless @dir == 1;
93print "ok 7\n";
85ok(@dir, 1);
86ok($dir[0][0], "dir");
87ok($dir[0][1], "d");
9488
95print "not " unless $dir[0][0] eq "dir";
96print "ok 8\n";
97
98print "not " unless $dir[0][1] eq "d";
99print "ok 9\n";
100
10189$timestring = scalar(localtime($dir[0][3]));
10290print "# $timestring\n";
103print "not " unless $timestring =~ /^Thu Mar 22 21:48/;
104print "ok 10\n";
91ok($timestring =~ /^Thu Mar 22 21:48/);
  
1#!perl -w
2
3use Test;
4
15use LWP::MediaTypes;
26
37require URI::URL;
4646 ["x.ppm.Z.UU" => "image/x-portable-pixmap","compress","x-uuencode",],
4747);
4848
49$notests = @tests + 3;
50print "1..$notests\n";
49plan tests => @tests * 3 + 4;
5150
5251if ($ENV{HOME} and -f "$ENV{HOME}/.mime.types") {
5352 warn "
5656}
5757
5858
59$testno = 1;
6059for (@tests) {
6160 ($file, $expectedtype, @expectedEnc) = @$_;
6261 $type1 = guess_media_type($file);
6362 ($type, @enc) = guess_media_type($file);
64 if ($type1 ne $type) {
65 print "guess_media_type does not return same content-type in scalar and array conext.\n";
66 next;
67 }
68 $type = "undef" unless defined $type;
69 if ($type eq $expectedtype and "@enc" eq "@expectedEnc") {
70 print "ok $testno\n";
71 }
72 else {
73 print "expected '$expectedtype' for '$file', got '$type'\n";
74 print "encoding: expected: '@expectedEnc', got '@enc'\n"
75 if @expectedEnc || @enc;
76 print "nok ok $testno\n";
77 }
78 $testno++;
63 ok($type1, $type);
64 ok($type, $expectedtype);
65 ok("@enc", "@expectedEnc");
7966}
8067
8168@imgSuffix = media_suffix('image/*');
82print "Image suffixes: @imgSuffix\n";
69print "# Image suffixes: @imgSuffix\n";
70ok(grep $_ eq "gif", @imgSuffix);
8371
84print "\n";
8572require HTTP::Response;
8673$r = new HTTP::Response 200, "Document follows";
8774$r->title("file.tar.gz.uu");
8875guess_media_type($r->title, $r);
89print $r->as_string;
76#print $r->as_string;
9077
91print "not " unless $r->content_type eq "application/x-tar";
92print "ok $testno\n"; $testno++;
78ok($r->content_type, "application/x-tar");
9379
9480@enc = $r->header("Content-Encoding");
95print "not " unless "@enc" eq "gzip x-uuencode";
96print "ok $testno\n"; $testno++;
81ok("@enc", "gzip x-uuencode");
9782
9883#
9984use LWP::MediaTypes qw(add_type add_encoding);
8888
8989@x = guess_media_type("foo.vrml.r13.gz");
9090#print "@x\n";
91print "not " unless "@x" eq "x-world/x-vrml rot13 x-gzip";
92print "ok $testno\n"; $testno++;
91ok("@x", "x-world/x-vrml rot13 x-gzip");
9392
9493#print LWP::MediaTypes::_dump();
9594
  
1print "1..5\n";
1#!perl -w
22
3use Test;
4plan tests => 5;
5
36use HTTP::Request;
47use HTTP::Negotiate;
58
69
7$no = 1;
8sub ok
9{
10 print "ok " . $no++ . "\n";
11}
12
13sub not_ok
14{
15 print "not ";
16 ok;
17}
18
19
2010 # ID QS Content-Type Encoding Char-Set Lang Size
2111 $variants =
2212 [
3030
3131$a = choose($variants, $request);
3232print "The chosen one is '$a'\n";
33if ($a eq 'var2') {
34 ok;
35}
36else {
37 not_ok;
38}
33ok($a, "var2");
3934
4035#------------------
4136
6161
6262$a = choose($variants);
6363
64if ($a eq 'var-de') {
65 ok;
66}
67else {
68 not_ok
69}
64ok($a, 'var-de');
7065
7166
7267$variants = [
7272
7373$ENV{HTTP_ACCEPT_LANGUAGE}='en-US';
7474$a = choose($variants);
75if ($a eq 'Generic English') {
76 ok;
77}
78else {
79 not_ok;
80}
75ok($a, 'Generic English');
8176
8277#------------------
8378
8888 ($vb, $qb) = @$b;
8989 if ($va ne $vb) {
9090 print "$va == $vb ?\n";
91 not_ok;
91 ok(0);
9292 return;
9393 }
9494 if (abs($qa - $qb) > 0.002) {
9595 print "$qa ~= $qb ?\n";
96 not_ok;
96 ok(0);
9797 return;
9898 }
9999 }
100100
101101 } until (!defined($a) || !defined($b));
102 return not_ok if defined($a) ne defined($b);
103 ok;
102 ok(defined($a), defined($b));
104103}
105104
106105sub show_res
  
1print "1..6\n";
1use Test;
2plan tests => 6;
23
34use LWP::UserAgent;
4
55$ua = LWP::UserAgent->new();
66
77$ua->protocols_forbidden(['hTtP']);
8print "not " unless scalar(@{$ua->protocols_forbidden()}) == 1;
9print "ok 1\n";
8ok(scalar(@{$ua->protocols_forbidden()}), 1);
9ok(@{$ua->protocols_forbidden()}[0], 'hTtP');
1010
11print "not " unless @{$ua->protocols_forbidden()}[0] eq 'hTtP';
12print "ok 2\n";
13
1411$response = $ua->get('http://www.cpan.org/');
12ok($response->is_error());
13ok(!$ua->is_protocol_supported('http'));
14ok(!$ua->protocols_allowed());
1515
16print "not " unless $response->is_error();
17print "ok 3\n";
18
19print "not " if $ua->is_protocol_supported('http');
20print "ok 4\n";
21
22print "not " if $ua->protocols_allowed();
23print "ok 5\n";
24
2516$ua->protocols_forbidden(undef);
26
27print "not " if $ua->protocols_forbidden();
28print "ok 6\n";
17ok(!$ua->protocols_forbidden());
  
1#!perl -w
12
23# Test extra HTTP::Response methods. Basic operation is tested in the
34# message.t test suite.
45
6use strict;
7use Test;
8plan tests => 8;
59
6print "1..8\n";
7
8
910use HTTP::Date;
1011use HTTP::Request;
1112use HTTP::Response;
1213
1314my $time = time;
1415
15$req = HTTP::Request->new(GET => 'http://www.sn.no');
16my $req = HTTP::Request->new(GET => 'http://www.sn.no');
1617$req->date($time - 30);
1718
18$r = new HTTP::Response 200, "OK";
19my $r = new HTTP::Response 200, "OK";
1920$r->client_date($time - 20);
2021$r->date($time - 25);
2122$r->last_modified($time - 5000000);
2223$r->request($req);
2324
24print $r->as_string;
25#print $r->as_string;
2526
26$current_age = $r->current_age;
27my $current_age = $r->current_age;
2728
28if ($current_age < 35 || $current_age > 40) {
29 print "not ";
30}
31print "ok 1\n";
29ok($current_age >= 35 && $current_age <= 40);
3230
33$freshness_lifetime = $r->freshness_lifetime;
34if ($freshness_lifetime < 12 * 3600) {
35 print "not ";
36}
37print "ok 2\n";
31my $freshness_lifetime = $r->freshness_lifetime;
32ok($freshness_lifetime >= 12 * 3600);
3833
39$is_fresh = $r->is_fresh;
34my $is_fresh = $r->is_fresh;
35ok($is_fresh);
4036
41print "not " unless $is_fresh;
42print "ok 3\n";
43
44print "current_age = $current_age\n";
45print "freshness_lifetime = $freshness_lifetime\n";
46print "response is ";
47print "not " unless $is_fresh;
37print "# current_age = $current_age\n";
38print "# freshness_lifetime = $freshness_lifetime\n";
39print "# response is ";
40print " not " unless $is_fresh;
4841print "fresh\n";
4942
50
51print "it will be fresh is ";
43print "# it will be fresh for ";
5244print $freshness_lifetime - $current_age;
5345print " more seconds\n";
5446
5547# OK, now we add an Expires header
5648$r->expires($time);
57print $r->as_string;
49#print $r->as_string;
5850
5951$freshness_lifetime = $r->freshness_lifetime;
60print "freshness_lifetime = $freshness_lifetime\n";
61print "not " unless $freshness_lifetime == 25;
62print "ok 4\n";
52ok($freshness_lifetime, 25);
6353$r->remove_header('expires');
6454
6555# Now we try the 'Age' header and the Cache-Contol:
66
6756$r->header('Age', 300);
6857$r->push_header('Cache-Control', 'junk');
6958$r->push_header(Cache_Control => 'max-age = 10');
7059
71print $r->as_string;
60#print $r->as_string;
7261
7362$current_age = $r->current_age;
7463$freshness_lifetime = $r->freshness_lifetime;
7564
76print "current_age = $current_age\n";
77print "freshness_lifetime = $freshness_lifetime\n";
65print "# current_age = $current_age\n";
66print "# freshness_lifetime = $freshness_lifetime\n";
7867
79print "not " if $current_age < 300;
80print "ok 5\n";
68ok($current_age >= 300);
69ok($freshness_lifetime, 10);
8170
82print "not " if $freshness_lifetime != 10;
83print "ok 6\n";
71ok($r->fresh_until); # should return something
8472
85print "not " unless $r->fresh_until; # should return something
86print "ok 7\n";
87
8873my $r2 = HTTP::Response->parse($r->as_string);
8974my @h = $r2->header('Cache-Control');
90print "not " unless scalar @h == 2;
91print "ok 8\n"
75ok(@h, 2);
  
1use HTTP::Status;
1#!perl -w
22
3print "1..8\n";
3use Test;
4plan tests => 8;
45
5200 == RC_OK || print "not ";
6print "ok 1\n";
6use HTTP::Status;
77
8is_success(RC_ACCEPTED) || print "not ";
9print "ok 2\n";
8ok(RC_OK, 200);
109
11is_error(RC_BAD_REQUEST) || print "not ";
12print "ok 3\n";
10ok(is_info(RC_CONTINUE));
11ok(is_success(RC_ACCEPTED));
12ok(is_error(RC_BAD_REQUEST));
13ok(is_redirect(RC_MOVED_PERMANENTLY));
1314
14is_redirect(RC_MOVED_PERMANENTLY) || print "not ";
15print "ok 4\n";
15ok(!is_success(RC_NOT_FOUND));
1616
17is_success(RC_NOT_FOUND) && print "not ";
18print "ok 5\n";
19
20$mess = status_message(0);
21
22defined $mess && print "not ";
23print "ok 6\n";
24
25$mess = status_message(200);
26
27if ($mess =~ /ok/i) {
28 print "ok 7\n";
29}
30
31is_info(RC_CONTINUE) || print "not ";
32print "ok 8\n";
17ok(status_message(0), undef);
18ok(status_message(200), "OK");
t/base/ua.t
(18 / 29)
  
1print "1..10\n";
1#!perl -w
22
3use LWP::UserAgent;
3use strict;
4use Test;
45
5$ua = LWP::UserAgent->new;
6$clone = $ua->clone;
6plan tests => 10;
77
8print "not " unless $ua->agent =~ /^libwww-perl/;
9print "ok 1\n";
8use LWP::UserAgent;
109
10my $ua = LWP::UserAgent->new;
11my $clone = $ua->clone;
1112
12print "not " if defined $ua->proxy(ftp => "http://www.sol.no");
13print "ok 2\n";
13ok($ua->agent =~ /^libwww-perl/);
14ok(!defined $ua->proxy(ftp => "http://www.sol.no"));
15ok($ua->proxy("ftp"), "http://www.sol.no");
1416
15print "not " unless $ua->proxy("ftp") eq "http://www.sol.no";
16print "ok 3\n";
17
18@a = $ua->proxy([qw(ftp http wais)], "http://proxy.foo.com");
19
17my @a = $ua->proxy([qw(ftp http wais)], "http://proxy.foo.com");
2018for (@a) { $_ = "undef" unless defined; }
2119
22print "not " unless "@a" eq "http://www.sol.no undef undef";
23print "ok 4\n";
20ok("@a", "http://www.sol.no undef undef");
21ok($ua->proxy("http"), "http://proxy.foo.com");
22ok(ref($ua->default_headers), "HTTP::Headers");
2423
25print "not " unless $ua->proxy("http") eq "http://proxy.foo.com";
26print "ok 5\n";
27
28print "not " unless ref($ua->default_headers) eq "HTTP::Headers";
29print "ok 6\n";
30
3124$ua->default_header("Foo" => "bar", "Multi" => [1, 2]);
32print "not " unless $ua->default_headers->header("Foo") eq "bar";
33print "ok 7\n";
25ok($ua->default_headers->header("Foo"), "bar");
26ok($ua->default_header("Foo"), "bar");
3427
35print "not " unless $ua->default_header("Foo") eq "bar";
36print "ok 8\n";
37
3828# Try it
3929$ua->proxy(http => "loopback:");
4030$ua->agent("foo/0.1");
4131
42print "not " unless $ua->get("http://www.example.com", x => "y")->content eq <<EOT; print "ok 9\n";
32ok($ua->get("http://www.example.com", x => "y")->content, <<EOT);
4333GET http://www.example.com
4434User-Agent: foo/0.1
4535Foo: bar
3939
4040EOT
4141
42print "not " unless (ref($clone->{proxy}) eq 'HASH');
43print "ok 10\n";
42ok(ref($clone->{proxy}), 'HASH');
  
1#!/usr/bin/perl
1#!perl -w
22
3use Test;
4
35use strict;
46use File::Listing;
57use LWP::Simple;
68
7my $ok = 1;
8
99# some sample URLs
1010my @urls = (
1111 "http://www.apache.org/dist/apr/?C=N&O=D",
1313 "http://stein.cshl.org/WWW/software/",
1414 "http://www.cpan.org/modules/by-module/",
1515 );
16print "1.." . scalar(@urls) . "\n";
16plan tests => scalar(@urls);
1717
1818for my $url (@urls) {
1919 print "# $url\n";
2020 my @listing = parse_dir(get($url),undef,"apache");
21 print "not " if @listing == 0;
22 print "ok " . $ok++ . "\n";
23 #require Data::Dumper; print Data::Dumper->Dump(["Listing for $url", \@listing],[]);
21 ok(@listing);
2422}
  
1print "1..1\n";
1#!perl -w
22
33use strict;
4use Test;
5plan tests => 6;
6
47use Net::HTTP;
58
69
1313 PeerHTTPVersion => "1.1",
1414 MaxLineLength => 512) || die "$@";
1515
16for (1..1) {
16for (1..2) {
1717 $s->write_request(TRACE => "/libwww-perl",
1818 'User-Agent' => 'Mozilla/5.0',
1919 'Accept-Language' => 'no,en',
2626 }
2727 print "\n";
2828
29 my $err;
30 $err++ unless $code eq "200";
31 $err++ unless $h{'Content-Type'} eq "message/http";
29 ok($code, "200");
30 ok($h{'Content-Type'}, "message/http");
3231
3332 my $buf;
3433 while (1) {
3838 }
3939 $buf =~ s/\r//g;
4040
41 $err++ unless $buf eq "TRACE /libwww-perl HTTP/1.1
41 ok($buf, <<EOT);
42TRACE /libwww-perl HTTP/1.1
4243Host: www.apache.org
4344User-Agent: Mozilla/5.0
4445Accept-Language: no,en
4546Accept: */*
4647
47";
48
49 print "not " if $err;
50 print "ok $_\n";
48EOT
5149}
  
11#!perl -w
22
33use strict;
4use Test;
5
46use LWP::UserAgent;
57
68my $ua = LWP::UserAgent->new();
1313 exit;
1414}
1515
16print "1..2\n";
17print "not " unless $res->is_success;
18print "ok 1\n";
19
20print "not " unless $res->content =~ /Sun Microsystems/;
21print "ok 2\n";
16plan tests => 2;
17ok($res->is_success);
18ok($res->content =~ /Sun Microsystems/);
2219
2320my $cref = $res->content_ref;
2421substr($$cref, 100) = "..." if length($$cref) > 100;
  
1print "1..3\n";
2
31use strict;
2use Test;
3
4plan tests => 5;
5
46use LWP::UserAgent;
57
68my $ua = LWP::UserAgent->new(keep_alive => 1);
1313
1414#print $res->as_string;
1515
16print "not " unless $res->code eq "401";
17print "ok 1\n";
16ok($res->code, 401);
1817
1918$req->authorization_basic('guest', 'guest');
20$res = $ua->request($req);
19$res = $ua->simple_request($req);
2120
21print $req->as_string, "\n";
22
2223#print $res->as_string;
23print "not " unless $res->code eq "200" && $res->content =~ /Your browser made it!/;
24print "ok 2\n";
24ok($res->code, 200);
25ok($res->content =~ /Your browser made it!/);
2526
2627{
2728 package MyUA;
3333
3434 sub get_basic_credentials {
3535 my($self,$realm, $uri, $proxy) = @_;
36 print "$realm/$uri/$proxy\n";
36 #print "$realm/$uri/$proxy\n";
3737 my $p = shift @try;
38 print join("/", @$p), "\n";
38 #print join("/", @$p), "\n";
3939 return @$p;
4040 }
4141
4848
4949#print $res->as_string;
5050
51print "not " unless $res->content =~ /Your browser made it!/ &&
52 $res->header("Client-Response-Num") == 5;
53print "ok 3\n";
51ok($res->content =~ /Your browser made it!/);
52ok($res->header("Client-Response-Num"), 5);
  
1print "1..1\n";
2
31use strict;
2use Test;
3
4plan tests => 2;
5
46use LWP::UserAgent;
57
68{
1414
1515 sub get_basic_credentials {
1616 my($self,$realm, $uri, $proxy) = @_;
17 print "$realm/$uri/$proxy\n";
17 print "$realm:$uri:$proxy => ";
1818 my $p = shift @try;
1919 print join("/", @$p), "\n";
2020 return @$p;
2929
3030#print $res->as_string;
3131
32print "not " unless $res->content =~ /Your browser made it!/ &&
33 $res->header("Client-Response-Num") == 5;
34print "ok 1\n";
32ok($res->content =~ /Your browser made it!/);
33ok($res->header("Client-Response-Num"), 5);
  
2626 exit;
2727}
2828$TMPDIR =~ tr|\\|/|;
29print "1..2\n";
3029
30use Test;
31plan tests => 2;
32
3133use LWP::Simple;
3234require LWP::Protocol::file;
3335
3939# First we create the original
4040open(OUT, ">$orig") or die "Cannot open $orig: $!";
4141binmode(OUT);
42for (1..100) {
42for (1..5) {
4343 print OUT "This is line $_ of $orig\n";
4444}
4545close(OUT);
6767
6868unlink($copy);
6969
70if ($origtext eq $copytext) {
71 print "ok 1\n";
72}
73else {
74 print "not ok 1\n";
75}
70ok($copytext, $origtext);
7671
7772
7873# Test getstore() function
8383unlink($orig);
8484unlink($copy);
8585
86if ($origtext eq $copytext) {
87 print "ok 2\n";
88}
89else {
90 print "not ok 2\n";
91}
86ok($copytext, $origtext);