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 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 21 ▶use base 'Lemonldap::NG::Handler::Main';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 21 our $VERSION = '2.19.0';
9  
10 # Specific modules and constants for Test or CGI
11 21 ▶use constant FORBIDDEN => 403;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use constant HTTP_UNAUTHORIZED => 401;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use constant REDIRECT => 302;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use constant OK => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 21 ▶use constant DECLINED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 21 ▶use constant DONE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 21 ▶use constant SERVER_ERROR => 500;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 21 ▶use constant AUTH_REQUIRED => 401;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 21 ▶use constant MAINTENANCE => 503;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 21 ▶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 ▶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 ▶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 sub set_user {
40 78 ▶ my ( $class, $req, $user ) = @_;
Subroutine set_user: called CC=1 SCAR=0.0
Pod undocumented
41 78 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 sub set_custom {
48 78 ▶ my ( $class, $req, $custom ) = @_;
Subroutine set_custom: called CC=2 SCAR=7.1
Pod undocumented
49 78 ▶ push @{ $req->{respHeaders} }, 'Lm-Remote-Custom' => $custom
Branch: 1 branch
BranchTrueFalseTotal
if defined $custom 78 0 78
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 sub set_header_in {
57 11 ▶ my ( $class, $req, %headers ) = @_;
Subroutine set_header_in: called CC=3 SCAR=11.1
Pod undocumented
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 sub unset_header_in {
67 19 ▶ my ( $class, $req, @headers ) = @_;
Subroutine unset_header_in: called CC=2 SCAR=6.9
Pod undocumented
68 19 foreach my $h (@headers) {
69 19 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 sub set_header_out {
77 47 ▶ my ( $class, $req, %headers ) = @_;
Subroutine set_header_out: called CC=2 SCAR=6.9
Pod undocumented
78 47 ▶ while ( my ( $h, $v ) = each %headers ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %headers) 47 47 94
79 47 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 sub is_initial_req {
87 122 ▶ return 1;
Subroutine is_initial_req: called CC=1 SCAR=0.0
Pod undocumented
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 sub print {
94 0 ▶ my ( $class, $req, $data ) = @_;
Subroutine print: not called CC=1 SCAR=6.9
Pod undocumented
95 0 $req->{respBody} .= $data;
96 }
97  
98 sub addToHtmlHead {
99 0 ▶ my $self = shift;
Subroutine addToHtmlHead: not called CC=1 SCAR=6.9
Pod undocumented
100 0 $self->logger->error(
101 'Features like form replay or logout_app can only be used with Apache');
102 }
103  
104 sub cgiName {
105 383 ▶ my $h = uc(shift);
Subroutine cgiName: called CC=1 SCAR=0.0
Pod undocumented
106 383 $h =~ s/-/_/g;
107 383 return "HTTP_$h";
108 }
109  
110 sub logout_app {
111 0 ▶ my $class = shift;
Subroutine logout_app: not called CC=1 SCAR=6.9
Pod undocumented
112 0 my $u = shift;
113 0 $class->logger->debug("Nginx logout_app redirect to $u");
114 return (
115 sub {
116 0 ▶ my ( $req, $session ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
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 sub logout_app_sso {
130 0 ▶ my $class = shift;
Subroutine logout_app_sso: not called CC=1 SCAR=6.9
Pod undocumented
131 0 my $u = shift;
132 0 $class->logger->debug("Nginx logout_app_sso redirect to $u");
133 return (
134 sub {
135 0 ▶ my ( $req, $session ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
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 21 *setPostParams = *addToHtmlHead;
154  
155 21 1;
« Lemonldap/NG/Handler/Server/Nginx.pm ↑ Summary Lemonldap/NG/Handler/Lib/DevOpsCDA.pm »