File: 50_driver.t

package info (click to toggle)
libcgi-application-plugin-authorization-perl 0.07%2B~cs0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 356 kB
  • sloc: perl: 1,237; makefile: 17
file content (70 lines) | stat: -rw-r--r-- 1,724 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
#!/usr/bin/perl
use Test::More;
use Test::Exception;
use lib qw(t);

plan tests => 8;

use strict;
use warnings;

{

    package TestAppDriverBasic;

    use base qw(TestAppDriver);

    __PACKAGE__->authz->config(
        DRIVER => [
            [ 'Dummy', PARAM1 => 'param1', PARAM2 => 'param2' ],
            [ 'Generic', sub { 1 } ],
        ],
    );

}

my $cgiapp = TestAppDriverBasic->new;

my @drivers = $cgiapp->authz->drivers;

isa_ok($drivers[0], 'CGI::Application::Plugin::Authorization::Driver::Dummy');
isa_ok($drivers[1], 'CGI::Application::Plugin::Authorization::Driver::Generic');

is($drivers[0]->find_option('PARAM2'), 'param2', 'find_option returns correct parameter');
is($drivers[0]->find_option('PARAM1'), 'param1', 'find_option returns correct parameter');
is($drivers[0]->find_option('PARAM'), undef, 'find_option returns undef when parameter not found');


throws_ok { CGI::Application::Plugin::Authorization::Driver->authorize_user } qr/authorize_user must be implemented in the subclass/, "authorize_user dies unless overriden in a subclass";



{
    package TestAppDriverInvalid;

    use base qw(TestAppDriver);

    __PACKAGE__->authz->config(
        DRIVER => [
            [ 'Invalid' ],
        ],
    );

}

throws_ok { TestAppDriverInvalid->new->authz->authorize('testgroup') } qr/Could not create new Invalid object/, "die with invalid driver";

{
    package TestAppDriverNonExistant;

    use base qw(TestAppDriver);

    __PACKAGE__->authz->config(
        DRIVER => [
            [ 'NonExistant::Driver' ],
        ],
    );

}

throws_ok { TestAppDriverNonExistant->new->authz->authorize('testgroup') } qr/Driver NonExistant::Driver can not be found/, "die with invalid driver";