Bug fix for auth session restoration + Improvements to handling of default auth store
[catagits/Catalyst-Authentication-Credential-HTTP-Proxy.git] / t / basic.t
CommitLineData
19c14a20 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More 'no_plan';
7use Test::MockObject::Extends;
8use Test::MockObject;
9use Test::Exception;
10
11use Catalyst::Plugin::Authentication::User::Hash;
12
13my $m;
14BEGIN { use_ok( $m = "Catalyst::Plugin::Authentication::Credential::TypeKey" ) }
15
16my $req = Test::MockObject->new;
17$req->set_always( params => {} );
18$req->mock( param => sub { $_[0]->params->{ $_[1] } } );
19
20my $tk = Test::MockObject->new;
21$tk->set_true("verify");
22
23my $store = Test::MockObject->new;
24$store->mock( get_user => sub { shift; Catalyst::Plugin::Authentication::User::Hash->new( @_ ) } );
25
26my $c = Test::MockObject::Extends->new($m);
27$c->set_always( config => {} );
28my $config = $c->config->{authentication}{typekey} ||= {};
29
30$c->set_always( req => $req );
31$c->set_always( request => $req );
32$c->set_false("debug");
33
34my $authenticated;
35$c->mock( set_authenticated => sub { $authenticated = $_[1] } );
36
37can_ok( $m, "setup" );
38
39$c->setup;
40
41isa_ok( $config->{typekey_object},
42 "Authen::TypeKey", '$c->config->{authentication}{typekey}{obj}' );
43
44$config->{typekey_object} = $tk;
45
46can_ok( $m, "authenticate_typekey" );
47
48lives_ok {
49 $c->authenticate_typekey;
50 }
51 "can try to auth with no args, no params";
52
53ok( !$c->called("set_authenticated"), "nothing was authenticated" );
54ok( !$tk->called("verify"), "didn't even verify with no params" );
55
56$_->clear for $c, $tk;
57
58# from 01-verify.t in Authen-TypeKey-0.04
59%{ $req->params } = my %vars = (
60 ts => '1091163746',
61 email => 'bentwo@stupidfool.org',
62 name => 'Melody',
63 nick => 'foobar baz',
64 sig => 'GWwAIXbkb2xNrQO2e/r2LDl14ek=:U5+tDsPM0+EXeKzFWsosizG7+VU=',
65);
66
67lives_ok {
68 $c->authenticate_typekey;
69 }
70 "can try to auth, no args, all params";
71
72$tk->called_ok("verify");
73$c->called_ok( "set_authenticated", "authenticated" );
74
75$_->clear for $c, $tk;
76
77%{ $req->params } = ();
78$config->{auth_store} = $store;
79
80lives_ok {
81 $c->authenticate_typekey(%vars);
82 }
83 "can try to auth with args";
84
85$tk->called_ok("verify");
86$c->called_ok( "set_authenticated", "authenticated" );
87$store->called_ok( "get_user", "user retrieved from store" );
88
89
90$_->clear for $c, $tk, $store;
91
92$tk->set_false("verify");
93
94
95lives_ok {
96 $c->authenticate_typekey(%vars);
97 }
98 "can try to auth with args";
99
100$tk->called_ok("verify");
101ok( !$c->called( "set_authenticated" ), "authenticated" );
102ok( !$store->called( "get_user" ), "no user retrieved from store");
103
104