Refactor HTTP cred, part I
[catagits/Catalyst-Authentication-Credential-HTTP.git] / t / live_app.t
CommitLineData
790f9ddb 1#!/usr/bin/perl
790f9ddb 2use strict;
3use warnings;
ed61ff6d 4use Test::More;
ed61ff6d 5BEGIN {
6 eval { require Test::WWW::Mechanize::Catalyst }
7 or plan skip_all =>
8 "Test::WWW::Mechanize::Catalyst is needed for this test";
9 plan tests => 4;
10}
790f9ddb 11use HTTP::Request;
790f9ddb 12{
ed61ff6d 13 package AuthTestApp;
14 use Catalyst qw/
15 Authentication
16 Authentication::Store::Minimal
17 Authentication::Credential::HTTP
18 /;
ed61ff6d 19 use Test::More;
ed61ff6d 20 our $users;
ed61ff6d 21 sub moose : Local {
22 my ( $self, $c ) = @_;
790f9ddb 23 $c->authorization_required;
0914298e 24 $c->res->body( $c->user->id );
ed61ff6d 25 }
007935b8 26 __PACKAGE__->config->{authentication}{http}{type} = 'basic';
ed61ff6d 27 __PACKAGE__->config->{authentication}{users} = $users = {
28 foo => { password => "s3cr3t", },
29 };
ed61ff6d 30 __PACKAGE__->setup;
790f9ddb 31}
790f9ddb 32use Test::WWW::Mechanize::Catalyst qw/AuthTestApp/;
790f9ddb 33my $mech = Test::WWW::Mechanize::Catalyst->new;
790f9ddb 34$mech->get("http://localhost/moose");
ed61ff6d 35is( $mech->status, 401, "status is 401" );
ed61ff6d 36$mech->content_lacks( "foo", "no output" );
790f9ddb 37my $r = HTTP::Request->new( GET => "http://localhost/moose" );
38$r->authorization_basic(qw/foo s3cr3t/);
ed61ff6d 39$mech->request($r);
40is( $mech->status, 200, "status is 200" );
41$mech->content_contains( "foo", "foo output" );