| 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'
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
| |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if ($ENV{MOD_PERL}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | $server->{apache}->status($server->response_code || RC_OK); | ||||||||||||||||||||||||||
|
Condition0%0/2
$server->response_code || 200
MC/DC0%0/1
$server->response_code || 200
$server->response_code
Truth table0%0/2
A
A= $server->response_code
| |||||||||||||||||||||||||||||
| 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
MC/DC0%0/1
$server->response_code || 200
$server->response_code
Truth table0%0/2
A
A= $server->response_code
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | return unless $auth =~ s/^\s*Basic\s+//; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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)
MC/DC0%0/1
$server->get_auth_info || (return)
$server->get_auth_info
Truth table0%0/2
A
A= $server->get_auth_info
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Basic Authentication | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (defined $auth->{userid}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
not defined $password or $password ne $auth->{"password"}
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"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 0 | my $password = $server->password_for_user($auth->{Username}); | |||||||||||||||||||||||||||
| 81 | 0 | ▶ | return $server->auth_failure(RC_FORBIDDEN, 'Invalid login') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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'
MC/DC0%0/1
$server->realm || 'Atompub'
$server->realm
Truth table0%0/2
A
A= $server->realm
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||