Fix SSL/Kerberos Auth with Choice & Improve unit tests (#1636)

This commit is contained in:
Christophe Maudoux 2019-02-03 20:05:28 +01:00
parent d70d7e11a9
commit 153084118f
5 changed files with 20 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package Lemonldap::NG::Portal::Auth::Choice;
use strict;
use Mouse;
use Lemonldap::NG::Portal::Main::Constants qw(PE_OK PE_FIRSTACCESS PE_ERROR);
use Data::Dumper;
our $VERSION = '2.0.2';
@ -29,19 +30,24 @@ sub extractFormInfo {
foreach my $mod ( values %{ $self->modules } ) {
if ( $mod->{AjaxInitScript} ) {
$self->logger->debug(
'Append ' . $mod->{Name} . ' init/script' ) if $mod->{Name};
'Append ' . $mod->{Name} . ' init/script' )
if $mod->{Name};
$req->data->{customScript} .= $mod->AjaxInitScript;
}
if ( $mod->{InitCmd} ) {
$self->logger->debug(
'Launch ' . $mod->{Name} . ' init command' ) if $mod->{Name};
'Launch ' . $mod->{Name} . ' init command' )
if $mod->{Name};
my $res = eval( $mod->{InitCmd} );
if ($@) {
$self->logger("Auth error: $@");
return PE_ERROR;
}
}
}
}
$self->logger->debug("@@@@ Req -> " . Dumper($req) );
foreach my $mod ( values %{ $self->modules } ) {
if ( $mod->can('setSecurity') ) {
$mod->setSecurity($req);

View File

@ -55,6 +55,13 @@ sub extractFormInfo {
return PE_FIRSTACCESS;
}
else {
if ( $self->conf->{sslByAjax} ) {
$self->logger->debug(
'Append ' . $self->{Name} . ' init/script' );
$req->data->{customScript} .= $self->{AjaxInitScript};
$self->logger->debug(
"Send init/script -> " . $req->data->{customScript} );
}
$self->userLogger->warn('No certificate found');
return PE_CERTIFICATEREQUIRED;
}

View File

@ -460,8 +460,9 @@ sub buildHiddenForm {
if $self->checkXSSAttack( $_, $req->{portalHiddenFormValues}->{$_} );
# Build hidden input HTML code
# 'id' is removed to avoid warning with Choice
#$val .= qq{<input type="hidden" name="$_" id="$_" value="}
$val .= qq{<input type="hidden" name="$_" id="$_" value="}
$val .= qq{<input type="hidden" name="$_" value="}
. $req->{portalHiddenFormValues}->{$_} . '" />';
}

View File

@ -48,7 +48,7 @@ SKIP: {
expectForm( $res, '#', undef, 'kerberos' );
ok( $res->[2]->[0]
=~ m%<input type="hidden" name="kerberos" id="kerberos" value="0" />%,
=~ m%<input type="hidden" name="kerberos" value="0" />%,
'Found hidden attribut "kerberos" with value="0"'
) or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ /kerberos\.(?:min\.)?js/,

View File

@ -83,7 +83,7 @@ SKIP: {
) or print STDERR Dumper( $res->[2]->[0] );
expectForm( $res, '#', undef, 'kerberos' );
ok( $res->[2]->[0]
=~ m%<input type="hidden" name="kerberos" id="kerberos" value="0" />%,
=~ m%<input type="hidden" name="kerberos" value="0" />%,
'Found hidden attribut "kerberos" with value="0"'
) or print STDERR Dumper( $res->[2]->[0] );
ok( $res->[2]->[0] =~ /kerberosChoice\.(?:min\.)?js/,