AnyEvent/FTP/Server/Role/Auth.pm

filter: Statementstmt 89.2% 58 / 65 Branchbran 90.0% 9 / 10 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 86.6% 13 / 15 Podpod 20.0% 1 / 5 totaltotal 86.0% 86 / 100 SCAR 19.5
CC
7
Cov
90%
cmd_pass
4.2
auth_command_check_hook
3.0
__ANON__
2.0
CRAP 7.1
« AnyEvent/FTP/Client/Transfer/Passive.pm ↑ Summary AnyEvent/FTP/Client/Role/ResponseBuffer.pm »
1 package AnyEvent::FTP::Server::Role::Auth;
2  
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 25 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 25 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: Authentication role for FTP server
9 25 our $VERSION = '0.19'; # VERSION
10  
11  
12 25 has user => (is => 'rw');
13  
14  
15 69 ▶has authenticated => (is => 'rw', default => sub { 0 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
16  
17  
18 has authenticator => (
19 is => 'rw',
20 lazy => 1,
21 0 ▶ default => sub { sub { 0 } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 25 );
23  
24  
25 has bad_authentication_delay => (
26 is => 'rw',
27 69 ▶ default => sub { 5 },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 25 );
29  
30  
31 has _safe_commands => (
32 is => 'ro',
33 lazy => 1,
34 default => sub {
35 69 ▶ my %h = map { (lc $_ => 1) } @{ shift->unauthenticated_safe_commands };
Subroutine __ANON__: called CC=1 SCAR=0.0
36 69 \%h;
37 },
38 25 );
39  
40 has unauthenticated_safe_commands => (
41 is => 'ro',
42 lazy => 1,
43 default => sub {
44 68 ▶ [qw( USER PASS HELP QUIT )]
Subroutine __ANON__: called CC=1 SCAR=0.0
45 },
46 25 );
47  
48  
49 sub auth_command_check_hook
50 {
51 674 ▶ my($self, $con, $command) = @_;
Subroutine auth_command_check_hook: called CC=3 SCAR=11.0
Pod documented
52 674 ▶ return 1 if $self->authenticated || $self->_safe_commands->{$command};
Branch: 1 branch
BranchTrueFalseTotal
if $self->authenticated or $self->_safe_commands->{$command} 650 24 674
Condition100%3/3
$self->authenticated or $self->_safe_commands->{$command}
l!l&&r!l&&!r
50714324
MC/DC100%2/2
$self->authenticated or $self->_safe_commands->{$command}
$self->authenticated $self->_safe_commands->{$command}
Truth table100%3/3
A or B
A= $self->authenticatedB= $self->_safe_commands->{$command}
ABresult
1X1
011
000
53 24 $con->send_response(530 => 'Please login with USER and PASS');
54 24 $self->done;
55 24 return 0;
56 }
57  
58  
59 6 ▶sub help_user { 'USER <sp> username' }
Subroutine help_user: called CC=1 SCAR=0.0
Pod undocumented
60  
61 sub cmd_user
62 {
63 69 ▶ my($self, $con, $req) = @_;
Subroutine cmd_user: called CC=2 SCAR=6.9
Pod undocumented
64  
65 69 my $user = $req->args;
66 69 $user =~ s/^\s+//;
67 69 $user =~ s/\s+$//;
68  
69 69 ▶ if($user ne '')
Branch: 1 branch
BranchTrueFalseTotal
if ($user ne '') { } 68 1 69
70 {
71 68 $self->user($user);
72 68 $con->send_response(331 => "Password required for $user");
73 }
74 else
75 {
76 1 $con->send_response(530 => "USER requires a parameter");
77 }
78  
79 69 $self->done;
80 }
81  
82  
83 6 ▶sub help_pass { 'PASS <sp> password' }
Subroutine help_pass: called CC=1 SCAR=0.0
Pod undocumented
84  
85 sub cmd_pass
86 {
87 69 ▶ my($self, $con, $req) = @_;
Subroutine cmd_pass: called CC=4 SCAR=14.3
Pod undocumented
88  
89 69 my $user = $self->user;
90 69 my $pass = $req->args;
91  
92 69 ▶ unless(defined $user)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user) 1 68 69
93 {
94 1 $con->send_response(503 => 'Login with USER first');
95 1 $self->done;
96 1 return;
97 }
98  
99 68 ▶ if($self->authenticator->($user, $pass))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->authenticator->($user, $pass)) { } 64 4 68
100 {
101 64 $con->send_response(230 => "User $user logged in");
102 64 $self->{authenticated} = 1;
103 64 $self->emit(auth => $user);
104 64 $self->done;
105 }
106 else
107 {
108 4 my $delay = $self->bad_authentication_delay;
109 4 ▶ if($delay > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($delay > 0) { } 0 4 4
110 {
111 0 my $timer;
112 $timer = AnyEvent->timer( after => 5, cb => sub {
113 0 ▶ $con->send_response(530 => 'Login incorrect');
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 0 $self->done;
115 0 undef $timer;
116 0 });
117 }
118 else
119 {
120 4 $con->send_response(530 => 'Login incorrect');
121 4 $self->done;
122 }
123 }
124 }
125  
126 25 1;
127  
128 __END__
« AnyEvent/FTP/Client/Transfer/Passive.pm ↑ Summary AnyEvent/FTP/Client/Role/ResponseBuffer.pm »