Connector/Builtin/Authentication/Password.pm

filter: Statementstmt 84.4% 65 / 77 Branchbran 78.5% 22 / 28 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 78.9% 101 / 128 CC 17 SCAR 18.7
CC
17
Cov
80%
get
10.9
exists
6.3
_build_config
6.0
CRAP 6.5
« Connector/Builtin/Memory.pm ↑ Summary Connector/Multi/Merge.pm »
1 # Connector::Builtin::Authentication::Password
2 #
3 # Check passwords against a unix style password file
4 #
5 package Connector::Builtin::Authentication::Password;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 extends 'Connector::Builtin';
14  
15 0 ▶sub _build_config {
Subroutine _build_config: not called CC=2 SCAR=17.9
16 0 my $self = shift;
17  
18 0 ▶ if (! -r $self->{LOCATION}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $self->{"LOCATION"}) 0 0 0
19 0 confess("Cannot open input file " . $self->{LOCATION} . " for reading.");
20 }
21  
22 0 return 1;
23 }
24  
25 7 ▶sub get {
Subroutine get: called CC=10 SCAR=23.9
Pod documented
26 7 my $self = shift;
27 7 my $arg = shift;
28 7 my $params = shift;
29  
30 7 my @path = $self->_build_path( $arg );
31 7 my $user = shift @path;
32  
33 7 my $password = $params->{password};
34  
35  
36 7 ▶ if (!$user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 0 7 7
37 0 $self->log()->error('No username');
38 0 die "no username given";
39 }
40  
41 7 ▶ if (!$password) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($password) 1 6 7
42 1 $self->log()->error('No password');
43 1 die "no password given";
44 }
45  
46  
47 6 $self->log()->debug('verify password for ' . $user );
48  
49 6 ▶ if ($user =~ /[^a-zA-Z0-9_\-\.\@]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user =~ /[^a-zA-Z0-9_\-\.\@]/) 1 5 6
50 1 $self->log()->error('Invalid chars in username ('.$user.')');
51 1 return $self->_node_not_exists( $user );
52 }
53  
54 5 my $filename = $self->{LOCATION};
55  
56 5 ▶ if (! -r $filename || ! open FILE, "$filename") {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $filename and open FILE, "$filename") 0 5 5
Condition33%1/3
-r $filename and open FILE, "$filename"
!ll&&!rl&&r
005
MC/DC0%0/2
-r $filename and open FILE, "$filename"
-r $filename open FILE, "$filename"
Truth table33%1/3
A and B
A= -r $filenameB= open FILE, "$filename"
ABresult
0X0
100
111
57 0 $self->log()->error('Can\'t open/read from file ' . $filename);
58 0 die 'Can\'t open/read from file ' . $filename;
59 }
60  
61 5 ▶ while (<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 8 2 10
62 8 ▶ if (/^$user:/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^$user:/) 3 5 8
63 3 chomp;
64 3 my @t = split(/:/, $_, 3);
65 3 $self->log()->trace('found line ' . Dumper @t);
66 #if ($password eq $t[1]) {
67 3 ▶ if (not defined $t[1]) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t[1]) 0 3 3
68 0 $self->log()->info('Password value not defined for ' . $user);
69 0 return 0;
70 }
71  
72 3 ▶ if (crypt($password, $t[1]) eq $t[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (crypt($password, $t[1]) eq $t[1]) { } 2 1 3
73 2 $self->log()->info('Password accepted for ' . $user);
74 2 return 1;
75 } else {
76 1 $self->log()->info('Password mismatch for ' . $user);
77 1 return 0;
78 }
79 }
80 }
81 2 return $self->_node_not_exists( $user );
82 }
83  
84 2 ▶sub get_meta {
Subroutine get_meta: called CC=2 SCAR=6.9
Pod documented
85 2 my $self = shift;
86  
87 # If we have no path, we tell the caller that we are a connector
88 2 my @path = $self->_build_path( shift );
89 2 ▶ if (scalar @path == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @path == 0) 1 1 2
90 1 return { TYPE => "connector" };
91 }
92 1 return {TYPE => "scalar" };
93 }
94  
95 4 ▶sub exists {
Subroutine exists: called CC=6 SCAR=18.4
Pod documented
96  
97 4 my $self = shift;
98  
99 # No path = connector root which always exists
100 4 my @path = $self->_build_path( shift );
101 4 ▶ if (scalar @path == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @path == 0) 1 3 4
102 1 return 1;
103 }
104  
105 3 my $user = shift @path;
106  
107 3 my $filename = $self->{LOCATION};
108 3 ▶ if (! -r $filename || ! open FILE, "$filename") {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $filename and open FILE, "$filename") 0 3 3
Condition33%1/3
-r $filename and open FILE, "$filename"
!ll&&!rl&&r
003
MC/DC0%0/2
-r $filename and open FILE, "$filename"
-r $filename open FILE, "$filename"
Truth table33%1/3
A and B
A= -r $filenameB= open FILE, "$filename"
ABresult
0X0
100
111
109 0 $self->log()->error('Can\'t open/read from file ' . $filename);
110 0 return 0;
111 }
112  
113 3 ▶ while (<FILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILE)) 4 1 5
114 4 ▶ if (/^$user:/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^$user:/) 2 2 4
115 2 return 1;
116 }
117 }
118 1 return 0;
119 }
120  
121 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 1 __PACKAGE__->meta->make_immutable;
123  
124 1 1;
125 __END__
« Connector/Builtin/Memory.pm ↑ Summary Connector/Multi/Merge.pm »