New test for credentials with detach.
[catagits/Catalyst-Plugin-Authentication.git] / t / lib / AuthRealmTestAppProgressive / Controller / Root.pm
1 package AuthRealmTestAppProgressive::Controller::Root;
2 use warnings;
3 use strict;
4 use base qw/Catalyst::Controller/;
5
6 __PACKAGE__->config( namespace => '' );
7
8 use Test::More;
9 use Test::Exception;
10
11 sub progressive : Local {
12     my ( $self, $c ) = @_;
13
14     foreach my $realm ( keys %AuthRealmTestAppProgressive::members ) {
15         while ( my ( $user, $info ) =
16             each %{ $AuthRealmTestAppProgressive::members{$realm} } )
17         {
18             my $res;
19             my $ok = eval {
20                 $res = $c->authenticate(
21                     { username => $user, password => $info->{password} },
22                 );
23                 1;
24             };
25             ok( !$@,                       "authentication passed." );
26             ok( $ok,                       "user authenticated" );
27             ok( $c->user_in_realm($realm), "user in proper realm" );
28         }
29     }
30     $c->res->body("ok");
31 }
32
33 sub progressive_detach : Local {
34     my ( $self, $c ) = @_;
35
36     my $realm = $AuthRealmTestAppProgressive::detach_test_info->{realm_to_pass};
37     my $user  = $AuthRealmTestAppProgressive::detach_test_info->{user};
38     my $pass  = $AuthRealmTestAppProgressive::detach_test_info->{password};
39     my $res;
40     my $ok = eval {
41         $res = $c->authenticate( { username => $user, password => $pass }, );
42         1;
43     };
44     ok( !$@,                       "authentication passed skipping detach." );
45     ok( $ok,                       "user authenticated skipping detach" );
46     ok( $c->user_in_realm($realm), "user in proper realm" );
47     $c->res->body("ok");
48 }
49 1;
50