Allow hashes in Combination module overload (Closes: #1707)

This commit is contained in:
Xavier 2019-04-09 21:01:55 +02:00
parent f1cb8d236e
commit 046585020f
3 changed files with 27 additions and 5 deletions

View File

@ -1,14 +1,27 @@
package Lemonldap::NG::Common::Conf::Wrapper;
use strict;
use JSON;
our $VERSION = '2.0.0';
sub TIEHASH {
my ( $class, $conf, $overrides ) = @_;
my %h = %$overrides;
foreach ( keys %h ) {
if ( $h{$_} =~ /^[\[\{]/ ) {
my $tmp = eval { JSON::from_json( $h{$_} ) };
if ($@) {
print STDERR "Wrapper: unable to compile $_ key, skipping\n";
}
else {
$h{$_} = $tmp;
}
}
}
return bless {
_wrapC => $conf,
_wrapO => $overrides,
_wrapO => \%h,
}, $class;
}

View File

@ -47,7 +47,7 @@ sub set_user {
sub set_header_in {
my ( $class, $req, %headers ) = @_;
while ( my ( $h, $v ) = each %headers ) {
$req->{env}->{ cgiName($h) } = $v;
$req->{env}->{ cgiName($h) } = $v if ( defined $v );
}
}

View File

@ -47,8 +47,9 @@ sub try {
sub iniCmb {
my $expr = shift;
count(1);
if (
my $res = LLNG::Manager::Test->new( {
my $client = LLNG::Manager::Test->new( {
ini => {
logLevel => 'error',
useSafeJail => 1,
@ -68,7 +69,7 @@ sub iniCmb {
dbiAuthLoginCol => 'user',
dbiAuthPasswordCol => 'password',
dbiAuthPasswordHash => '',
dbiExportedVars => {},
dbiExportedVars => '{"user":"user"}',
}
},
Dm => {
@ -84,7 +85,15 @@ sub iniCmb {
)
{
pass(qq'Expression loaded: "$expr"');
ok(
$client->{p}->{loadedModules}->{'Lemonldap::NG::Portal::Auth::DBI'}
->{conf}->{dbiExportedVars}->{user} eq 'user',
'JSON is parsed'
);
count(1);
return $res;
return $client;
}
else {
fail "Unable to build object";
}
}