File: 04_forbidden.t

package info (click to toggle)
libcgi-application-plugin-authorization-perl 0.07-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 332 kB
  • ctags: 81
  • sloc: perl: 1,236; sh: 29; makefile: 2
file content (109 lines) | stat: -rw-r--r-- 2,276 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl
use Test::More tests => 3;
use Test::Exception;
use Scalar::Util;

use strict;
use warnings;
use lib './t';

{
    {
        package TestAppForbidden;

        use base qw(CGI::Application);
        use CGI::Application::Plugin::Authorization;

        sub setup {
            my $self = shift;
            $self->start_mode('one');
            $self->run_modes([qw(one)]);
        }

        sub one {
            my $self = shift;
            return $self->authz->forbidden;
        }

    }

    $ENV{CGI_APP_RETURN_ONLY} = 1;

    my $cgiapp = TestAppForbidden->new();
    my $results = $cgiapp->run;

    like($results, qr/<title>Forbidden<\/title>/, "authz_forbidden worked correctly");
}

{
    {
        package TestAppForbiddenRunmode;

        use base qw(CGI::Application);
        use CGI::Application::Plugin::Authorization;

        __PACKAGE__->authz->config(
            FORBIDDEN_RUNMODE => 'myforbidden',
        );

        sub setup {
            my $self = shift;
            $self->start_mode('one');
            $self->run_modes([qw(one myforbidden)]);
        }

        sub one {
            my $self = shift;
            return $self->authz->forbidden;
        }

        sub myforbidden {
            return 'myforbidden runmode';
        }

    }

    $ENV{CGI_APP_RETURN_ONLY} = 1;

    my $cgiapp = TestAppForbiddenRunmode->new();
    my $results = $cgiapp->run;

    like($results, qr/myforbidden runmode/, "forbidden returned the custom runmode");
}

{
    {
        package TestAppForbiddenURL;

        use base qw(CGI::Application);
        use CGI::Application::Plugin::Authorization;

        __PACKAGE__->authz->config(
            FORBIDDEN_URL => '/myforbidden.html',
        );

        sub setup {
            my $self = shift;
            $self->start_mode('one');
            $self->run_modes([qw(one)]);
        }

        sub one {
            my $self = shift;
            return $self->authz->forbidden;
        }

        sub myforbidden {
            return 'myforbidden runmode';
        }

    }

    $ENV{CGI_APP_RETURN_ONLY} = 1;

    my $cgiapp = TestAppForbiddenURL->new();
    my $results = $cgiapp->run;

    like($results, qr/Location:\s+\/myforbidden\.html/, "forbidden returned the custom URL");
}