]> Dogcows Code - chaz/p5-HTTP-AnyUA/blob - t/21-basic-auth.t
change an instance of "and" to "&&"
[chaz/p5-HTTP-AnyUA] / t / 21-basic-auth.t
1 #!perl
2
3 use warnings;
4 use strict;
5
6 use lib 't/lib';
7
8 use HTTP::AnyUA;
9 use Test::More;
10 use Util qw(:server :test :ua);
11
12 my $server = start_server('t/app.psgi');
13
14 plan tests => scalar user_agents;
15
16 test_all_user_agents {
17 plan tests => 12;
18
19 my $ua = shift;
20 my $any_ua = HTTP::AnyUA->new($ua, response_is_future => 1);
21
22 my $user = 'bob';
23 my $pass = 'opensesame';
24 my $auth = 'Ym9iOm9wZW5zZXNhbWU=';
25 my $path = '/get-document';
26 my $url = $server->url . $path;
27 $url =~ s!^(https?://)!${1}${user}:${pass}\@!;
28 my $future = $any_ua->get($url);
29
30 $future->on_ready(sub {
31 my $self = shift;
32 my $resp = $self->is_done ? $self->get : $self->failure;
33 my $env = $server->read_env;
34
35 note explain 'RESPONSE: ', $resp;
36 note explain 'ENV: ', $env;
37
38 SKIP: {
39 skip 'unexpected env', 4 if ref($env) ne 'HASH';
40 is($env->{REQUEST_METHOD}, 'GET', 'correct method sent');
41 is($env->{REQUEST_URI}, $path, 'correct url sent');
42 is($env->{content}, '', 'no body sent');
43 is($env->{HTTP_AUTHORIZATION}, "Basic $auth", 'correct authorization sent');
44 }
45
46 is_response_content($resp, 'this is a document');
47 is_response_reason($resp, 'OK');
48 is_response_status($resp, 200);
49 is_response_success($resp, 1);
50 TODO: {
51 local $TODO = 'some user agents strip the auth from the URL';
52 # Mojo::UserAgent strips the auth from the URL
53 is_response_url($resp, $url);
54 };
55 is_response_header($resp, 'content-type', 'text/plain');
56 is_response_header($resp, 'content-length', 18);
57 response_protocol_ok($resp);
58 });
59
60 return $future;
61 };
62
This page took 0.03149 seconds and 4 git commands to generate.