Combination override conf (#1151)
TODO: lot of job in the manager...environments/ppa-mbqj77/deployments/1
parent
b78022558d
commit
8a3bb7b0f9
@ -0,0 +1,58 @@ |
||||
package Lemonldap::NG::Common::Conf::Wrapper; |
||||
|
||||
use strict; |
||||
|
||||
our $VERSION = '2.0.0'; |
||||
|
||||
sub TIEHASH { |
||||
my ( $class, $conf, $overrides ) = @_; |
||||
return bless { |
||||
_wrapC => $conf, |
||||
_wrapO => $overrides, |
||||
}, $class; |
||||
} |
||||
|
||||
sub FETCH { |
||||
my ( $self, $key ) = @_; |
||||
return ( |
||||
exists( $self->{_wrapO}->{$key} ) |
||||
? $self->{_wrapO}->{$key} |
||||
: $self->{_wrapC}->{$key} |
||||
); |
||||
} |
||||
|
||||
sub STORE { |
||||
my ( $self, $key, $value ) = @_; |
||||
return $self->{_wrapO}->{$key} = $value; |
||||
} |
||||
|
||||
sub DELETE { |
||||
my ( $self, $key ) = @_; |
||||
my $res = $self->{_wrapO}->{$key} // $self->{_wrapC}->{$key}; |
||||
$self->{_wrapO}->{$key} = undef; |
||||
return $res; |
||||
} |
||||
|
||||
sub EXISTS { |
||||
my ( $self, $key ) = @_; |
||||
return ( |
||||
exists( $self->{_wrapC}->{$key} ) |
||||
or exists( $self->{_wrapO}->{$key} ) |
||||
); |
||||
} |
||||
|
||||
sub DESTROY { |
||||
my $self = shift; |
||||
delete $self->{_wrapO}; |
||||
delete $self->{_wrapC}; |
||||
} |
||||
|
||||
sub FIRSTKEY { |
||||
return each %{ $_[0]->{_wrapC} }; |
||||
} |
||||
|
||||
sub NEXTKEY { |
||||
return each %{ $_[0]->{_wrapC} }; |
||||
} |
||||
|
||||
1; |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,95 @@ |
||||
use Test::More; |
||||
use strict; |
||||
use IO::String; |
||||
|
||||
require 't/test-lib.pm'; |
||||
|
||||
my $res; |
||||
my $mainTests = 0; |
||||
my $client; |
||||
|
||||
eval { unlink 't/userdb.db' }; |
||||
|
||||
SKIP: { |
||||
eval { require DBI; require DBD::SQLite; }; |
||||
if ($@) { |
||||
skip 'DBD::SQLite not found', $mainTests; |
||||
} |
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=t/userdb.db"); |
||||
$dbh->do('CREATE TABLE users (user text,password text,name text)'); |
||||
$dbh->do("INSERT INTO users VALUES ('dvador','dvador','Test user 1')"); |
||||
$dbh->do("INSERT INTO users VALUES ('rtyler','rtyler','Test user 1')"); |
||||
|
||||
$client = iniCmb('[Dm] or [DB]'); |
||||
expectCookie( try('dwho') ); |
||||
expectCookie( try('dvador') ); |
||||
} |
||||
count($mainTests); |
||||
clean_sessions(); |
||||
eval { unlink 't/userdb.db' }; |
||||
done_testing( count() ); |
||||
|
||||
sub try { |
||||
my $user = shift; |
||||
my $s = "user=$user&password=$user"; |
||||
my $res; |
||||
ok( |
||||
$res = $client->_post( |
||||
'/', IO::String->new($s), |
||||
length => length($s), |
||||
custom => { HTTP_X => $user } |
||||
), |
||||
" Try to connect with login $user" |
||||
); |
||||
count(1); |
||||
return $res; |
||||
} |
||||
|
||||
sub iniCmb { |
||||
my $expr = shift; |
||||
if ( |
||||
my $res = LLNG::Manager::Test->new( |
||||
{ |
||||
ini => { |
||||
logLevel => 'error', |
||||
useSafeJail => 1, |
||||
authentication => 'Combination', |
||||
userDB => 'Same', |
||||
|
||||
combination => $expr, |
||||
combModules => [ |
||||
{ |
||||
for => 0, |
||||
name => 'DB', |
||||
type => 'DBI', |
||||
}, |
||||
{ |
||||
for => 0, |
||||
name => 'Dm', |
||||
type => 'Demo', |
||||
}, |
||||
], |
||||
|
||||
combOver => { |
||||
DB => { |
||||
dbiAuthChain => 'dbi:SQLite:dbname=t/userdb.db', |
||||
dbiAuthUser => '', |
||||
dbiAuthPassword => '', |
||||
dbiAuthTable => 'users', |
||||
dbiAuthLoginCol => 'user', |
||||
dbiAuthPasswordCol => 'password', |
||||
dbiAuthPasswordHash => '', |
||||
dbiExportedVars => {}, |
||||
} |
||||
}, |
||||
demoExportedVars => {}, |
||||
} |
||||
} |
||||
) |
||||
) |
||||
{ |
||||
pass(qq'Expression loaded: "$expr"'); |
||||
count(1); |
||||
return $res; |
||||
} |
||||
} |
Loading…
Reference in new issue