File: Root.pm

package info (click to toggle)
libcatalyst-plugin-authentication-perl 0.10023-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 608 kB
  • sloc: perl: 3,672; makefile: 2
file content (74 lines) | stat: -rw-r--r-- 1,822 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package AuthRealmTestApp::Controller::Root;
use warnings;
use strict;
use base qw/Catalyst::Controller/;

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

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

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

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

    while ( my ($user, $info) = each %$AuthRealmTestApp::members ) {

        ok(
            $c->authenticate(
                { username => $user, password => $info->{password} },
                'members'
            ),
            "user $user authentication"
        );

        # check existing realms
        ok( $c->user_in_realm('members'), "user in members realm");
        ok(!$c->user_in_realm('admins'),  "user not in admins realm");

        # check an invalid realm
        ok(!$c->user_in_realm('foobar'), "user not in foobar realm");

        # check if we've got the right user
        is( $c->user, $info, "user object is in proper place");

        $c->logout;

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

    }

    while ( my ($user, $info) = each %$AuthRealmTestApp::admins ) {

        ok(
            $c->authenticate(
                { username => $user, password => $info->{password} },
                'admins'
            ),
            "user $user authentication"
        );

        # check existing realms
        ok(!$c->user_in_realm('members'), "user not in members realm");
        ok( $c->user_in_realm('admins'),  "user in admins realm");

        # check an invalid realm
        ok(!$c->user_in_realm('foobar'), "user not in foobar realm");

        # check if we've got the right user
        is( $c->user, $info, "user object is in proper place");

        $c->logout;

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

    }

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

1;