Lemonldap/NG/Handler/Server/Traefik.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 6 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 92.5% 50 / 54 CC 5 SCAR 9.8
CC
5
Cov
98%
handler
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« Lemonldap/NG/Handler/ApacheMP2/Main.pm ↑ Summary Lemonldap/NG/Handler/Main/SharedVariables.pm »
1 package Lemonldap::NG::Handler::Server::Traefik;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Lemonldap::NG::Handler::Server::Main;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '2.19.0';
8  
9 1 extends 'Lemonldap::NG::Handler::PSGI';
10  
11 1 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
12 1 my $self = shift;
13 1 $self->api('Lemonldap::NG::Handler::Server::Main');
14 1 my $tmp = $self->SUPER::init(@_);
15 }
16  
17 1 ▶sub _run {
Subroutine _run: called CC=1 SCAR=0.0
18 1 my $self = shift;
19  
20 # Create regular _authAndTrace PSGI app
21 my $app = $self->psgiAdapter(
22 21 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
23 21 my $req = $_[0];
24 21 return $self->_authAndTrace($req);
25 }
26 1 );
27  
28 # Middleware to set correct values for Traefik
29 21 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 21 my $env = $_[0];
31 21 $env->{HTTP_HOST} = $env->{HTTP_X_FORWARDED_HOST};
32 21 $env->{REQUEST_URI} = $env->{HTTP_X_FORWARDED_URI};
33  
34 # Traefik/Caddy don't expose the routed URI: X-Forwarded-Uri is all
35 # we have, so it is the source of the access control URI
36 21 $self->api->setAccessControlUri($env);
37 21 return $app->($env);
38 }
39 1 }
40  
41 8 ▶sub handler {
Subroutine handler: called CC=5 SCAR=16.1
Pod undocumented
42 8 my ( $self, $req ) = @_;
43 my @convertedHdrs =
44 8 ▶ ( 'Content-Length' => 0, Cookie => ( $req->env->{HTTP_COOKIE} // '' ) );
Condition50%1/2
$req->env->{"HTTP_COOKIE"} // ""
l!l
08
MC/DC0%0/1
$req->env->{"HTTP_COOKIE"} // ""
$req->env->{"HTTP_COOKIE"}
Truth table50%1/2
A
A= $req->env->{"HTTP_COOKIE"}
Aresult
11
00
45 8 ▶ while ( my ( $k, $v ) = splice( @{ $req->{respHeaders} }, 0, 2 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@{$$req{"respHeaders"};}, 0, 2)) 38 8 46
46 38 ▶ if ( $k =~ /^(?:Deleteheader\d+|Cookie)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k =~ /^(?:Deleteheader\d+|Cookie)$/) { } 18 20 38
47 18 next;
48 }
49 else {
50 20 push @convertedHdrs, $k, $v;
51 }
52 }
53  
54 # Echo the Authorization header to compensate the fact that Traefik removes
55 # it from the incoming HTTP request
56 8 ▶ if ( my $authorization = $req->headers->header('Authorization') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $authorization = $req->headers->header("Authorization")) 1 7 8
57 1 push @convertedHdrs, "Authorization" => $authorization;
58 }
59  
60 8 return [ 200, \@convertedHdrs, [] ];
61 }
62  
63 1 1;
« Lemonldap/NG/Handler/ApacheMP2/Main.pm ↑ Summary Lemonldap/NG/Handler/Main/SharedVariables.pm »