Nakamura/Authn.pm

filter: Statementstmt 45.3% 34 / 75 Branchbran 4.1% 1 / 24 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 75.0% 9 / 12 Podpod 100% 5 / 5 totaltotal 39.2% 51 / 130 CC 16 SCAR 33.7
CC
16
Cov
34%
switch_user
72.0
login_user
25.3
form_login
6.0
CRAP 29.1
« Nakamura/Content.pm ↑ Summary Nakamura/World.pm »
1 #!/usr/bin/perl -w
2  
3 package Sakai::Nakamura::Authn;
4  
5 7 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use base qw(Apache::Sling::Authn);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Sakai::Nakamura::AuthnUtil;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 7 require Exporter;
13  
14 7 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 7 our @EXPORT_OK = ();
17  
18 7 our $VERSION = '0.13';
19  
20 #{{{sub new
21 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
22 6 my ( $class, $nakamura ) = @_;
23  
24 6 my $authn = $class->SUPER::new($nakamura);
25 6 ${$nakamura}->{'Authn'} = \$authn;
26 6 bless $authn, $class;
27 6 return $authn;
28 }
29  
30 #}}}
31  
32 #{{{sub form_login
33 0 ▶sub form_login {
Subroutine form_login: not called CC=2 SCAR=17.9
Pod documented
34 0 my ($authn) = @_;
35 0 my $username = $authn->{'Username'};
36 0 my $password = $authn->{'Password'};
37 my $res = Apache::Sling::Request::request(
38 \$authn,
39 Sakai::Nakamura::AuthnUtil::form_login_setup(
40 0 $authn->{'BaseURL'}, $username, $password
41 )
42 );
43 0 my $success = Sakai::Nakamura::AuthnUtil::form_login_eval($res);
44 0 my $message = "Form log in as user \"$username\" ";
45 0 ▶ $message .= ( $success ? 'succeeded!' : 'failed!' );
Branch: 1 branch
BranchTrueFalseTotal
$success ? : 0 0 0
46 0 $authn->set_results( "$message", $res );
47 0 return $success;
48 }
49  
50 #}}}
51  
52 #{{{sub form_logout
53 0 ▶sub form_logout {
Subroutine form_logout: not called CC=2 SCAR=17.9
Pod documented
54 0 my ($authn) = @_;
55 my $res =
56 Apache::Sling::Request::request( \$authn,
57 0 Sakai::Nakamura::AuthnUtil::form_logout_setup( $authn->{'BaseURL'} ) );
58 0 my $success = Sakai::Nakamura::AuthnUtil::form_logout_eval($res);
59 0 my $message = 'Form log out ';
60 0 ▶ $message .= ( $success ? 'succeeded!' : 'failed!' );
Branch: 1 branch
BranchTrueFalseTotal
$success ? : 0 0 0
61 0 $authn->set_results( "$message", $res );
62 0 return $success;
63 }
64  
65 #}}}
66  
67 #{{{sub switch_user
68 0 ▶sub switch_user {
Subroutine switch_user: not called CC=8 SCAR=42.8
Pod documented
69 0 my ( $authn, $new_username, $new_password ) = @_;
70 0 ▶ if ( !defined $new_username ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_username) 0 0 0
71 0 croak 'New username to switch to not defined';
72 }
73 0 ▶ if ( !defined $new_password ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_password) 0 0 0
74 0 croak 'New password to use in switch not defined';
75 }
76 0 ▶ if ( ( $authn->{'Username'} !~ /^$new_username$/msx )
Branch: 1 branch
BranchTrueFalseTotal
if (not $authn->{'Username'} =~ /^$new_username$/msx && $authn->{'Password'} =~ /^$new_password$/msx) { } 0 0 0
Condition0%0/3
$authn->{'Username'} =~ /^$new_username$/msx && $authn->{'Password'} =~ /^$new_password$/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$authn->{'Username'} =~ /^$new_username$/msx && $authn->{'Password'} =~ /^$new_password$/msx
$authn->{'Username'} =~ /^$new_username$/msx $authn->{'Password'} =~ /^$new_password$/msx
Truth table0%0/3
A && B
A= $authn->{'Username'} =~ /^$new_username$/msxB= $authn->{'Password'} =~ /^$new_password$/msx
ABresult
0X0
100
111
77 || ( $authn->{'Password'} !~ /^$new_password$/msx ) )
78 {
79 0 $authn->{'Username'} = $new_username;
80 0 $authn->{'Password'} = $new_password;
81  
82 0 my $success = $authn->form_logout();
83 0 ▶ if ( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
84 croak 'Form Auth log out for user "'
85 . $authn->{'Username'}
86 . '" at URL "'
87 0 . $authn->{'BaseURL'}
88 . "\" was unsuccessful\n";
89 }
90 0 $success = $authn->form_login();
91 0 ▶ if ( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
92 croak "Form Auth log in for user \"$new_username\" at URL \""
93 0 . $authn->{'BaseURL'}
94 . "\" was unsuccessful\n";
95 }
96 }
97 else {
98 0 $authn->{'Message'} = 'User already active, no need to switch!';
99 }
100 0 ▶ if ( $authn->{'Verbose'} >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($authn->{"Verbose"} >= 1) 0 0 0
101 0 Apache::Sling::Print::print_result($authn);
102 }
103 0 return 1;
104 }
105  
106 #}}}
107  
108 #{{{sub login_user
109 3 ▶sub login_user {
Subroutine login_user: called CC=7 SCAR=32.3
Pod documented
110 3 my ($authn) = @_;
111 3 my $success = 1;
112  
113 # Log in if url, username and
114 # password are supplied:
115 3 ▶ if ( defined $authn->{'BaseURL'}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $authn->{"BaseURL"} and defined $authn->{"Username"} and defined $authn->{"Password"}) 0 3 3
Condition33%2/6
defined $authn->{"BaseURL"} and defined $authn->{"Username"} and defined $authn->{"Password"}
!ll&&!rl&&r
300
defined $authn->{"BaseURL"} and defined $authn->{"Username"}
!ll&&!rl&&r
030
MC/DC0%0/3
defined $authn->{"BaseURL"} and defined $authn->{"Username"} and defined $authn->{"Password"}
defined $authn->{"BaseURL"} defined $authn->{"Username"} defined $authn->{"Password"}
Truth table25%1/4
A and B and C
A= defined $authn->{"BaseURL"}B= defined $authn->{"Username"}C= defined $authn->{"Password"}
ABCresult
0XX0
10X0
1100
1111
116 && defined $authn->{'Username'}
117 && defined $authn->{'Password'} )
118 {
119 0 $success = $authn->form_login();
120 0 ▶ if ( !$success ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 0 0
121 0 ▶ if ( $authn->{'Verbose'} >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($authn->{"Verbose"} >= 1) 0 0 0
122 0 Apache::Sling::Print::print_result($authn);
123 }
124 croak 'Form Auth log in for user "'
125 . $authn->{'Username'}
126 . '" at URL "'
127 0 . $authn->{'BaseURL'}
128 . "\" was unsuccessful\n";
129 }
130 0 ▶ if ( $authn->{'Verbose'} >= 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($authn->{"Verbose"} >= 1) 0 0 0
131 0 Apache::Sling::Print::print_result($authn);
132 }
133 }
134 3 return $success;
135 }
136  
137 #}}}
138  
139 7 1;
140  
141 __END__
« Nakamura/Content.pm ↑ Summary Nakamura/World.pm »