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 = my $plugin =
$self->loadedModules->{ $self->loadedModules->{
"Lemonldap::NG::Portal::Plugins::FindUser"}; "Lemonldap::NG::Portal::Plugins::FindUser"};
my $fields = []; my ( $fields, $slogin, $mandatory ) = ( [], '', 0 );
my $slogin;
if ( $plugin if ( $plugin
&& $self->conf->{findUser} && $self->conf->{findUser}
&& $self->conf->{impersonationRule} && $self->conf->{impersonationRule}
&& $self->conf->{findUserSearchingAttributes} ) && $self->conf->{findUserSearchingAttributes} )
{ {
$slogin = $req->data->{findUser}; $slogin = $req->data->{findUser};
$fields = $plugin->buildForm(); ( $fields, $mandatory ) = $plugin->buildForm();
} }
# Authentication loop # Authentication loop
@ -526,6 +526,7 @@ sub display {
DISPLAY_OPENID_FORM => 0, DISPLAY_OPENID_FORM => 0,
DISPLAY_YUBIKEY_FORM => 0, DISPLAY_YUBIKEY_FORM => 0,
DISPLAY_FINDUSER => scalar @$fields, DISPLAY_FINDUSER => scalar @$fields,
MANDATORY => $mandatory,
FIELDS => $fields, FIELDS => $fields,
SPOOFID => $slogin SPOOFID => $slogin
); );
@ -559,6 +560,7 @@ sub display {
PORTAL_URL => PORTAL_URL =>
( $displayType eq "logo" ? $self->conf->{portal} : 0 ), ( $displayType eq "logo" ? $self->conf->{portal} : 0 ),
MSG => $req->info(), MSG => $req->info(),
MANDATORY => $mandatory,
FIELDS => $fields, FIELDS => $fields,
SPOOFID => $slogin SPOOFID => $slogin
); );

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -203,6 +203,7 @@
"mail2f":"Kod e-mail", "mail2f":"Kod e-mail",
"mailSent2":"Wiadomość została wysłana na Twój adres 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", "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!", "maxNumberof2FDevicesReached":"Osiągnięto maksymalną liczbę urządzeń 2F!",
"missingCode":"Brakuje kodu", "missingCode":"Brakuje kodu",
"myNotification":"Moje zaakceptowane powiadomienie", "myNotification":"Moje zaakceptowane powiadomienie",

View File

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

View File

@ -203,6 +203,7 @@
"mail2f":"Código do email", "mail2f":"Código do email",
"mailSent2":"Uma mensagem foi enviada para o seu endereço de e-mail.", "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", "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!", "maxNumberof2FDevicesReached":"Número máximo de dispositivos 2F atingido!",
"missingCode":"Falta o código", "missingCode":"Falta o código",
"myNotification":"Minha notificação aceita", "myNotification":"Minha notificação aceita",

View File

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

View File

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

View File

@ -203,6 +203,7 @@
"mail2f":"Email code", "mail2f":"Email code",
"mailSent2":"Một tin nhắn đã được gửi đến địa chỉ thư của bạn.", "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", "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!", "maxNumberof2FDevicesReached":"Maximum number of 2F devices reached!",
"missingCode":"Code is missing", "missingCode":"Code is missing",
"myNotification":"My accepted notification", "myNotification":"My accepted notification",

View File

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

View File

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

View File

@ -27,18 +27,23 @@
<option value="<TMPL_VAR NAME="key">"><TMPL_VAR NAME="value"></option> <option value="<TMPL_VAR NAME="key">"><TMPL_VAR NAME="value"></option>
</TMPL_LOOP> </TMPL_LOOP>
</select> </select>
<TMPL_IF NAME="null"><TMPL_ELSE>*</TMPL_IF>
</div> </div>
<TMPL_ELSE> <TMPL_ELSE>
<div class="input-group mb-3"> <div class="input-group mb-3">
<div class="input-group-prepend"> <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">" /> <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> <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>
</div> </div>
</TMPL_IF> </TMPL_IF>
</br> </br>
</TMPL_LOOP> </TMPL_LOOP>
</div> </div>
<TMPL_IF NAME="MANDATORY">
<span trspan="mandatoryField">* Mandatory field</span>
</TMPL_IF>
<div class="modal-footer justify-content-between"> <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="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"> <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'; require 't/test-lib.pm';
my $maintests = 25; my $maintests = 29;
my $res; my $res;
my $json; my $json;
@ -24,7 +24,8 @@ my $client = LLNG::Manager::Test->new( {
'uid##1' => 'Name', 'uid##1' => 'Name',
'guy' => 'Kind', 'guy' => 'Kind',
'type#Type#1' => 'mutant; mutant; character', '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 => findUserExcludingAttributes =>
{ type => 'mutant', uid => 'rtyler' }, { 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', ); ok( $res = $client->_get( '/', accept => 'text/html' ), 'Get Portal', );
my ( $host, $url, $query ) = my ( $host, $url, $query ) =
expectForm( $res, '#', undef, 'user', 'password', 'spoofId' ); 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 = ''; my $request = '';
ok( ok(