| 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"} // ""
MC/DC0%0/1
$req->env->{"HTTP_COOKIE"} // ""
$req->env->{"HTTP_COOKIE"}
Truth table50%1/2
A
A= $req->env->{"HTTP_COOKIE"}
| |||||||||||||
| 45 | 8 | ▶ | while ( my ( $k, $v ) = splice( @{ $req->{respHeaders} }, 0, 2 ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | 38 | ▶ | if ( $k =~ /^(?:Deleteheader\d+|Cookie)$/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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
| |||||||||||||
| 57 | 1 | push @convertedHdrs, "Authorization" => $authorization; | |||||||||||
| 58 | } | ||||||||||||
| 59 | |||||||||||||
| 60 | 8 | return [ 200, \@convertedHdrs, [] ]; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 1 | 1; | |||||||||||