File: 50_driver_generic.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 (63 lines) | stat: -rw-r--r-- 1,522 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
#!/usr/bin/perl
use Test::More;
use Test::Exception;
use lib qw(t);

plan tests => 6;

use strict;
use warnings;

{

    package TestAppDriverGeneric;

    use base qw(TestAppDriver);

    my %groupmap = ( testuser => 'testgroup', );

    __PACKAGE__->authz->config(
        DRIVER       => [ 'Generic', sub { return $groupmap{ $_[0] } eq $_[1] ? 1 : 0 } ],
        GET_USERNAME => sub { 'testuser' },
    );

}

TestAppDriverGeneric->run_authz_success_tests( [qw(testgroup)], [qw(othertestgroup testgroup)] );

TestAppDriverGeneric->run_authz_failure_tests( [qw(badgroup)], [qw(badgroup otherbadgroup)] );

{

    package TestAppDriverGenericBadSub;

    use base qw(TestAppDriver);

    my %groupmap = ( testuser => 'testgroup', );

    __PACKAGE__->authz->config(
        DRIVER       => [ 'Generic' ],
        GET_USERNAME => sub { 'testuser' },
    );

}

throws_ok { TestAppDriverGenericBadSub->authz->authorize('testgroup') } qr/The Generic driver requires a subroutine reference as its only option/, "Generic driver dies with non CODE driver option";

{

    package TestAppDriverGenericNoSub;

    use base qw(TestAppDriver);

    my %groupmap = ( testuser => 'testgroup', );

    __PACKAGE__->authz->config(
        DRIVER       => [ 'Generic', 'BADVALUE' ],
        GET_USERNAME => sub { 'testuser' },
    );

}

throws_ok { TestAppDriverGenericNoSub->authz->authorize('testgroup') } qr/The Generic driver requires a subroutine reference as its only option/, "Generic driver dies with non CODE driver option";