Catalyst-Authentication-AuthTkt
view release on metacpan or search on metacpan
t/01-authtkt.t view on Meta::CPAN
#!/usr/bin/env/perl
use strict;
use Test::More tests => 21;
use lib 't/MyApp/lib';
use Catalyst::Test 'MyApp';
use HTTP::Request::Common;
use Data::Dump qw( dump );
use Config::General;
use Apache::AuthTkt;
use HTTP::Request::AsCGI;
use HTTP::Cookies;
my $class = 'MyApp';
# based on Catalyst::Test local_request() but
# hack in session cookie support.
my $scookie;
sub my_request {
my $uri = shift or die "uri required";
my $request = Catalyst::Utils::request($uri);
if ($scookie) {
$request->header( 'Cookie', $scookie );
}
my $response = request($request);
if ( !$scookie && $response->header('Set-Cookie') ) {
$scookie = $response->header('Set-Cookie');
$scookie =~ s/;.*//;
}
return $response;
}
# cribbed from Test::HTTP::Response
sub extract_cookies {
my $response = shift;
my %cookies;
my $cookie_jar = HTTP::Cookies->new();
$cookie_jar->extract_cookies($response);
$cookie_jar->scan(
sub {
my %cookie = ();
@cookie{
qw(version key value path domain port path domain port path_spec secure expires discard hash)
} = @_;
$cookies{ $cookie{key} } = \%cookie;
}
);
return \%cookies;
}
ok( my $conf = Config::General->new("t/MyApp/myapp.conf"),
"get config via file" );
ok( my %config = $conf->getall, "parse config file" );
#dump \%config;
my $store = $config{'Plugin::Authentication'}->{realms}->{authtkt}->{store};
my $secret = $store->{secret};
my $cookie_name = $store->{cookie_name};
my $res;
ok( $res = my_request('/'), "get /" );
is( $res->headers->{status}, 302, "req redirects without auth tkt" );
is( $res->headers->{location},
$config{'Controller::Root'}->{auth_url},
"auth url"
);
#diag( dump $res );
( run in 2.448 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )