File: Root.pm

package info (click to toggle)
libcatalyst-plugin-authentication-perl 0.10023-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 604 kB
  • ctags: 307
  • sloc: perl: 3,672; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,782 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package AuthTestApp::Controller::Root;
use strict;
use warnings;
use base qw/ Catalyst::Controller /;

__PACKAGE__->config( namespace => '' );

use Test::More;
use Test::Exception;

use Digest::MD5 qw/md5/;
use Digest::SHA1 qw/sha1_base64/;

sub number_of_elements { return scalar @_ }

sub moose : Local {
    my ( $self, $c ) = @_;

    is(number_of_elements($c->user), 1, "Array undef");
    is($c->user, undef, "no user, returns undef");
    ok(!$c->user, "no user");
    ok($c->login( "foo", "s3cr3t" ), "can login with clear");
    is( $c->user, $AuthTestApp::users->{foo}, "user object is in proper place");

    ok( !$c->user->roles, "no roles for foo" );
    my @new = qw/foo bar gorch/;
    $c->user->roles( @new );
    is_deeply( [ $c->user->roles ], \@new, "roles set as array");

    $c->logout;
    ok(!$c->user, "no more user, after logout");

    ok($c->login( "bar", "s3cr3t" ), "can login with crypted");
    is( $c->user, $AuthTestApp::users->{bar}, "user object is in proper place");
    $c->logout;

    ok($c->login("gorch", "s3cr3t"), "can login with hashed");
    is( $c->user, $AuthTestApp::users->{gorch}, "user object is in proper place");
    $c->logout;

    ok($c->login("shabaz", "s3cr3t"), "can login with base64 hashed");
    is( $c->user, $AuthTestApp::users->{shabaz}, "user object is in proper place");
    $c->logout;

    ok($c->login("sadeek", "s3cr3t"), "can login with padded base64 hashed");
    is( $c->user, $AuthTestApp::users->{sadeek}, "user object is in proper place");
    $c->logout;

    ok(!$c->login( "bar", "bad pass" ), "can't login with bad password");
    ok(!$c->user, "no user");

    throws_ok { $c->login( "baz", "foo" ) } qr/support.*mechanism/, "can't login without any supported mech";

    $c->res->body( "ok" );
}