Mark mandatory fields & Improve unit test (#1976)

This commit is contained in:
Christophe Maudoux 2021-10-02 22:12:42 +02:00
parent c74c478b02
commit 64d55b6a93
20 changed files with 56 additions and 20 deletions

View File

@ -501,15 +501,15 @@ sub display {
my $plugin =
$self->loadedModules->{
"Lemonldap::NG::Portal::Plugins::FindUser"};
my $fields = [];
my $slogin;
my ( $fields, $slogin, $mandatory ) = ( [], '', 0 );
if ( $plugin
&& $self->conf->{findUser}
&& $self->conf->{impersonationRule}
&& $self->conf->{findUserSearchingAttributes} )
{
$slogin = $req->data->{findUser};
$fields = $plugin->buildForm();
( $fields, $mandatory ) = $plugin->buildForm();
}
# Authentication loop
@ -526,6 +526,7 @@ sub display {
DISPLAY_OPENID_FORM => 0,
DISPLAY_YUBIKEY_FORM => 0,
DISPLAY_FINDUSER => scalar @$fields,
MANDATORY => $mandatory,
FIELDS => $fields,
SPOOFID => $slogin
);
@ -548,9 +549,9 @@ sub display {
DISPLAY_YUBIKEY_FORM => $displayType =~ /\byubikeyform\b/
? 1
: 0,
DISPLAY_SSL_FORM => $displayType =~ /sslform/ ? 1 : 0,
DISPLAY_GPG_FORM => $displayType =~ /gpgform/ ? 1 : 0,
DISPLAY_LOGO_FORM => $displayType eq "logo" ? 1 : 0,
DISPLAY_SSL_FORM => $displayType =~ /sslform/ ? 1 : 0,
DISPLAY_GPG_FORM => $displayType =~ /gpgform/ ? 1 : 0,
DISPLAY_LOGO_FORM => $displayType eq "logo" ? 1 : 0,
DISPLAY_FINDUSER => scalar @$fields,
module => $displayType eq "logo"
? $self->getModule( $req, 'auth' )
@ -558,9 +559,10 @@ sub display {
AUTH_LOOP => [],
PORTAL_URL =>
( $displayType eq "logo" ? $self->conf->{portal} : 0 ),
MSG => $req->info(),
FIELDS => $fields,
SPOOFID => $slogin
MSG => $req->info(),
MANDATORY => $mandatory,
FIELDS => $fields,
SPOOFID => $slogin
);
}
}

View File

@ -17,7 +17,7 @@ extends qw(
);
# INITIALIZATION
has ott => (
has ott => (
is => 'rw',
lazy => 1,
default => sub {
@ -82,8 +82,9 @@ sub retreiveFindUserParams {
my ( $key, $value, $null ) = split '#', $_;
$key =~ s/^(?:\d+_)?//;
my $param = $req->params($key) // '';
my @values = grep s/^(?:\d+_)?//, split ($self->conf->{multiValuesSeparator},
$self->conf->{findUserSearchingAttributes}->{$_} || '');
my @values = grep s/^(?:\d+_)?//,
split( $self->conf->{multiValuesSeparator},
$self->conf->{findUserSearchingAttributes}->{$_} || '' );
my $select = scalar @values > 1 && not scalar @values % 2;
my %values = @values if $select;
my $defined = length $param;
@ -147,7 +148,7 @@ sub retreiveFindUserParams {
sub buildForm {
my $self = shift;
my $fields = [];
my ( $fields, @required ) = ( [], () );
$self->logger->debug('Building array ref with searching fields...');
@$fields =
@ -156,6 +157,7 @@ sub buildForm {
my @values = split $self->conf->{multiValuesSeparator},
$self->conf->{findUserSearchingAttributes}->{$_} || $key;
$key =~ s/^(?:\d+_)?//;
push @required, $key unless $null;
my $nbr = scalar @values;
if ( $nbr > 1 ) {
if ( $nbr % 2 ) { () }
@ -173,9 +175,9 @@ sub buildForm {
{
select => 1,
key => $key,
null => $null,
value => $value ? $value : $key,
choices => $choices
choices => $choices,
null => $null
};
}
}
@ -183,12 +185,14 @@ sub buildForm {
{
select => 0,
key => $key,
value => $values[0]
value => $values[0],
null => $null
};
}
} sort keys %{ $self->conf->{findUserSearchingAttributes} };
$self->logger->debug('Mandatory field(s) required') if scalar @required;
return $fields;
return ( $fields, scalar @required );
}
sub _sendResult {

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"تم إرسال رسالة إلى عنوان بريدك الإلكتروني.",
"maintenanceMode":"هذا التطبيق في صيانة، يرجى محاولة الاتصال في وقت لاحق",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"Eine Nachricht wurde an deine E-Mail Adresse gesendet.",
"maintenanceMode":"Diese Anwendung ist in Wartung, bitte versuche später eine Verbindung herzustellen",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code fehlt",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"A message has been sent to your mail address.",
"maintenanceMode":"This application is in maintenance, please try to connect later",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Código de e-mail",
"mailSent2":"Un mensaje ha sido enviado a su dirección de e-mail",
"maintenanceMode":"Aplicación en mantenimiento, por favor intente conectarse luego",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"¡El límite de dispositivos 2F ha sido alcanzado!",
"missingCode":"Código faltante",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"Viesti on lähetetty sähköpostiisi.",
"maintenanceMode":"This application is in maintenance, please try to connect later",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Code par mail",
"mailSent2":"Un message a été envoyé à votre adresse mail.",
"maintenanceMode":"Cette application est en maintenance, merci de réessayer plus tard",
"mandatoryField":"* Champ obligatoire",
"maxNumberof2FDevicesReached":"Nombre maximum de seconds facteurs atteint !",
"missingCode":"Code manquant",
"myNotification":"Ma notification acceptée",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"Vi é stato inviato un messaggio via mail",
"maintenanceMode":"Questa applicazione è in manutenzione, prova a connetterti più tardi",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Raggiunto il numero massimo di dispositivi 2F !",
"missingCode":"Manca il codice",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"A message has been sent to your mail address.",
"maintenanceMode":"This application is in maintenance, please try to connect later",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Kod e-mail",
"mailSent2":"Wiadomość została wysłana na Twój adres e-mail.",
"maintenanceMode":"Ta aplikacja jest w trakcie prac serwisowych, spróbuj połączyć się później",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Osiągnięto maksymalną liczbę urządzeń 2F!",
"missingCode":"Brakuje kodu",
"myNotification":"Moje zaakceptowane powiadomienie",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"A message has been sent to your mail address.",
"maintenanceMode":"This application is in maintenance, please try to connect later",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Código do email",
"mailSent2":"Uma mensagem foi enviada para o seu endereço de e-mail.",
"maintenanceMode":"Este aplicativo está em manutenção. Por favor, tente conectar mais tarde",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Número máximo de dispositivos 2F atingido!",
"missingCode":"Falta o código",
"myNotification":"Minha notificação aceita",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"A message has been sent to your mail address.",
"maintenanceMode":"This application is in maintenance, please try to connect later",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"E-posta kodu",
"mailSent2":"E-posta adresinize bir mesaj gönderildi.",
"maintenanceMode":"Bu uygulama şuan bakımda, lütfen daha sonra bağlanmayı deneyin",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maksimum 2F cihaz sayısına ulaşıldı!",
"missingCode":"Kod eksik",
"myNotification":"Kabul edilen bildirimim",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"Một tin nhắn đã được gửi đến địa chỉ thư của bạn.",
"maintenanceMode":"Ứng dụng này đang trong quá trình bảo trì, hãy thử kết nối sau",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"Email code",
"mailSent2":"已经发送一封邮件到您的邮箱",
"maintenanceMode":"程序维护中,请稍后再尝试连接。",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing",
"myNotification":"My accepted notification",

View File

@ -203,6 +203,7 @@
"mail2f":"電子郵件代碼",
"mailSent2":"訊息已傳送到您的電子郵件地址。",
"maintenanceMode":"此應用程式正在維護中,請稍後再嘗試連線",
"mandatoryField":"* Mandatory field",
"maxNumberof2FDevicesReached":"已達到雙因素驗證裝置的最大數量了!",
"missingCode":"代碼遺失",
"myNotification":"我已接受的通知",

View File

@ -27,18 +27,23 @@
<option value="<TMPL_VAR NAME="key">"><TMPL_VAR NAME="value"></option>
</TMPL_LOOP>
</select>
<TMPL_IF NAME="null"><TMPL_ELSE>*</TMPL_IF>
</div>
<TMPL_ELSE>
<div class="input-group mb-3">
<div class="input-group-prepend">
<input id="findUser_<TMPL_VAR NAME="key">" name="<TMPL_VAR NAME="key">" type="text" autocomplete="off" class="form-control" placeholder="<TMPL_VAR NAME="value">" />
<span class="input-group-text clear-finduser-field"><i class="fa fa-eraser"></i></span>
<TMPL_IF NAME="null"><TMPL_ELSE>*</TMPL_IF>
</div>
</div>
</TMPL_IF>
</br>
</TMPL_LOOP>
</div>
<TMPL_IF NAME="MANDATORY">
<span trspan="mandatoryField">* Mandatory field</span>
</TMPL_IF>
<div class="modal-footer justify-content-between">
<button id="closefinduserform" type="button" class="btn btn-secondary mr-auto" data-dismiss="modal"><span trspan="close">Close</span></button>
<button id="finduserbutton" type="submit" class="btn btn-info" data-dismiss="modal">

View File

@ -5,7 +5,7 @@ use IO::String;
require 't/test-lib.pm';
my $maintests = 25;
my $maintests = 29;
my $res;
my $json;
@ -22,9 +22,10 @@ my $client = LLNG::Manager::Test->new( {
findUserWildcard => '*',
findUserSearchingAttributes => {
'uid##1' => 'Name',
'guy' => 'Kind',
'guy' => 'Kind',
'type#Type#1' => 'mutant; mutant; character',
'cn#Name' => 'Bad Guy; Not a good person; The Daleks; daleks'
'cn#Name' =>
'2_Bad Guy; Not a good person; 1_The Daleks; daleks'
},
findUserExcludingAttributes =>
{ type => 'mutant', uid => 'rtyler' },
@ -37,6 +38,14 @@ use Lemonldap::NG::Portal::Main::Constants 'PE_USERNOTFOUND';
ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
my ( $host, $url, $query ) =
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' );
ok( $res->[2]->[0] =~ m%mandatoryField%, 'Mandatory field' )
or explain( $res->[2]->[0], 'Mandatory' );
my @c = ( $res->[2]->[0] =~ m%<option value="(.+?)">%gs );
ok( @c == 2, ' -> Two entries found' )
or explain( $res->[2]->[0], '2, found ' . scalar @c );
ok( $c[0] eq 'The Daleks', '1st -> ' . $c[0] );
ok( $c[1] eq 'Bad Guy', '2nd -> ' . $c[1] );
my $request = '';
ok(