fix Test::More version used, for done_testing
[catagits/Web-Simple.git] / t / test-request-basic-auth.t
CommitLineData
8c3623e2 1use strictures 1;
a30328b3 2use Test::More 0.88;
8c3623e2 3
4my $auth_result;
5my @auth_args;
6
7{
8 package TestApp;
9
10 use Web::Simple;
11 use Plack::Middleware::Auth::Basic;
12
13 sub dispatch_request {
14 sub () {
15 Plack::Middleware::Auth::Basic->new(
16 authenticator => sub {
17 @auth_args = @_; return $auth_result
18 }
19 )
20 },
21 sub () {
22 [ 200, [ 'Content-type' => 'text/plain' ], [ 'Woo' ] ]
23 }
24 }
25}
26
27my $ta = TestApp->new;
28
29my $res = $ta->run_test_request(GET => '/');
30
31is($res->code, '401', 'Auth failed with no user/pass');
32ok(!@auth_args, 'Auth callback never called with no user/pass');
33
34$res = $ta->run_test_request(GET => 'bob:secret@/');
35
36is($res->code, '401', 'Auth failed with bad user/pass');
37is($auth_args[0], 'bob', 'Username passed ok');
38is($auth_args[1], 'secret', 'Password passed ok');
39
40$auth_result = 1;
41@auth_args = ();
42
43$res = $ta->run_test_request(GET => '/');
44
45is($res->code, '401', 'Auth failed with no user/pass');
46ok(!@auth_args, 'Auth callback never called with no user/pass');
47
48$res = $ta->run_test_request(GET => 'bob:secret@/');
49
50is($res->code, '200', 'Auth succeeded with good user/pass');
51is($auth_args[0], 'bob', 'Username passed ok');
52is($auth_args[1], 'secret', 'Password passed ok');
53
54done_testing;