From 364fb8b627b24d604cbb624bddd4950bb38ea1d7 Mon Sep 17 00:00:00 2001 From: Xavier Guimard Date: Mon, 1 Jul 2019 16:45:40 +0200 Subject: [PATCH] Improve cli-restore file read (#1833) --- lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm | 6 +++--- lemonldap-ng-manager/t/16-cli.t | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm index 39302bd4d..f9c8e52ec 100644 --- a/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm +++ b/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Cli.pm @@ -213,9 +213,10 @@ sub restore { } else { die "Unable to read $file" unless ( -r $file ); - open( my $f, $file ); + open( my $f, $file ) or die $!; $conf = join '', <$f>; close $f; + die "Empty or malformed file $file" unless ( $conf =~ /\w/s ); } my $res = $self->_post( '/confs/raw', '', IO::String->new($conf), 'application/json', length($conf) ); @@ -265,8 +266,7 @@ sub _setKey { sub _save { my ( $self, $new ) = @_; require Lemonldap::NG::Manager::Conf::Parser; - my $parser = Lemonldap::NG::Manager::Conf::Parser->new( - { + my $parser = Lemonldap::NG::Manager::Conf::Parser->new( { newConf => $new, refConf => $self->mgr->currentConf, req => $self->req diff --git a/lemonldap-ng-manager/t/16-cli.t b/lemonldap-ng-manager/t/16-cli.t index 584bfe058..9c92b07e4 100644 --- a/lemonldap-ng-manager/t/16-cli.t +++ b/lemonldap-ng-manager/t/16-cli.t @@ -9,7 +9,7 @@ use strict; use_ok('Lemonldap::NG::Common::Cli'); use_ok('Lemonldap::NG::Manager::Cli'); -foreach (qw(2 3)) { +foreach ( 2 .. $tests - 3 ) { unlink "t/conf/lmConf-$_.json"; }