ActiveDirectory.pm

filter: Statementstmt 58.3% 21 / 36 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 50.0% 28 / 56 CC 7 SCAR 34.2
CC
7
Cov
44%
check
56.0
BEGIN
1.0
BEGIN
1.0
CRAP 30.6
« LDAP.pm ↑ Summary
1 package Authen::Simple::ActiveDirectory;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base 'Authen::Simple::Adapter';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Net::LDAP qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Net::LDAP::Constant qw[LDAP_INVALID_CREDENTIALS];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Params::Validate qw[];
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = 0.3;
12  
13 1 __PACKAGE__->options({
14 host => {
15 type => Params::Validate::SCALAR | Params::Validate::ARRAYREF,
16 default => 'localhost',
17 optional => 1
18 },
19 port => {
20 type => Params::Validate::SCALAR,
21 default => 389,
22 optional => 1
23 },
24 timeout => {
25 type => Params::Validate::SCALAR,
26 default => 60,
27 optional => 1
28 },
29 principal => {
30 type => Params::Validate::SCALAR,
31 optional => 0
32 }
33 });
34  
35 0 ▶sub check {
Subroutine check: not called CC=7 SCAR=40.3
Pod documented
36 0 my ( $self, $username, $password ) = @_;
37  
38 0 my $connection = Net::LDAP->new( $self->host,
39 port => $self->port,
40 timeout => $self->timeout
41 );
42  
43 0 ▶ unless ( defined $connection ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $connection) 0 0 0
44  
45 0 my $host = $self->host;
46  
47 0 ▶ $self->log->error( qq/Failed to connect to '$host'. Reason: '$@'/ )
Branch: 1 branch
BranchTrueFalseTotal
if $self->log 0 0 0
48 if $self->log;
49  
50 0 return 0;
51 }
52  
53 0 my $user = sprintf( '%s@%s', $username, $self->principal );
54 0 my $message = $connection->bind( $user, password => $password );
55  
56 0 ▶ if ( $message->is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($message->is_error) 0 0 0
57  
58 0 my $error = $message->error;
59 0 ▶ my $level = $message->code == LDAP_INVALID_CREDENTIALS ? 'debug' : 'error';
Branch: 1 branch
BranchTrueFalseTotal
$message->code == 49 ? : 0 0 0
60  
61 0 ▶ $self->log->$level( qq/Failed to authenticate user '$user'. Reason: '$error'/ )
Branch: 1 branch
BranchTrueFalseTotal
if $self->log 0 0 0
62 if $self->log;
63  
64 0 return 0;
65 }
66  
67 0 ▶ $self->log->debug( qq/Successfully authenticated user '$user'./ )
Branch: 1 branch
BranchTrueFalseTotal
if $self->log 0 0 0
68 if $self->log;
69  
70 0 return 1;
71 }
72  
73 1 1;
74  
75 __END__
« LDAP.pm ↑ Summary