Catalyst/ActionRole/ProtectedResource.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 41 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Catalyst::ActionRole::ProtectedResource;
2 use Moose::Role;
3 use HTTP::Headers::Util qw(split_header_words);
4 use Digest::HMAC_SHA1 qw/hmac_sha1/;
5 use namespace::autoclean;
6  
7 around execute => sub {
8 my $orig = shift;
9 my $self = shift;
10 my ( $controller, $ctx, @args ) = @_;
11  
12 my @values = split_header_words( $ctx->request->header('authorization') );
13 my $token = $values[0][-1];
14 my $secret = $ctx->config->{'Controller::OAuth'}->{protected_resource}->{secret_key};
15 my $hmac = Digest::HMAC_SHA1->new($secret);
16 my $s_token = $ctx->session->{token};
17 $hmac->add($ctx->session->{token});
18 my $server_digest = $hmac->b64digest;
19 $ctx->log->debug("S: $secret, CLIENT: $token, SERVER: $server_digest, SStoken: $s_token") if $ctx->debug;
20 if ( !$ctx->user or ( $token ne $server_digest ) ) {
21 $ctx->stash( error => "invalid_request",
22 error_description => "Wrong token" );
23  
24 }
25 return $self->$orig(@_);
26 };
27  
28 1;
29  
30 __END__