Commit 5f7981e2 authored by Christophe Maudoux's avatar Christophe Maudoux 🐛
Browse files

Improve error message & unit test (#2458)

parent 1757cf53
......@@ -21,6 +21,7 @@ sub portalConsts {
'102' => 'PE_UPGRADESESSION',
'103' => 'PE_NO_SECOND_FACTORS',
'104' => 'PE_BAD_DEVOPS_FILE',
'105' => 'PE_FILENOTFOUND',
'2' => 'PE_FORMEMPTY',
'20' => 'PE_NO_PASSWORD_BE',
'21' => 'PE_PP_ACCOUNT_LOCKED',
......
......@@ -112,7 +112,8 @@ sub portalConstants {
PE_PP_NOT_ALLOWED_CHARACTERS => 101,
PE_UPGRADESESSION => 102,
PE_NO_SECOND_FACTORS => 103,
PE_BAD_DEVOPS_FILE => 104
PE_BAD_DEVOPS_FILE => 104,
PE_FILENOTFOUND => 105
};
}
......
......@@ -109,6 +109,7 @@ use constant {
PE_UPGRADESESSION => 102,
PE_NO_SECOND_FACTORS => 103,
PE_BAD_DEVOPS_FILE => 104,
PE_FILENOTFOUND => 105,
};
sub portalConsts {
......@@ -126,6 +127,7 @@ sub portalConsts {
'102' => 'PE_UPGRADESESSION',
'103' => 'PE_NO_SECOND_FACTORS',
'104' => 'PE_BAD_DEVOPS_FILE',
'105' => 'PE_FILENOTFOUND',
'2' => 'PE_FORMEMPTY',
'20' => 'PE_NO_PASSWORD_BE',
'21' => 'PE_PP_ACCOUNT_LOCKED',
......@@ -322,7 +324,8 @@ our @EXPORT_OK = (
'PE_PP_NOT_ALLOWED_CHARACTERS',
'PE_UPGRADESESSION',
'PE_NO_SECOND_FACTORS',
'PE_BAD_DEVOPS_FILE'
'PE_BAD_DEVOPS_FILE',
'PE_FILENOTFOUND'
);
our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK, 'import' ], );
......
......@@ -10,6 +10,7 @@ use Lemonldap::NG::Portal::Main::Constants qw(
PE_BADURL
PE_NOTOKEN
PE_TOKENEXPIRED
PE_FILENOTFOUND
PE_BAD_DEVOPS_FILE
);
......@@ -133,21 +134,33 @@ sub run {
$url = "$proto$vhost/rules.json";
my $response =
$self->ua->get( $url, 'Accept' => 'application/json' );
$self->logger->debug( "Message/Code from $url: "
. $response->{_msg} . '/'
. $response->{_rc} );
$self->logger->debug( "Code/Message from $url: "
. $response->{_rc} . '/'
. $response->{_msg} );
$self->logger->debug(
"Content from $url: " . $response->{_content} );
$json = eval { from_json( $response->{_content} ) };
"Content from $url: " . $response->{_content} ) if $response->{_content};
if ($@) {
if ( $response->{_rc} == 200 ) {
$json = eval { from_json( $response->{_content} ) };
if ($@) {
# Prepare form params
$msg = 'PE' . PE_BAD_DEVOPS_FILE;
$alert = 'alert-danger';
$json = '';
$self->userLogger->error(
"CheckDevOps: bad 'rules.json' file retrieved from $url ($@)"
);
}
}
else {
# Prepare form params
$msg = 'PE' . PE_BAD_DEVOPS_FILE;
$msg = 'PE' . PE_FILENOTFOUND;
$alert = 'alert-danger';
$json = '';
$self->userLogger->error(
"CheckDevOps: bad 'rules.json' file retrieved from $url ($@)"
"CheckDevOps: Unable to download 'rules.json' file from $url"
);
}
}
......@@ -157,7 +170,7 @@ sub run {
$msg = 'PE' . PE_BADURL;
$alert = 'alert-danger';
$json = '';
$self->userLogger->error('CheckDevOps: bad URL provided');
$self->userLogger->error('CheckDevOps: bad provided URL');
}
}
unless ( $json || $msg ) {
......@@ -185,7 +198,7 @@ sub run {
delete $json->{headers}->{$_};
my $user = $req->userData->{ $self->conf->{whatToTrace} };
$self->userLogger->warn(
"CheckDevOps: $user tried to retrieve hidden attribute $v"
"CheckDevOps: $user tried to retrieve hidden attribute '$v'"
);
}
}
......
......@@ -94,8 +94,9 @@
"PE101":"Password contains not allowed characters",
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"2FDeviceNotFound":"2F device not found",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"قبول",
"accessDenied":"ليس لديك إذن بالدخول لهذا التطبيق",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"Dieser Dienst benötigt Zwei-Faktor-Authentifizierung. Bitte legen Sie ein Gerät an und gehen dann zum Portal zurück.",
"accept":"Akzeptieren",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"Este servicio necesita la autenticación de dos factores. Registre un dispositivo ahora, luego reingrese al portal.",
"accept":"Aceptar",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Hyväksy",
......
......@@ -95,6 +95,7 @@
"PE102":"Mise à niveau de la session",
"PE103":"Aucun second facteur disponible pour votre compte",
"PE104":"Fichier DevOps mal formaté",
"PE105":"Fichier inexistant",
"2FDeviceNotFound":"Second facteur non trouvé",
"2fRegRequired":"Ce service requiert une authentification à deux facteurs. Enregistrez un équipement ici et retournez au portail.",
"accept":"Accepter",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"Questo servizio richiede un'autenticazione a doppio fattore. Registrare un dispositivo ora, quindi tornare al portale.",
"accept":"Accetta",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept",
......
......@@ -95,6 +95,7 @@
"PE102":"Sesja musi zostać zaktualizowana",
"PE103":"Na Twoim koncie nie ma dostępnych drugich czynników",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"Nie znaleziono urządzenia 2F",
"2fRegRequired":"Ta usługa wymaga podwójnego uwierzytelnienia. Zarejestruj urządzenie 2ndFA teraz, a następnie wróć do portalu.",
"accept":"Akceptuj",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept",
......
......@@ -95,6 +95,7 @@
"PE102":"Oturum yükseltilmeli",
"PE103":"Hesabınız için ikinci faktör kullanılabilir değil",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F cihazı bulunamadı",
"2fRegRequired":"Bu servis iki adımlı kimlik doğrulama gerektiriyor. Şimdi bir cihaz ekleyin ve ardından portala geri dönün",
"accept":"Kabul Et",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Chấp nhận",
......
......@@ -95,6 +95,7 @@
"PE102":"Session must be upgraded",
"PE103":"No second factors available for your account",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"2F device not found",
"2fRegRequired":"This service requires a double factor authentication. Register a device now, then go back to the portal.",
"accept":"Accept 方法",
......
......@@ -95,6 +95,7 @@
"PE102":"工作階段必須升級",
"PE103":"您的帳號沒有可用的第二因素",
"PE104":"Bad DevOps handler file",
"PE105":"File not found",
"2FDeviceNotFound":"找不到雙因素驗證裝置",
"2fRegRequired":"此服務需要雙因素驗證。請先註冊裝置,然後在回到首頁。",
"accept":"接受",
......
......@@ -25,7 +25,7 @@ my $file = '{
}';
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
logLevel => 'debug',
authentication => 'Demo',
userDB => 'Same',
requireToken => 0,
......@@ -123,6 +123,26 @@ count(13);
( $host, $url, $query ) =
expectForm( $res, undef, '/checkdevops', 'checkDevOpsFile' );
# Fail to download file
# ---------------------
$query = 'url=http://testfail.example.com';
ok(
$res = $client->_post(
'/checkdevops',
IO::String->new($query),
cookie => "lemonldap=$id",
length => length($query),
),
'POST checkdevops with url'
);
ok( $res = eval { from_json( $res->[2]->[0] ) }, 'Response is JSON' )
or print STDERR "$@\n" . Dumper($res);
ok( $res->{ALERTE} eq 'alert-danger', 'alert-danger found' )
or print STDERR Dumper($res);
ok( $res->{MSG} eq 'PE105', 'PE105' )
or print STDERR Dumper($res);
count(4);
# Download file
# -------------
$query = 'url=http://test3.example.com';
......@@ -174,9 +194,16 @@ sub LWP::UserAgent::request {
"Name": "$cn"
}
}';
$httpResp = HTTP::Response->new( 200, 'OK' );
$httpResp->header( 'Content-Type', 'application/json' );
$httpResp->header( 'Content-Length', length($s) );
$httpResp->content($s);
if ( $req->{_uri} =~ /testfail\.example\.com/ ) {
$httpResp = HTTP::Response->new( 404, 'NOT FOUND' );
$httpResp->header( 'Content-Length', 0 );
}
else {
$httpResp = HTTP::Response->new( 200, 'OK' );
$httpResp->header( 'Content-Length', length($s) );
$httpResp->header( 'Content-Type', 'application/json' );
$httpResp->content($s);
}
return $httpResp;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment