Atompub/Server.pm

filter: Statementstmt 36.2% 25 / 69 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 61.5% 8 / 13 Podpod 100% 5 / 5 totaltotal 29.9% 38 / 127 CC 19 SCAR 36.1
CC
19
Cov
25%
authenticate
90.0
send_http_header
30.0
get_auth_info
30.0
CRAP 36.8
« Atompub/Client.pm ↑ Summary Atompub/DateTime.pm »
1 package Atompub::Server;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Atompub;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Digest::SHA qw(sha1);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MIME::Base64 qw(encode_base64 decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use HTTP::Status;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use XML::Atom;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use base qw(XML::Atom::Server);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub send_http_header {
Subroutine send_http_header: not called CC=5 SCAR=34.0
Pod documented
15 0 my($server) = @_;
16 0 ▶ my $type = $server->response_content_type || 'application/atom+xml';
Condition0%0/2
$server->response_content_type || 'application/atom+xml'
l!l
00
MC/DC0%0/1
$server->response_content_type || 'application/atom+xml'
$server->response_content_type
Truth table0%0/2
A
A= $server->response_content_type
Aresult
11
00
17 0 ▶ if ($ENV{MOD_PERL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'MOD_PERL'}) { } 0 0 0
18 0 ▶ $server->{apache}->status($server->response_code || RC_OK);
Condition0%0/2
$server->response_code || 200
l!l
00
MC/DC0%0/1
$server->response_code || 200
$server->response_code
Truth table0%0/2
A
A= $server->response_code
Aresult
11
00
19 0 $server->{apache}->send_http_header($type);
20 }
21 else {
22 0 ▶ $server->{cgi_headers}{-status} = $server->response_code || RC_OK;
Condition0%0/2
$server->response_code || 200
l!l
00
MC/DC0%0/1
$server->response_code || 200
$server->response_code
Truth table0%0/2
A
A= $server->response_code
Aresult
11
00
23 0 $server->{cgi_headers}{-type} = $type;
24 0 print $server->{cgi}->header(%{ $server->{cgi_headers} });
25 }
26 }
27  
28 0 ▶sub realm {
Subroutine realm: not called CC=2 SCAR=17.9
Pod documented
29 0 my($server, $realm) = @_;
30 0 ▶ $server->{realm} = $realm if $realm;
Branch: 1 branch
BranchTrueFalseTotal
if $realm 0 0 0
31 0 $server->{realm};
32 }
33  
34 0 ▶sub get_auth_info {
Subroutine get_auth_info: not called CC=5 SCAR=34.0
Pod documented
35 0 my($server) = @_;
36 0 my %param;
37  
38 # Basic Authentication
39 0 ▶ if (my $auth = $server->request_header('Authorization')) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $auth = $server->request_header('Authorization')) { } 0 0 0
elsif (my $req = $server->request_header('X-WSSE')) { } 0 0 0
40 0 ▶ return unless $auth =~ s/^\s*Basic\s+//;
Branch: 1 branch
BranchTrueFalseTotal
unless $auth =~ s/^\s*Basic\s+// 0 0 0
41 0 require MIME::Base64;
42 0 my $val = MIME::Base64::decode($auth);
43 0 my($userid, $password) = split /:/, $val, 2;
44 0 %param = (userid => $userid, password => $password);
45 }
46 # WSSE Authentication
47 elsif (my $req = $server->request_header('X-WSSE')) {
48 0 $req =~ s/^(?:WSSE|UsernameToken) //;
49 0 for my $i (split /,\s*/, $req) {
50 0 my($k, $v) = split /=/, $i, 2;
51 0 $v =~ s/^"//;
52 0 $v =~ s/"$//;
53 0 $param{$k} = $v;
54 }
55 }
56 else {
57 0 return $server->auth_failure(RC_UNAUTHORIZED, 'Basic or WSSE authentication required');
58 }
59  
60 0 \%param;
61 }
62  
63 0 ▶sub authenticate {
Subroutine authenticate: not called CC=9 SCAR=45.0
Pod documented
64 0 my($server) = @_;
65  
66 0 ▶ my $auth = $server->get_auth_info || return;
Condition0%0/2
$server->get_auth_info || (return)
l!l
00
MC/DC0%0/1
$server->get_auth_info || (return)
$server->get_auth_info
Truth table0%0/2
A
A= $server->get_auth_info
Aresult
11
00
67  
68 # Basic Authentication
69 0 ▶ if (defined $auth->{userid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $auth->{'userid'}) { } 0 0 0
70 0 my $password = $server->password_for_user($auth->{userid});
71 return $server->auth_failure(RC_FORBIDDEN, 'Invalid login')
72 0 ▶ if !defined $password || $password ne $auth->{password};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $password or $password ne $auth->{"password"} 0 0 0
Condition0%0/3
not defined $password or $password ne $auth->{"password"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $password or $password ne $auth->{"password"}
not defined $password $password ne $auth->{"password"}
Truth table0%0/3
not(A) or B
A= not defined $passwordB= $password ne $auth->{"password"}
ABresult
1X1
011
000
73 }
74 # WSSE Authentication
75 else {
76 0 for my $f (qw(Username PasswordDigest Nonce Created)) {
77 return $server->auth_failure(RC_BAD_REQUEST, "X-WSSE requires $f")
78 0 ▶ unless $auth->{$f};
Branch: 1 branch
BranchTrueFalseTotal
unless $auth->{$f} 0 0 0
79 }
80 0 my $password = $server->password_for_user($auth->{Username});
81 0 ▶ return $server->auth_failure(RC_FORBIDDEN, 'Invalid login')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $password 0 0 0
82 unless defined $password;
83 my $expected
84 0 = encode_base64(sha1(decode_base64($auth->{Nonce}).$auth->{Created}.$password), '');
85 return $server->auth_failure(RC_FORBIDDEN, 'Invalid login')
86 0 ▶ unless $expected eq $auth->{PasswordDigest};
Branch: 1 branch
BranchTrueFalseTotal
unless $expected eq $auth->{"PasswordDigest"} 0 0 0
87 }
88  
89 0 1;
90 }
91  
92 0 ▶sub auth_failure {
Subroutine auth_failure: not called CC=2 SCAR=17.9
Pod documented
93 0 my($server) = @_;
94 0 ▶ my $realm = $server->realm || 'Atompub';
Condition0%0/2
$server->realm || 'Atompub'
l!l
00
MC/DC0%0/1
$server->realm || 'Atompub'
$server->realm
Truth table0%0/2
A
A= $server->realm
Aresult
11
00
95 0 $server->response_header(
96 'WWW-Authenticate',
97 qq{Basic realm="$realm", WSSE profile="UsernameToken"},
98 );
99 0 $server->error(@_);
100 }
101  
102 2 1;
103 __END__
« Atompub/Client.pm ↑ Summary Atompub/DateTime.pm »