Spore/Middleware/Auth/ApiKey.pm

filter: Statementstmt 53.6% 22 / 41 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 44.2% 27 / 61 CC 6 SCAR 31.5
CC
6
Cov
42%
call
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 23.4
« Spore/Middleware/Redirection.pm ↑ Summary Spore/Meta/Method.pm »
1 package Net::HTTP::Spore::Middleware::Auth::ApiKey;
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 {
6 1 $Net::HTTP::Spore::Middleware::Auth::ApiKey::VERSION = '0.01';
7 }
8  
9 # ABSTRACT: middleware for authentication with apikey
10  
11 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Digest::SHA qw(hmac_sha512_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 extends 'Net::HTTP::Spore::Middleware::Auth';
15  
16 1 has key_name => (isa => 'Str', is => 'rw', required => 0);
17 1 has api_key => (isa => 'Str', is => 'rw', required => 1);
18 1 has api_secret => (isa => 'Str', is => 'rw', required => 1);
19  
20 0 ▶sub call {
Subroutine call: not called CC=6 SCAR=37.4
Pod undocumented
21 0 my ($self, $req) = @_;
22  
23 0 ▶ return unless $self->should_authenticate($req);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->should_authenticate($req) 0 0 0
24  
25 0 my ($path, $query_string) = $req->_path;
26  
27 0 my $keyname = $self->key_name;
28 0 ▶ if (!defined($keyname)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $keyname) 0 0 0
29 0 $keyname = 'Key';
30 }
31  
32 0 my $nonce = time(); # XXX need $nonce++ and error handling to do more than
33 # one query per second
34 0 my $content = $req->body;
35 0 ▶ if (!defined($content) || length($content) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $content or length $content == 0) { } 0 0 0
Condition0%0/3
not defined $content or length $content == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $content or length $content == 0
not defined $content length $content == 0
Truth table0%0/3
not(A) or B
A= not defined $contentB= length $content == 0
ABresult
1X1
011
000
36 0 $content = "";
37 } else {
38 0 $content .= "&";
39 }
40 0 $content .= "nonce=".$nonce;
41 0 ▶ if (defined($query_string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $query_string) 0 0 0
42 0 $content .= "&".$query_string;
43 }
44 0 printf STDERR "ApiKey: content = '%s'\n", $content;
45 0 $req->body($content);
46 0 $req->header('Content-Type' => 'application/x-www-form-urlencoded');
47 0 $req->header($keyname => $self->api_key);
48 0 $req->header('Sign' => hmac_sha512_hex($content, $self->api_secret));
49 }
50  
51 1 1;
52  
53 __END__
« Spore/Middleware/Redirection.pm ↑ Summary Spore/Meta/Method.pm »