Lemonldap/NG/Handler/PSGI/Main.pm

filter: Statementstmt 70.2% 59 / 84 Branchbran 75.0% 6 / 8 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 74.0% 20 / 27 Podpod 0.0% 0 / 13 totaltotal 59.8% 85 / 142 CC 8 SCAR 7.2
CC
8
Cov
66%
__ANON__
6.0
__ANON__
6.0
set_header_in
3.0
CRAP 2.1
« Lemonldap/NG/Handler/Server/Nginx.pm ↑ Summary Lemonldap/NG/Handler/Lib/DevOpsCDA.pm »
1 # Main auto-protected PSGI adapter for LLNG handler
2 #
3 # See https://lemonldap-ng.org/documentation/latest/handlerarch
4 package Lemonldap::NG::Handler::PSGI::Main;
5  
6 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 23 ▶use base 'Lemonldap::NG::Handler::Main';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 23 our $VERSION = '2.19.0';
9  
10 # Specific modules and constants for Test or CGI
11 23 ▶use constant FORBIDDEN => 403;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 23 ▶use constant HTTP_UNAUTHORIZED => 401;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 23 ▶use constant REDIRECT => 302;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 23 ▶use constant OK => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 23 ▶use constant DECLINED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 23 ▶use constant DONE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 23 ▶use constant SERVER_ERROR => 500;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 23 ▶use constant AUTH_REQUIRED => 401;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 23 ▶use constant MAINTENANCE => 503;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 23 ▶use constant defaultLogger => 'Lemonldap::NG::Common::Logger::Std';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 ## @method void thread_share(string $variable)
23 # share or not the variable (if authorized by specific module)
24 # @param $variable the name of the variable to share
25 0 ▶sub thread_share {
Subroutine thread_share: not called CC=1 SCAR=0.0
Pod undocumented
26  
27 # nothing to do in PSGI
28 }
29  
30 ## @method void setServerSignature(string sign)
31 # modifies web server signature
32 # @param $sign String to add to server signature
33 45 ▶sub setServerSignature {
Subroutine setServerSignature: called CC=1 SCAR=0.0
Pod undocumented
34 }
35  
36 ## @method void set_user(string user)
37 # sets remote_user in response headers
38 # @param user string username
39 112 ▶sub set_user {
Subroutine set_user: called CC=1 SCAR=0.0
Pod undocumented
40 112 my ( $class, $req, $user ) = @_;
41 112 push @{ $req->{respHeaders} }, 'Lm-Remote-User' => $user;
42 }
43  
44 ## @method void set_custom(string custom)
45 # sets remote_custom in response headers
46 # @param custom string custom_value
47 112 ▶sub set_custom {
Subroutine set_custom: called CC=2 SCAR=7.1
Pod undocumented
48 112 my ( $class, $req, $custom ) = @_;
49 112 ▶ push @{ $req->{respHeaders} }, 'Lm-Remote-Custom' => $custom
Branch: 1 branch
BranchTrueFalseTotal
if defined $custom 112 0 112
50 if defined $custom;
51 }
52  
53 ## @method void set_header_in(hash headers)
54 # sets or modifies request headers
55 # @param headers hash containing header names => header value
56 11 ▶sub set_header_in {
Subroutine set_header_in: called CC=3 SCAR=11.1
Pod undocumented
57 11 my ( $class, $req, %headers ) = @_;
58 11 ▶ while ( my ( $h, $v ) = each %headers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %headers) 11 11 22
59 11 ▶ $req->{env}->{ cgiName($h) } = $v if ( defined $v );
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 11 0 11
60 }
61 }
62  
63 ## @method void unset_header_in(array headers)
64 # removes request headers
65 # @param headers array with header names to remove
66 23 ▶sub unset_header_in {
Subroutine unset_header_in: called CC=2 SCAR=6.9
Pod undocumented
67 23 my ( $class, $req, @headers ) = @_;
68 23 foreach my $h (@headers) {
69 23 delete $req->{env}->{ cgiName($h) };
70 }
71 }
72  
73 ## @method void set_header_out(hash headers)
74 # sets response headers
75 # @param headers hash containing header names => header value
76 53 ▶sub set_header_out {
Subroutine set_header_out: called CC=2 SCAR=6.9
Pod undocumented
77 53 my ( $class, $req, %headers ) = @_;
78 53 ▶ while ( my ( $h, $v ) = each %headers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %headers) 53 53 106
79 53 push @{ $req->{respHeaders} }, $h => $v;
80 }
81 }
82  
83 ## @method boolean is_initial_req
84 # always returns true
85 # @return is_initial_req boolean
86 161 ▶sub is_initial_req {
Subroutine is_initial_req: called CC=1 SCAR=0.0
Pod undocumented
87 161 return 1;
88 }
89  
90 ## @method void print(string data)
91 # write data in HTTP response body
92 # @param data Text to add in response body
93 0 ▶sub print {
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
94 0 my ( $class, $req, $data ) = @_;
95 0 $req->{respBody} .= $data;
96 }
97  
98 0 ▶sub addToHtmlHead {
Subroutine addToHtmlHead: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my $self = shift;
100 0 $self->logger->error(
101 'Features like form replay or logout_app can only be used with Apache');
102 }
103  
104 688 ▶sub cgiName {
Subroutine cgiName: called CC=1 SCAR=0.0
Pod undocumented
105 688 my $h = uc(shift);
106 688 $h =~ s/-/_/g;
107 688 return "HTTP_$h";
108 }
109  
110 0 ▶sub logout_app {
Subroutine logout_app: not called CC=1 SCAR=6.9
Pod undocumented
111 0 my $class = shift;
112 0 my $u = shift;
113 0 $class->logger->debug("Nginx logout_app redirect to $u");
114 return (
115 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
116 0 my ( $req, $session ) = @_;
117 0 ▶ my $dest = $u || $class->tsv->{portal}->($req);
Condition0%0/3
$u || $class->tsv->{'portal'}->($req)
l!l&&r!l&&!r
000
MC/DC0%0/2
$u || $class->tsv->{'portal'}->($req)
$u $class->tsv->{'portal'}->($req)
Truth table0%0/3
A || B
A= $uB= $class->tsv->{'portal'}->($req)
ABresult
1X1
011
000
118 0 $class->logger->debug(
119 "logout_app_sso: sending internal_lemonldap_logout_url with $dest"
120 );
121 0 $class->set_header_out( $req,
122 ( "internal_lemonldap_logout_url" => "$dest" ) );
123 0 1;
124 },
125 0 0
126 );
127 }
128  
129 0 ▶sub logout_app_sso {
Subroutine logout_app_sso: not called CC=1 SCAR=6.9
Pod undocumented
130 0 my $class = shift;
131 0 my $u = shift;
132 0 $class->logger->debug("Nginx logout_app_sso redirect to $u");
133 return (
134 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
135 0 my ( $req, $session ) = @_;
136 0 $class->localUnlog( $req, @_ );
137 0 my $portal = $class->tsv->{portal}->($req);
138 0 ▶ my $dest = $u || $portal;
Condition0%0/3
$u || $portal
l!l&&r!l&&!r
000
MC/DC0%0/2
$u || $portal
$u $portal
Truth table0%0/3
A || B
A= $uB= $portal
ABresult
1X1
011
000
139 0 my $rurl =
140 $portal . "?url="
141 . $class->encodeUrl( $req, $dest )
142 . "&logout=1";
143 0 $class->logger->debug(
144 "logout_app: sending internal_lemonldap_logout_url with $rurl");
145 0 $class->set_header_out( $req,
146 ( "internal_lemonldap_logout_url" => "$rurl" ) );
147 0 1;
148 },
149 0 0
150 );
151 }
152  
153 23 *setPostParams = *addToHtmlHead;
154  
155 23 1;
« Lemonldap/NG/Handler/Server/Nginx.pm ↑ Summary Lemonldap/NG/Handler/Lib/DevOpsCDA.pm »