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
|
#!/usr/bin/perl
use strict;
use warnings;
use lib "t/lib";
use Test::More;
BEGIN {
eval {
require Test::WWW::Mechanize::Catalyst;
require Catalyst::Plugin::Authorization::Roles;
require Catalyst::Plugin::Authentication;
require Catalyst::Plugin::Session;
require Catalyst::Plugin::Session::State::Cookie;
} or plan 'skip_all' => "A bunch of plugins are required for this test... Look in the source if you really care... $@";
plan tests => 97;
}
use Test::WWW::Mechanize::Catalyst 'ACLTestApp';
my $m = Test::WWW::Mechanize::Catalyst->new;
my $u = "http://localhost";
is_allowed("", "welcome");
is_denied("restricted");
is_denied("lioncage");
is_denied("zoo/elk");
is_denied("zoo/moose");
is_denied("zoo/rabbit");
is_denied("zoo/penguins/emperor");
is_denied("zoo/penguins/tux");
is_denied("zoo/penguins/madagascar");
login(qw/foo bar/);
is_allowed("auth/check", "logged in");
is_denied("restricted");
is_denied("lioncage");
is_allowed("zoo/elk");
is_denied("zoo/moose");
is_denied("zoo/rabbit");
is_allowed("zoo/penguins/emperor");
is_denied("zoo/penguins/tux");
is_allowed("zoo/penguins/madagascar");
is_allowed("auth/logout");
is_denied("restricted");
is_denied("lioncage");
is_denied("zoo/elk");
is_denied("zoo/moose");
is_denied("zoo/rabbit");
is_denied("zoo/penguins/emperor");
is_denied("zoo/penguins/tux");
is_denied("zoo/penguins/madagascar");
login(qw/gorch moose/);
is_allowed("zoo/elk");
is_denied("zoo/moose");
is_allowed("zoo/rabbit");
is_denied("lioncage");
is_denied("restricted");
is_allowed("zoo/penguins/emperor");
is_allowed("zoo/penguins/tux");
is_allowed("zoo/penguins/madagascar");
login(qw/quxx ding/);
is_allowed("zoo/elk");
is_allowed("zoo/moose");
is_denied("zoo/rabbit");
is_allowed("lioncage");
is_denied("restricted");
is_allowed("zoo/penguins/emperor");
is_denied("zoo/penguins/tux");
is_allowed("zoo/penguins/madagascar");
sub login {
my ( $l, $p ) = @_;
is_allowed("auth/login?login=$l&password=$p", "login successful");
}
sub is_denied {
my $path = shift;
local $Test::Builder::Level = 2;
$m->get_ok("$u/$path", "get '$path'");
$m->content_is("denied", "access to '$path' is denied");
}
sub is_allowed {
my ( $path, $contains ) = @_;
$path ||= "";
$m->get_ok("$u/$path", "get '$path'");
$m->content_contains( $contains, "'$path' contains '$contains'") if $contains;
$m->content_like(qr/allowed$/, "access to '$path' is allowed");
}
|