File: 90diveintomark.t

package info (click to toggle)
libhttp-proxy-perl 0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 568 kB
  • sloc: perl: 2,392; makefile: 2
file content (99 lines) | stat: -rw-r--r-- 2,602 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# good place for web client tests:
# http://diveintomark.org/tests/client/http/

use strict;
my @url;
my $tests;

BEGIN {
    @url = (
        [ '200.xml', 200 ],
        [ '220.xml', 220 ],
        [ '320.xml', 320 ],
        [ '420.xml', 420 ],
        [ '520.xml', 520 ],
        [ '301.xml', 301,  200 ],
        [ '302.xml', 302,  200 ],
        [ '307.xml', 307,  200 ],
        [ '400.xml', 400 ],
        [ '403.xml', 403 ],
        [ '404.xml', 404 ],
        [ '410.xml', 410 ],
        [ '500.xml', 500 ],
        [ '300.xml', 300,  200 ],
        [ '200_basic_auth.xml',  401, 200 ], # these tests actually
        [ '200_digest_auth.xml', 401, 200 ], # do 401, then 401/200
        #['200_gzip.xml'],
        #['etag.xml'],
        #['lastmodified.xml'],
    );
    $tests += @$_ - 1 for @url;
}

use Test::More;
use HTTP::Proxy;
use HTTP::Request::Common;
use t::Utils;

my $base = 'http://diveintomark.org/tests/client/http';

plan skip_all => "$base seems to have stopped working";
plan tests => $tests;

SKIP:
{
    skip "$base is not available", $tests unless web_ok( $base );

    # $tests + 2, because of the duplicate 401
    my $proxy = HTTP::Proxy->new(
        port                    => 0,
        max_keep_alive_requests => $tests + 2,
        max_connections         => 1,
    );
    $proxy->init;

    # the auto-authenticating client
    {
        package MyUA;
        use base qw( LWP::UserAgent );

        my %credentials = (
            "Use test/basic" => [ "test", "basic" ],
            "DigestTest"     => [ "test", "digest" ],
        );

        sub get_basic_credentials {
            my($self, $realm, $uri) = @_;
            return @{$credentials{$realm}};
        }
    }

    my $ua = MyUA->new( keep_alive => 1 );
    $ua->proxy( http => $proxy->url );

    # fork the proxy
    my $pid = fork_proxy($proxy);

    # check all those pages
    for (@url) {
        my ( $doc, $status, $status2, $realm, $user, $pass ) = @$_;
        my $res = $ua->simple_request( GET "$base/$doc" );
        is( $res->code, $status, "$doc => $status" );

        # redirection
        if ( $res->is_redirect && $status2 ) {
            $res = $ua->simple_request( GET $res->header('Location') );
            is( $res->code, $status2, "$doc => $status2 (redirect)" );
        }

        # authentication
        if ( $res->code == 401 ) {
            # this request is actually two requests (401/200)
            $res = $ua->request( GET "$base/$doc" );
            is( $res->code, $status2, "$doc => $status2 (auth)" );
        }
    }

    # wait for the proxy
    wait;
}