diff --git a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Jail.pm b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Jail.pm index 486ccccf6610dbf4913812f0572dac7f0fe3c9c0..272b48b1d272790b98397686b07cfb4dc24a2f4e 100644 --- a/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Jail.pm +++ b/lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main/Jail.pm @@ -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; diff --git a/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t b/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t index 25c6329d6b2c4d4424de6ee158c8d9405ba1d1fe..55ed31859f822a2874d09f0f75aa229d46b9d5d2 100644 --- a/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t +++ b/lemonldap-ng-handler/t/12-Lemonldap-NG-Handler-Jail.t @@ -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' +); diff --git a/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t b/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t index b6584b7655c61eb7380eeb1bcd792fc393bca9fb..c2911f736b4c39b2bbcab6aeec7ed8cf86a4f62f 100644 --- a/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t +++ b/lemonldap-ng-handler/t/13-Lemonldap-NG-Handler-Fake-Safe.t @@ -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' +);