RequireSSL.pm

filter: Statementstmt 100% 24 / 24 Branchbran 80.0% 8 / 10 Conditioncond 77.7% 14 / 18 MC/DCmcdc 55.5% 5 / 9 Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 84.3% 54 / 64 CC 12 SCAR 23.8
CC
12
Cov
88%
__ANON__
12.4
BEGIN
1.0
BEGIN
1.0
CRAP 10.8
↑ Summary RequireSSL/Role.pm »
1 package Catalyst::ActionRole::RequireSSL;
2 2 $Catalyst::ActionRole::RequireSSL::VERSION = '1.00';
3 2 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 with 'Catalyst::ActionRole::RequireSSL::Role';
5 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 Catalyst::ActionRole::RequireSSL - Force an action to be secure only.
10  
11 =head1 VERSION
12  
13 version 1.00
14  
15 =head1 SYNOPSIS
16  
17 package MyApp::Controller::Foo;
18  
19 use parent qw/Catalyst::Controller::ActionRole/;
20  
21 sub bar : Local Does('RequireSSL') { ... }
22 sub bar : Local Does('NoSSL') { ... }
23  
24 =head2 HIERARCHY
25  
26 You can chain the SSL Roles to allow for enforced combinations such as all
27 secure apart from a certain action and vice versa. See the tests to see this
28 in action.
29  
30 =cut
31  
32 9 ▶around execute => sub {
Subroutine __ANON__: called CC=12 SCAR=25.2
33 9 my $orig = shift;
34 9 my $self = shift;
35 9 my ($controller, $c) = @_;
36  
37 9 ▶ unless(defined $c->config->{require_ssl}->{disabled}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $c->config->{"require_ssl"}{"disabled"}) 1 8 9
38 $c->config->{require_ssl}->{disabled} =
39 1 ▶ $c->engine->isa("Catalyst::Engine::HTTP") ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$c->engine->isa('Catalyst::Engine::HTTP') ? : 0 1 1
40 }
41 #use Data::Dumper;warn Dumper($c->action);
42 9 ▶ if (!$c->req->secure && $c->req->method eq "POST"
Branch: 1 branch
BranchTrueFalseTotal
if (not $c->req->secure and $c->req->method eq "POST" and not $c->config->{"require_ssl"}{"ignore_on_post"}) 1 8 9
Condition83%5/6
not $c->req->secure and $c->req->method eq "POST" and not $c->config->{"require_ssl"}{"ignore_on_post"}
!ll&&!rl&&r
801
not $c->req->secure and $c->req->method eq "POST"
!ll&&!rl&&r
351
MC/DC66%2/3
not $c->req->secure and $c->req->method eq "POST" and not $c->config->{"require_ssl"}{"ignore_on_post"}
not $c->req->secure $c->req->method eq "POST" not $c->config->{"require_ssl"}{"ignore_on_post"}
Truth table75%3/4
not(A) and B and not(C)
A= not $c->req->secureB= $c->req->method eq "POST"C= not $c->config->{"require_ssl"}{"ignore_on_post"}
ABCresult
0XX0
10X0
1100
1111
43 && !$c->config->{require_ssl}->{ignore_on_post})
44 {
45 1 $c->error("Cannot secure request on POST")
46 }
47  
48 9 ▶ unless(
Branch: 1 branch
BranchTrueFalseTotal
if ($c->config->{'require_ssl'}{'disabled'} or $c->req->secure or $c->req->method eq 'POST' or not $self->check_chain($c)) { } 5 4 9
Condition88%8/9
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure or $c->req->method eq "POST" or not $self->check_chain($c)
l!l&&r!l&&!r
414
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure or $c->req->method eq "POST"
l!l&&r!l&&!r
315
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure
l!l&&r!l&&!r
036
MC/DC75%3/4
$c->config->{"require_ssl"}{"disabled"} or $c->req->secure or $c->req->method eq "POST" or not $self->check_chain($c)
$c->config->{"require_ssl"}{"disabled"} $c->req->secure $c->req->method eq "POST" not $self->check_chain($c)
Truth table80%4/5
A or B or C or not(D)
A= $c->config->{"require_ssl"}{"disabled"}B= $c->req->secureC= $c->req->method eq "POST"D= not $self->check_chain($c)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
49 $c->config->{require_ssl}->{disabled} ||
50 $c->req->secure ||
51 $c->req->method eq "POST" ||
52 !$self->check_chain($c)
53 ) {
54 4 my $uri = $c->req->uri->clone;
55 4 $uri->scheme('https');
56 4 $c->res->redirect( $uri, 301 );
57 4 $c->detach();
58 } else {
59 $c->log->warn("Would've redirected to SSL")
60 5 ▶ if $c->config->{require_ssl}->{disabled} && $c->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $c->config->{"require_ssl"}{"disabled"} and $c->debug 0 5 5
Condition33%1/3
$c->config->{"require_ssl"}{"disabled"} and $c->debug
!ll&&!rl&&r
500
MC/DC0%0/2
$c->config->{"require_ssl"}{"disabled"} and $c->debug
$c->config->{"require_ssl"}{"disabled"} $c->debug
Truth table33%1/3
A and B
A= $c->config->{"require_ssl"}{"disabled"}B= $c->debug
ABresult
0X0
100
111
61 5 $self->$orig( @_ );
62 }
63 2 };
64  
65 2 1;
66  
67 =head1 AUTHOR
68  
69 Simon Elliott <cpan@papercreatures.com>
70  
71 =head1 THANKS
72  
73 Andy Grundman, <andy@hybridized.org> for the original RequireSSL Plugin
74  
75 t0m (Tomas Doran), zamolxes (Bogdan Lucaciu), wreis (Wallace Reis)
76  
77 =head1 COPYRIGHT & LICENSE
78  
79 Copyright 2009 by Simon Elliott
80  
81 This program is free software; you can redistribute it and/or modify it under
82 the same terms as Perl itself.
↑ Summary RequireSSL/Role.pm »