Clustericious/Plugin/SelfPlugAuth.pm

filter: Statementstmt 42.5% 20 / 47 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 75.0% 6 / 8 Podpod 33.3% 1 / 3 totaltotal 36.9% 27 / 73 CC 7 SCAR 24.7
CC
7
Cov
33%
authenticate
20.0
authorize
20.0
BEGIN
1.0
CRAP 11.9
« PlugAuth/Plugin/Audit.pm ↑ Summary PlugAuth/Routes.pm »
1 package Clustericious::Plugin::SelfPlugAuth;
2  
3 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use Clustericious::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use Mojo::ByteStream qw( b );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Self authentication for PlugAuth
10 24 our $VERSION = '0.39'; # VERSION
11  
12  
13 23 ▶sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
14 23 my ($self, $app, $conf) = @_;
15 23 PlugAuth::Role::Plugin->_self_auth_plugin($self);
16 23 $self;
17 }
18  
19 sub authenticate
20 0 ▶{
Subroutine authenticate: not called CC=4 SCAR=30.0
Pod undocumented
21 0 my($self, $c, $realm) = @_;
22  
23 0 TRACE ("Authenticating for realm $realm");
24 # Everyone needs to send an authorization header
25 0 ▶ my $auth = $c->req->headers->authorization or do {
Branch: 1 branch
BranchTrueFalseTotal
my $auth = $c->req->headers->authorization or do { $c->res->headers->www_authenticate(qq[Basic realm="$realm"]); $c->render("text", "auth required", "layout", "", "status", 401); return } 0 0 0
26 0 $c->res->headers->www_authenticate(qq[Basic realm="$realm"]);
27 0 $c->render(text => "auth required", layout => "", status => 401);
28 0 return;
29 };
30
31 0 my ($method,$str) = split / /,$auth;
32 0 my $userinfo = b($str)->b64_decode;
33 0 my ($user,$pw) = split /:/, $userinfo;
34  
35 0 $c->refresh;
36 0 ▶ if($c->authz->host_has_tag($c->tx->remote_address, 'trusted')
Branch: 1 branch
BranchTrueFalseTotal
if ($c->authz->host_has_tag($c->tx->remote_address, "trusted") or $c->auth->check_credentials($user, $pw)) 0 0 0
Condition0%0/3
$c->authz->host_has_tag($c->tx->remote_address, "trusted") or $c->auth->check_credentials($user, $pw)
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->authz->host_has_tag($c->tx->remote_address, "trusted") or $c->auth->check_credentials($user, $pw)
$c->authz->host_has_tag($c->tx->remote_address, "trusted") $c->auth->check_credentials($user, $pw)
Truth table0%0/3
A or B
A= $c->authz->host_has_tag($c->tx->remote_address, "trusted")B= $c->auth->check_credentials($user, $pw)
ABresult
1X1
011
000
37 || $c->auth->check_credentials($user,$pw)) {
38 0 $c->stash(user => $user);
39 0 return 1;
40 }
41  
42 0 INFO "Authentication denied for $user";
43 0 $c->res->headers->www_authenticate(qq[Basic realm="$realm"]);
44 0 $c->render(text => "authentication failure", status => 401);
45 0 return;
46 }
47  
48 sub authorize
49 0 ▶{
Subroutine authorize: not called CC=4 SCAR=30.0
Pod undocumented
50 0 my($self, $c, $action, $resource) = @_;
51 0 ▶ my $user = $c->stash("user") or LOGDIE "missing user in authorize()";
Branch: 1 branch
BranchTrueFalseTotal
my $user = $c->stash("user") or LOGDIE("missing user in authorize()") 0 0 0
52 0 ▶ LOGDIE "missing action or resource in authorize()" unless @_==4;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 4 0 0 0
53 0 TRACE "Authorizing user $user, action $action, resource $resource";
54 0 $resource =~ s[^/][/];
55 0 my $found = $c->authz->can_user_action_resource($user, $action, $resource);
56 0 ▶ if($found)
Branch: 1 branch
BranchTrueFalseTotal
if ($found) { } 0 0 0
57 {
58 0 return 1;
59 }
60 else
61 {
62 0 $c->render(text => "unauthorized", status => 403);
63 0 return 0;
64 }
65 }
66  
67 24 1;
68  
69 __END__
« PlugAuth/Plugin/Audit.pm ↑ Summary PlugAuth/Routes.pm »