File Coverage

blib/lib/Plack/Middleware/HubSignature.pm
Criterion Covered Total %
statement 34 34 100.0
branch 2 2 100.0
condition 2 2 100.0
subroutine 10 10 100.0
pod 1 1 100.0
total 49 49 100.0


line stmt bran cond sub pod time code
1             package Plack::Middleware::HubSignature;
2 2     2   46535 use 5.008001;
  2         7  
  2         109  
3 2     2   8 use strict;
  2         3  
  2         59  
4 2     2   17 use warnings;
  2         2  
  2         87  
5              
6             our $VERSION = "0.01";
7              
8 2     2   550 use parent 'Plack::Middleware';
  2         405  
  2         10  
9 2     2   23000 use Plack::Util;
  2         4  
  2         35  
10 2     2   6 use Plack::Util::Accessor qw/secret/;
  2         4  
  2         505  
11 2     2   1283 use Plack::Request;
  2         98071  
  2         78  
12              
13 2     2   2368 use Digest::SHA;
  2         9514  
  2         168  
14 2     2   1272 use String::Compare::ConstantTime;
  2         1066  
  2         360  
15              
16             sub call {
17 3     3 1 37630 my ($self, $env) = @_;
18              
19 3         33 my $req = Plack::Request->new($env);
20 3         46 my $expected = 'sha1=' . Digest::SHA::hmac_sha1_hex($req->content, $self->secret);
21 3   100     2143 my $actual = $req->header('X-Hub-Signature') || '';
22 3 100       940 if (!String::Compare::ConstantTime::equals($expected, $actual)) {
23 2         33 return [400, ['Content-Type' => 'text/plain'], ['BAD REQUEST'] ];
24             }
25              
26 1         15 $self->app->($env);
27             }
28              
29             1;
30             __END__