diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/StatusConstants.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/StatusConstants.pm index 26b7f53e8..a06f1d476 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/StatusConstants.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Lib/StatusConstants.pm @@ -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', diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/PortalConstants.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/PortalConstants.pm index 3787d8064..756cf71ea 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/PortalConstants.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Build/PortalConstants.pm @@ -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 }; } diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm index 95281c406..5cdcdad3e 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Constants.pm @@ -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' ], ); diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CheckDevOps.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CheckDevOps.pm index 3e7e4dfde..5b8b835b8 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CheckDevOps.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/CheckDevOps.pm @@ -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'" ); } } diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/ar.json b/lemonldap-ng-portal/site/htdocs/static/languages/ar.json index 57d926f9c..1abdebd45 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/ar.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/ar.json @@ -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":"ليس لديك إذن بالدخول لهذا التطبيق", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/de.json b/lemonldap-ng-portal/site/htdocs/static/languages/de.json index e89ddad98..d716ac74e 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/de.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/de.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/en.json b/lemonldap-ng-portal/site/htdocs/static/languages/en.json index 6e71977b2..d0e0269e1 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/en.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/en.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/es.json b/lemonldap-ng-portal/site/htdocs/static/languages/es.json index 3bd1041fe..bad9828d9 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/es.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/es.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/fi.json b/lemonldap-ng-portal/site/htdocs/static/languages/fi.json index 6c4e309bd..51f2638fc 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/fi.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/fi.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/fr.json b/lemonldap-ng-portal/site/htdocs/static/languages/fr.json index a2a3beba6..1469c50f8 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/fr.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/fr.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/it.json b/lemonldap-ng-portal/site/htdocs/static/languages/it.json index 4b917e589..a8abe5cfc 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/it.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/it.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/nl.json b/lemonldap-ng-portal/site/htdocs/static/languages/nl.json index 5edb57381..7ad13e0cf 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/nl.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/nl.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/pl.json b/lemonldap-ng-portal/site/htdocs/static/languages/pl.json index ff12e25a3..df0cdd03d 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/pl.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/pl.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/pt.json b/lemonldap-ng-portal/site/htdocs/static/languages/pt.json index 450185f53..7e26514e9 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/pt.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/pt.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/ro.json b/lemonldap-ng-portal/site/htdocs/static/languages/ro.json index 14d2bf78c..9a225d922 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/ro.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/ro.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/tr.json b/lemonldap-ng-portal/site/htdocs/static/languages/tr.json index 414a4f24f..5934b2087 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/tr.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/tr.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/vi.json b/lemonldap-ng-portal/site/htdocs/static/languages/vi.json index 605e1e99e..50cf4960e 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/vi.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/vi.json @@ -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", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/zh.json b/lemonldap-ng-portal/site/htdocs/static/languages/zh.json index 0664e9ce9..f7afdd4f0 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/zh.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/zh.json @@ -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 方法", diff --git a/lemonldap-ng-portal/site/htdocs/static/languages/zh_TW.json b/lemonldap-ng-portal/site/htdocs/static/languages/zh_TW.json index 9426039cf..350c3b83e 100644 --- a/lemonldap-ng-portal/site/htdocs/static/languages/zh_TW.json +++ b/lemonldap-ng-portal/site/htdocs/static/languages/zh_TW.json @@ -95,6 +95,7 @@ "PE102":"工作階段必須升級", "PE103":"您的帳號沒有可用的第二因素", "PE104":"Bad DevOps handler file", +"PE105":"File not found", "2FDeviceNotFound":"找不到雙因素驗證裝置", "2fRegRequired":"此服務需要雙因素驗證。請先註冊裝置,然後在回到首頁。", "accept":"接受", diff --git a/lemonldap-ng-portal/t/56-CheckDevOps-with-Download.t b/lemonldap-ng-portal/t/56-CheckDevOps-with-Download.t index cc6c7912c..a3689856a 100644 --- a/lemonldap-ng-portal/t/56-CheckDevOps-with-Download.t +++ b/lemonldap-ng-portal/t/56-CheckDevOps-with-Download.t @@ -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; }