Test if Vhost is HTTP or HTTPS & improve unit test (#2386)
This commit is contained in:
parent
f963afd812
commit
b04bb6ab84
|
@ -333,7 +333,7 @@ sub check {
|
|||
|
||||
# Check url format
|
||||
my $originalUrl;
|
||||
( $url, $originalUrl ) = $self->_resolveURL($url);
|
||||
( $url, $originalUrl ) = $self->_resolveURL( $req, $url );
|
||||
|
||||
# User is allowed ?
|
||||
$self->logger->debug(
|
||||
|
@ -389,15 +389,17 @@ sub check {
|
|||
}
|
||||
|
||||
sub _resolveURL {
|
||||
my ( $self, $url ) = @_;
|
||||
$url = 'http://' . $url unless ( $url =~ m#^https?://[^/]*.*#i );
|
||||
my ( $proto, $vhost, $appuri ) = $url =~ m#^(https?://)([^/]*)(.*)#i;
|
||||
my ( $self, $req, $url ) = @_;
|
||||
my ($proto) = $url =~ m#^(https?://).*#i;
|
||||
my ( $vhost, $appuri ) = $url =~ m#^(?:https?://)?([^/]*)(.*)#i;
|
||||
my ($port) = $vhost =~ m#^.+(:\d+)$#;
|
||||
|
||||
$port ||= '';
|
||||
$vhost =~ s/:\d+$//;
|
||||
$vhost .= $self->conf->{domain} unless ( $vhost =~ /\./ );
|
||||
|
||||
$proto =
|
||||
$self->p->HANDLER->_isHttps( $req, $vhost ) ? 'https://' : 'http://'
|
||||
unless $proto;
|
||||
$self->logger->debug( 'VHost is ' . uc( ( split( /:/, $proto ) )[0] ) );
|
||||
my $originalVhost = $self->p->HANDLER->resolveAlias($vhost);
|
||||
|
||||
return (
|
||||
|
|
|
@ -10,7 +10,7 @@ my $res;
|
|||
|
||||
my $client = LLNG::Manager::Test->new( {
|
||||
ini => {
|
||||
logLevel => 'error',
|
||||
logLevel => 'debug',
|
||||
authentication => 'Demo',
|
||||
userDB => 'Same',
|
||||
loginHistoryEnabled => 0,
|
||||
|
@ -36,6 +36,11 @@ my $client = LLNG::Manager::Test->new( {
|
|||
authGroup => '$authenticationLevel == 1',
|
||||
realAuthGroup => '$real_authenticationLevel == 1',
|
||||
},
|
||||
vhostOptions => {
|
||||
'test2.example.com' => {
|
||||
vhostHttps => 1
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -117,6 +122,11 @@ count(1);
|
|||
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, undef, '/checkuser', 'user', 'url' );
|
||||
ok(
|
||||
$res->[2]->[0] =~
|
||||
m%<input id="urlfield" name="url" type="text" class="form-control" value="http://test1.example.com" trplaceholder="URL / DNS"%,
|
||||
'Found HTTP url'
|
||||
) or explain( $res->[2]->[0], 'HTTP url' );
|
||||
ok(
|
||||
$res->[2]->[0] =~
|
||||
m%<div class="alert alert-success"><div class="text-center"><b><span trspan="allowed"></span></b></div></div>%,
|
||||
|
@ -142,7 +152,7 @@ ok( $res->[2]->[0] =~ m%<td scope="row">Macro_1</td>%, 'Found uid' )
|
|||
ok( my $nbr = ( $res->[2]->[0] =~ s%<td scope="row">Macro_1</td>%%g ),
|
||||
'Found two macros' )
|
||||
or explain( $res->[2]->[0], 'Macros not well computed' );
|
||||
count(10);
|
||||
count(11);
|
||||
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
|
@ -186,6 +196,39 @@ ok( $res->[2]->[0] =~ m%<div class="col">realAuthGroup</div>%,
|
|||
or explain( $res->[2]->[0], 'Found group "realAuthGroup"' );
|
||||
count(7);
|
||||
|
||||
ok(
|
||||
$res = $client->_get(
|
||||
'/checkuser',
|
||||
cookie => "lemonldap=$id",
|
||||
accept => 'text/html'
|
||||
),
|
||||
'CheckUser form',
|
||||
);
|
||||
count(1);
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, undef, '/checkuser', 'user', 'url' );
|
||||
|
||||
$query =~ s/url=/url=test2.example.com/;
|
||||
|
||||
ok(
|
||||
$res = $client->_post(
|
||||
'/checkuser',
|
||||
IO::String->new($query),
|
||||
cookie => "lemonldap=$id",
|
||||
length => length($query),
|
||||
accept => 'text/html',
|
||||
),
|
||||
'POST checkuser'
|
||||
);
|
||||
( $host, $url, $query ) =
|
||||
expectForm( $res, undef, '/checkuser', 'user', 'url' );
|
||||
ok(
|
||||
$res->[2]->[0] =~
|
||||
m%<input id="urlfield" name="url" type="text" class="form-control" value="https://test2.example.com" trplaceholder="URL / DNS"%,
|
||||
'Found HTTPS url'
|
||||
) or explain( $res->[2]->[0], 'HTTP url' );
|
||||
count(2);
|
||||
|
||||
$client->logout($id);
|
||||
clean_sessions();
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user