blib/lib/Catalyst/Authentication/Credential/Testing.pm

filter: Statementstmt 100% 3 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 100% 4 / 4 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package Catalyst::Authentication::Credential::Testing;
2 1 ▶use base 'Catalyst::Authentication::Credential::Password';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 use strict;
5 use warnings;
6  
7 use Carp;
8 use Catalyst::Exception;
9  
10 our $VERSION = '0.01';
11  
12 =head1 NAME
13  
14 Catalyst::Authentication::Credential::Testing
15  
16 =head1 SYNOPSIS
17  
18 # Setup the auth in your config on your dev machines only
19 __PACKAGE__->config(
20  
21 'Plugin::Authentication' => {
22 default_realm => 'your_realm',
23 realms => {
24 your_realm => {
25 credential => {
26 class => 'Testing',
27 password_field => 'password',
28 global_password => 'secret', # password for all users
29 },
30 },
31 },
32 },
33  
34 );
35  
36 =head1 DESCRIPTION
37  
38 When your developing an app it is often convenient to be able to log in as any
39 user. You can either achieve this by disabling authentication (but then you
40 can't test failed logins) or by setting all the passwords to be the same
41 (which is annoying).
42  
43 Or you can use this module and set one password for all users at the
44 authentication level. This leaves the rest of your code untouched.
45  
46 =head1 HOW IT WORKS
47  
48 This module is based on L<Catalyst::Authentication::Credential::Password> and
49 overides the C<new> and C<check_password> methods.
50  
51 =head2 new
52  
53 Checks that the config is complete.
54  
55 =head2 check_password
56  
57 Returns true if the password is the same as that set in the config, false
58 otherwise.
59  
60 =cut
61  
62 sub new {
63 my ( $class, $config, $app, $realm ) = @_;
64  
65 my $self = { _config => $config };
66 bless $self, $class;
67  
68 $self->realm($realm);
69  
70 foreach my $key (qw( global_password password_field )) {
71  
72 # we just want to check that this config exists
73 next if $self->_config->{$key};
74  
75 # produce a message that should be helpful enough to the user that
76 # they can debug using it.
77 my $msg
78 = "ERROR in %s: you must specify '%s' in your credential config";
79 Catalyst::Exception->throw( sprintf( $msg, __PACKAGE__, $key ) );
80  
81 }
82  
83 return $self;
84 }
85  
86 sub check_password {
87 my ( $self, $user, $authinfo ) = @_;
88  
89 # get the values out
90 my $password = $authinfo->{ $self->_config->{password_field} };
91 my $global_password = $self->_config->{global_password};
92  
93 # success if the two passwords are the same
94 return $password eq $global_password;
95 }
96  
97 =head1 SEE ALSO
98  
99 L<Catalyst::Authentication::Credential::Password>
100  
101 =head1 BUGS
102  
103 Test suite is minimal.
104  
105 =head1 AUTHOR
106  
107 Edmund von der Burg C<<evdb@ecclestoad.co.uk>>
108  
109 Bug reports and suggestions very welcome.
110  
111 =head1 ACKNOWLEDGMENTS
112  
113 Developed whilst working at Foxtons - L<http://www.foxtons.co.uk>. Thank you
114 for letting me open source this code.
115  
116 =head1 COPYRIGHT
117  
118 Copyright (C) 2008 Edmund von der Burg. All rights reserved.
119  
120 This module is free software; you can redistribute it and/or modify it under
121 the same terms as Perl itself.
122  
123 THERE IS NO WARRANTY.
124  
125 =cut
126  
127 1;
128  
↑ Summary