Lemonldap/NG/Handler/Server/Nginx.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 6 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 92.3% 48 / 52 CC 5 SCAR 7.4
CC
5
Cov
98%
__ANON__
3.0
handler
3.0
_run
1.0
CRAP 2.1
« Lemonldap/NG/Handler/Main/SharedVariables.pm ↑ Summary Lemonldap/NG/Handler/PSGI/Main.pm »
1 # PSGI authentication package written for Nginx. It replace
2 # Lemonldap::NG::Handler::Server to manage Nginx behaviour
3 package Lemonldap::NG::Handler::Server::Nginx;
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Lemonldap::NG::Handler::Server::Main;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '2.21.0';
10  
11 2 extends 'Lemonldap::NG::Handler::PSGI';
12  
13 sub init {
14 4 ▶ my $self = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
15 4 $self->api('Lemonldap::NG::Handler::Server::Main');
16 4 my $tmp = $self->SUPER::init(@_);
17 }
18  
19 ## @method void _run()
20 # Return a subroutine that call _authAndTrace() and tranform redirection
21 # response code from 302 to 401 (not authenticated) ones. This is required
22 # because Nginx "auth_request" parameter does not accept it. The Nginx
23 # configuration file should transform them back to 302 using:
24 #
25 # auth_request_set $lmlocation $upstream_http_location;
26 # error_page 401 $lmlocation;
27 #
28 #@return subroutine that will be called to manage FastCGI queries
29 sub _run {
30 2 ▶ my $self = shift;
Subroutine _run: called CC=1 SCAR=0.0
31 return $self->psgiAdapter(
32 sub {
33 25 ▶ my $req = $_[0];
Subroutine __ANON__: called CC=3 SCAR=11.0
34 25 my $res = $self->_authAndTrace($req);
35  
36 # Transform 302 responses in 401 since Nginx refuse it
37 25 ▶ if ( $res->[0] == 302 or $res->[0] == 303 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0] == 302 or $res->[0] == 303) 10 15 25
Condition66%2/3
$res->[0] == 302 or $res->[0] == 303
l!l&&r!l&&!r
10015
MC/DC50%1/2
$res->[0] == 302 or $res->[0] == 303
$res->[0] == 302 $res->[0] == 303
Truth table66%2/3
A or B
A= $res->[0] == 302B= $res->[0] == 303
ABresult
1X1
011
000
38 10 $res->[0] = 401;
39 }
40 25 return $res;
41 }
42 2 );
43 }
44  
45 ## @method PSGI-Response handler()
46 # Transform headers returned by handler main process:
47 # each "Name: value" is transformed to:
48 # - Headername<i>: Name
49 # - Headervalue<i>: value
50 # where <i> is an integer starting from 1
51 # It can be used in Nginx virtualhost configuration:
52 #
53 # auth_request_set $headername1 $upstream_http_headername1;
54 # auth_request_set $headervalue1 $upstream_http_headervalue1;
55 # #proxy_set_header $headername1 $headervalue1;
56 # # OR
57 # #fastcgi_param $headername1 $headervalue1;
58 #
59 # LLNG::Handler::Server::Main add also headers called Lm-Remote-User set to
60 # whatToTrace value and Lm-Remote-Custom that can be used in Nginx virtualhosts configuration to
61 # insert user id and a custom value in logs
62 #
63 # auth_request_set $lmremote_user $upstream_http_lm_remote_user
64 # auth_request_set $lmremote_custom $upstream_http_lm_remote_custom
65 #
66 #@param $req Lemonldap::NG::Common::PSGI::Request
67 sub handler {
68 11 ▶ my ( $self, $req ) = @_;
Subroutine handler: called CC=3 SCAR=11.0
Pod undocumented
69 11 my @convertedHdrs = ( 'Content-Length' => 0 );
70 11 my $i = 0;
71 11 ▶ while ( my ( $k, $v ) = splice( @{ $req->{respHeaders} }, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@{$$req{"respHeaders"};}, 0, 2)) 60 11 71
72 60 ▶ if ( $k =~ /^(?:Deleteheader\d+|Lm-Remote-(?:User|Custom)|Cookie)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^(?:Deleteheader\d+|Lm-Remote-(?:User|Custom)|Cookie)$/) { } 43 17 60
73 43 push @convertedHdrs, $k, $v;
74 }
75 else {
76 17 $i++;
77 17 push @convertedHdrs, "Headername$i", $k, "Headervalue$i", $v, $k,
78 $v;
79 }
80 }
81 11 return [ 200, \@convertedHdrs, [] ];
82 }
83  
84 2 1;
« Lemonldap/NG/Handler/Main/SharedVariables.pm ↑ Summary Lemonldap/NG/Handler/PSGI/Main.pm »