Merge branch 'fix-jail-log-2568' into 'v2.0'

Fix Safe jail error reporting

See merge request lemonldap-ng/lemonldap-ng!213
This commit is contained in:
Yadd 2021-07-26 16:00:02 +00:00
commit b756ee4d6a
3 changed files with 24 additions and 13 deletions

View File

@ -129,13 +129,7 @@ sub token {
# Fake reval method if useSafeJail is off
sub reval {
my ( $self, $e ) = @_;
my $res = eval $e;
if ($@) {
$self->error($@);
return undef;
}
return $res;
return eval $e;
}
## @method wrap_code_ref
@ -183,8 +177,7 @@ sub jail_reval {
# if nothing is returned by reval, add the return statement to
# the "no safe wrap" reval
my $res;
eval { $res = ( $self->jail->reval($reval) ) };
my $res = $self->jail->reval($reval);
if ($@) {
$self->error($@);
return undef;

View File

@ -6,7 +6,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use strict;
use Test::More tests => 20;
use Test::More tests => 22;
require 't/test.pm';
BEGIN { use_ok('Lemonldap::NG::Handler::Main::Jail') }
@ -60,7 +60,7 @@ ok(
ok( $res = &$code, "Function works" );
ok( $res == 1, 'Get good result' );
$sub = "sub { return(checkDate('20000101000000+0100','21000101000000+0100')) }";
$sub = "sub { return(checkDate('20000101000000+0100','21000101000000+0100')) }";
$code = $jail->jail_reval($sub);
ok(
( defined($code) and ref($code) eq 'CODE' ),
@ -105,3 +105,11 @@ is(
"Function works"
);
$sub = "sub { return(";
$code = $jail->jail_reval($sub);
ok( ( not defined($code) ), 'Syntax error yields undef result' );
like(
$jail->error,
qr/Missing right curly or square bracket/,
'Found correct error message'
);

View File

@ -5,7 +5,7 @@
# change 'tests => 1' to 'tests => last_test_to_print';
use Test::More tests => 14;
use Test::More tests => 16;
require 't/test.pm';
BEGIN { use_ok('Lemonldap::NG::Handler::Main::Jail') }
@ -43,7 +43,8 @@ my $checkDate = $jail->jail_reval($sub3);
ok( &$checkDate == "1",
'checkDate extended function working without Safe Jail' );
my $sub4 = "sub { return(checkDate('20000101000000+0100','21000101000000+0100')) }";
my $sub4 =
"sub { return(checkDate('20000101000000+0100','21000101000000+0100')) }";
my $checkDate = $jail->jail_reval($sub4);
ok( &$checkDate == "1",
'checkDate extended function working without Safe Jail' );
@ -96,3 +97,12 @@ is(
0,
"Function works"
);
$sub = "sub { return(";
$code = $jail->jail_reval($sub);
ok( ( not defined($code) ), 'Syntax error yields undef result' );
like(
$jail->error,
qr/Missing right curly or square bracket/,
'Found correct error message'
);