Commit 5886cbe2 authored by Xavier Guimard's avatar Xavier Guimard

Tidy

parent e2b026b7
......@@ -16,8 +16,10 @@ BEGIN { use_ok('Lemonldap::NG::Common::Conf') }
my $h;
ok( $h = new Lemonldap::NG::Common::Conf(
{ type => 'File',
ok(
$h = new Lemonldap::NG::Common::Conf(
{
type => 'File',
dirName => "t/",
}
),
......@@ -37,15 +39,15 @@ my @test = (
{ cfgNum => 1, test => 'éà' }
);
for ( my $i = 0; $i < @test; $i++ ) {
for ( my $i = 0 ; $i < @test ; $i++ ) {
ok( $h->store( $test[$i] ) == 1, "Test $i is stored" )
or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
or print STDERR "$Lemonldap::NG::Common::Conf::msg $!";
$count++;
my $cfg;
ok( $cfg = $h->load(1), "Test $i can be read" )
or print STDERR $Lemonldap::NG::Common::Conf::msg;
or print STDERR $Lemonldap::NG::Common::Conf::msg;
ok( $cfg->{test} eq $test[$i]->{test}, "Test $i is restored" )
or print STDERR "Expect $cfg->{test} eq $test[$i]->{test}\n";
or print STDERR "Expect $cfg->{test} eq $test[$i]->{test}\n";
$count += 2;
}
......
......@@ -109,7 +109,7 @@ sub statusInit {
exec $perl_exec, '-MLemonldap::NG::Handler::Lib::Status',
# Insert @INC in Perl path
map( {"-I$_"} @INC ),
map( { "-I$_" } @INC ),
# Command to launch
'-e', '&Lemonldap::NG::Handler::Lib::Status::run()',
......
......@@ -5,21 +5,22 @@ use Data::Dumper;
require 't/test-psgi-lib.pm';
init('Lemonldap::NG::Handler::PSGI', {
vhostOptions => {
'test1.example.com' => {
vhostHttps => 1,
vhostPort => 443,
init(
'Lemonldap::NG::Handler::PSGI',
{
vhostOptions => {
'test1.example.com' => {
vhostHttps => 1,
vhostPort => 443,
},
},
},
locationRules => {
},
exportedHeaders => {
},
https => undef,
port => undef,
maintenance => undef,
});
locationRules => {},
exportedHeaders => {},
https => undef,
port => undef,
maintenance => undef,
}
);
my $res;
......
......@@ -45,7 +45,7 @@ sub addRoutes {
$self->setTypes($conf);
$self->{multiValuesSeparator} ||= '; ';
$self->{hiddenAttributes} //= "_password";
$self->{TOTPCheck} = $self->{U2FCheck} = $self->{UBKCheck} = '1';
$self->{TOTPCheck} = $self->{U2FCheck} = $self->{UBKCheck} = '1';
}
###################
......
......@@ -2203,8 +2203,8 @@ sub attributes {
default => 0,
},
samlIDPMetaDataOptionsUserAttribute => { type => 'text', },
samlIDPMetaDataOptionsDisplayName => { type => 'text', },
samlIDPMetaDataOptionsIcon => { type => 'text', },
samlIDPMetaDataOptionsDisplayName => { type => 'text', },
samlIDPMetaDataOptionsIcon => { type => 'text', },
# SP keys
samlSPMetaDataExportedAttributes => {
......@@ -2563,10 +2563,9 @@ m{^(?:ldapi://[^/]*/?|\w[\w\-\.]*(?::\d{1,5})?|ldap(?:s|\+tls)?://\w[\w\-\.]*(?:
documentation => 'LDAP filter for auth search'
},
ldapGroupDecodeSearchedValue => {
default => 0,
type => 'bool',
documentation =>
'Decode value before searching it in LDAP groups',
default => 0,
type => 'bool',
documentation => 'Decode value before searching it in LDAP groups',
},
ldapGroupRecursive => {
default => 0,
......
......@@ -88,7 +88,7 @@ sub cTrees {
"samlIDPMetaDataOptionsCheckAudience"
]
},
{
{
title => "samlIDPMetaDataOptionsDisplay",
form => 'simpleInputContainer',
nodes => [
......
......@@ -36,40 +36,40 @@ sub addRoutes {
# HTML template
$self->addRoute( 'manager.html', undef, ['GET'] )
# READ
# Special keys
->addRoute(
# READ
# Special keys
->addRoute(
confs => {
':cfgNum' => [
qw(virtualHosts samlIDPMetaDataNodes samlSPMetaDataNodes
applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes
casSrvMetaDataNodes casAppMetaDataNodes
authChoiceModules grantSessionRules combModules
openIdIDPList)
applicationList oidcOPMetaDataNodes oidcRPMetaDataNodes
casSrvMetaDataNodes casAppMetaDataNodes
authChoiceModules grantSessionRules combModules
openIdIDPList)
]
},
['GET']
)
)
# Other keys
->addRoute( confs => { ':cfgNum' => { '*' => 'getKey' } }, ['GET'] )
# Other keys
->addRoute( confs => { ':cfgNum' => { '*' => 'getKey' } }, ['GET'] )
# New key and conf save
->addRoute(
# New key and conf save
->addRoute(
confs => {
newRSAKey => 'newRSAKey',
raw => 'newRawConf',
'*' => 'newConf'
},
['POST']
)
)
# Difference between confs
->addRoute( diff => { ':conf1' => { ':conf2' => 'diff' } } )
->addRoute( 'diff.html', undef, ['GET'] )
# Difference between confs
->addRoute( diff => { ':conf1' => { ':conf2' => 'diff' } } )
->addRoute( 'diff.html', undef, ['GET'] )
# Url loader
->addRoute( 'prx', undef, ['POST'] );
# Url loader
->addRoute( 'prx', undef, ['POST'] );
}
# 35 - New RSA key pair on demand
......@@ -85,7 +85,7 @@ sub addRoutes {
sub newRSAKey {
my ( $self, $req, @others ) = @_;
return $self->sendError( $req, 'There is no subkey for "newRSAKey"', 400 )
if (@others);
if (@others);
my $query = $req->jsonBodyToObj;
my $rsa = Crypt::OpenSSL::RSA->generate_key(2048);
my $keys = {
......@@ -127,12 +127,12 @@ sub newRSAKey {
sub prx {
my ( $self, $req, @others ) = @_;
return $self->sendError( $req, 'There is no subkey for "prx"', 400 )
if (@others);
if (@others);
my $query = $req->jsonBodyToObj;
return $self->sendError( $req, 'Missing parameter', 400 )
unless ( $query->{url} );
unless ( $query->{url} );
return $self->sendError( $req, 'Bad parameter', 400 )
unless ( $query->{url} =~ m#^(?:f|ht)tps?://\w# );
unless ( $query->{url} =~ m#^(?:f|ht)tps?://\w# );
$self->ua->timeout(10);
my $response = $self->ua->get( $query->{url} );
......@@ -140,12 +140,11 @@ sub prx {
return $self->sendError( $req,
$response->code . " (" . $response->message . ")", 400 );
}
unless ( $response->header('Content-Type')
=~ m#^(?:application/json|(?:application|text)/.*xml).*$# )
unless ( $response->header('Content-Type') =~
m#^(?:application/json|(?:application|text)/.*xml).*$# )
{
return $self->sendError( $req,
'Content refused for security reason (neither XML or JSON)',
400 );
'Content refused for security reason (neither XML or JSON)', 400 );
}
return $self->sendJSONresponse( $req, { content => $response->content } );
}
......@@ -189,7 +188,7 @@ sub getConfByNum {
sub newConf {
my ( $self, $req, @other ) = @_;
return $self->sendError( $req, 'There is no subkey for "newConf"', 400 )
if (@other);
if (@other);
# Body must be json
my $new = $req->jsonBodyToObj;
......@@ -207,9 +206,9 @@ sub newConf {
return $self->sendError(
$req,
"Configuration "
. $req->params('cfgNum')
. " not available "
. $Lemonldap::NG::Common::Conf::msg,
. $req->params('cfgNum')
. " not available "
. $Lemonldap::NG::Common::Conf::msg,
400
);
}
......@@ -233,15 +232,14 @@ sub newConf {
# "message" fields: note that words enclosed by "__" (__word__) will be
# translated
$res->{details}->{'__errors__'} = $parser->{errors}
if ( @{ $parser->{errors} } );
if ( @{ $parser->{errors} } );
unless ( @{ $parser->{errors} } ) {
$res->{details}->{'__needConfirmation__'}
= $parser->{needConfirmation}
if ( @{ $parser->{needConfirmation} } && !$req->params('force') );
$res->{details}->{'__needConfirmation__'} = $parser->{needConfirmation}
if ( @{ $parser->{needConfirmation} } && !$req->params('force') );
$res->{message} = $parser->{message};
foreach my $t (qw(warnings changes)) {
$res->{details}->{ '__' . $t . '__' } = $parser->$t
if ( @{ $parser->$t } );
if ( @{ $parser->$t } );
}
}
if ( $res->{result} ) {
......@@ -253,7 +251,7 @@ sub newConf {
$args{force} = 1 if ( $req->params('force') );
my $s = CONFIG_WAS_CHANGED;
$s = $self->confAcc->saveConf( $parser->newConf, %args )
unless ( @{ $parser->{needConfirmation} } && !$args{force} );
unless ( @{ $parser->{needConfirmation} } && !$args{force} );
if ( $s > 0 ) {
$self->userLogger->notice(
'User ' . $self->userId($req) . " has stored conf $s" );
......@@ -261,19 +259,19 @@ sub newConf {
$res->{cfgNum} = $s;
if ( my $status = $self->applyConf( $parser->newConf ) ) {
push @{ $res->{details}->{__applyResult__} },
{ message => "$_: $status->{$_}" }
foreach ( keys %$status );
{ message => "$_: $status->{$_}" }
foreach ( keys %$status );
}
}
else {
$self->userLogger->notice(
'Saving attempt rejected, asking for confirmation to '
. $self->userId($req) );
. $self->userId($req) );
$res->{result} = 0;
if ( $s == CONFIG_WAS_CHANGED ) {
$res->{needConfirm} = 1;
$res->{message} .= '__needConfirmation__'
unless @{ $parser->{needConfirmation} };
unless @{ $parser->{needConfirmation} };
}
else {
$res->{message} = $Lemonldap::NG::Common::Conf::msg;
......@@ -292,7 +290,7 @@ sub newConf {
sub newRawConf {
my ( $self, $req, @other ) = @_;
return $self->sendError( $req, 'There is no subkey for "newConf"', 400 )
if (@other);
if (@other);
# Body must be json
my $new = $req->jsonBodyToObj;
......@@ -317,7 +315,7 @@ sub newRawConf {
else {
$self->userLogger->notice(
'Raw saving attempt rejected, asking for confirmation to '
. $self->userId($req) );
. $self->userId($req) );
$res->{result} = 0;
$res->{needConfirm} = 1 if ( $s == CONFIG_WAS_CHANGED );
$res->{message} .= '__needConfirmation__';
......@@ -339,8 +337,8 @@ sub applyConf {
$self->api->checkConf();
# Get apply section values
my %reloadUrls
= %{ $self->confAcc->getLocalConf( APPLYSECTION, undef, 0 ) };
my %reloadUrls =
%{ $self->confAcc->getLocalConf( APPLYSECTION, undef, 0 ) };
if ( !%reloadUrls && $newConf->{reloadUrls} ) {
%reloadUrls = %{ $newConf->{reloadUrls} };
}
......@@ -356,7 +354,8 @@ sub applyConf {
my $targetUrl = $url->scheme . "://" . $host;
$targetUrl .= ":" . $url->port if defined( $url->port );
$targetUrl .= $url->full_path;
$r = HTTP::Request->new( 'GET', $targetUrl,
$r =
HTTP::Request->new( 'GET', $targetUrl,
HTTP::Headers->new( Host => $url->host ) );
if ( defined $url->userinfo
&& $url->userinfo =~ /^([^:]+):(.*)$/ )
......@@ -367,14 +366,12 @@ sub applyConf {
my $response = $self->ua->request($r);
if ( $response->code != 200 ) {
$status->{$host}
= "Error "
. $response->code . " ("
. $response->message . ")";
$status->{$host} =
"Error " . $response->code . " (" . $response->message . ")";
$self->logger->error( "Apply configuration for $host: error "
. $response->code . " ("
. $response->message
. ")" );
. $response->code . " ("
. $response->message
. ")" );
}
else {
$status->{$host} = "OK";
......@@ -388,14 +385,14 @@ sub applyConf {
sub diff {
my ( $self, $req, @path ) = @_;
return $self->sendError( $req, 'to many arguments in path info', 400 )
if (@path);
my @cfgNum
= ( scalar( $req->param('conf1') ), scalar( $req->param('conf2') ) );
if (@path);
my @cfgNum =
( scalar( $req->param('conf1') ), scalar( $req->param('conf2') ) );
my @conf;
$self->logger->debug(" Loading confs");
# Load the 2 configurations
for ( my $i = 0; $i < 2; $i++ ) {
for ( my $i = 0 ; $i < 2 ; $i++ ) {
if ( %{ $self->currentConf }
and $cfgNum[$i] == $self->currentConf->{cfgNum} )
{
......@@ -406,7 +403,7 @@ sub diff {
{ cfgNum => $cfgNum[$i], raw => 1, noCache => 1 } );
return $self->sendError(
$req,
"Configuration $cfgNum[$i] not available $Lemonldap::NG::Common::Conf::msg",
"Configuration $cfgNum[$i] not available $Lemonldap::NG::Common::Conf::msg",
400
) unless ( $conf[$i] );
}
......@@ -414,7 +411,8 @@ sub diff {
require Lemonldap::NG::Manager::Conf::Diff;
return $self->sendJSONresponse(
$req,
[ $self->Lemonldap::NG::Manager::Conf::Diff::diff(
[
$self->Lemonldap::NG::Manager::Conf::Diff::diff(
$conf[0], $conf[1]
)
]
......
......@@ -19,44 +19,50 @@ mkdir 't/sessions';
my ( $res, $resBody );
ok( $res = &client->_post( '/confs/', 'cfgNum=1', &body, 'application/json' ),
"Request succeed"
);
"Request succeed" );
ok( $res->[0] == 200, "Result code is 200" );
ok( $resBody = from_json( $res->[2]->[0] ),
"Result body contains JSON text" );
ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" );
ok( $resBody->{result} == 0, "JSON response contains \"result:0\"" )
or print STDERR Dumper($resBody);
or print STDERR Dumper($resBody);
ok( $resBody->{needConfirm} == 1, "JSON response contains \"needConfirm:1\"" )
or print STDERR Dumper($resBody);
or print STDERR Dumper($resBody);
ok( @{ $resBody->{details}->{__warnings__} } == 3,
ok(
@{ $resBody->{details}->{__warnings__} } == 3,
'JSON response contains 3 warnings'
) or print STDERR Dumper($resBody);
foreach my $i (0 .. 2) {
ok( $resBody->{details}->{__warnings__}->[$i]->{message}
=~ /\b(unprotected|cross-domain-authentication|retries)\b/,
foreach my $i ( 0 .. 2 ) {
ok(
$resBody->{details}->{__warnings__}->[$i]->{message} =~
/\b(unprotected|cross-domain-authentication|retries)\b/,
"Warning with 'unprotect', 'CDA' or 'retries' found"
) or print STDERR Dumper($resBody);
}
count(4);
ok( @{ $resBody->{details}->{__needConfirmation__} } == 1,
ok(
@{ $resBody->{details}->{__needConfirmation__} } == 1,
'JSON response contains 1 needConfirmation'
) or print STDERR Dumper($resBody);
ok( $resBody->{details}->{__needConfirmation__}->[0]->{message}
=~ /\bplugin is enabled without CSRF Token neither Captcha required\b/,
ok(
$resBody->{details}->{__needConfirmation__}->[0]->{message} =~
/\bplugin is enabled without CSRF Token neither Captcha required\b/,
"Warning with confirmation needed found"
) or print STDERR Dumper($resBody);
ok( @{ $resBody->{details}->{__changes__} } == 22,
ok(
@{ $resBody->{details}->{__changes__} } == 22,
'JSON response contains 24 changes'
) or print STDERR Dumper($resBody);
#print STDERR Dumper($resBody);
ok( $res = &client->_post( '/confs/', 'cfgNum=1&force=1', &body, 'application/json' ),
ok(
$res = &client->_post(
'/confs/', 'cfgNum=1&force=1', &body, 'application/json'
),
"Request succeed"
);
......@@ -79,13 +85,13 @@ while ( my $c = shift @{ $resBody->{details}->{__changes__} } ) {
}
else {
ok( ( $cmp1 - @changes ) == ( $cmp2 - @cmsg ), qq("$c->{key}" found) )
or print STDERR 'Expect: '
. ( $cmp1 - @changes )
. ', got: '
. ( $cmp2 - @cmsg )
. "\nExpect: "
. Dumper( \@d1 ) . "Got: "
. Dumper( \@d2 );
or print STDERR 'Expect: '
. ( $cmp1 - @changes )
. ', got: '
. ( $cmp2 - @cmsg )
. "\nExpect: "
. Dumper( \@d1 ) . "Got: "
. Dumper( \@d2 );
}
count(1);
}
......@@ -93,9 +99,9 @@ ok( !@changes, 'All changes detected' ) or $bug = 1;
if ($bug) {
print STDERR 'Expected not found: '
. Dumper( \@changes )
. 'Changes announced and not found: '
. Dumper( \@cmsg );
. Dumper( \@changes )
. 'Changes announced and not found: '
. Dumper( \@cmsg );
}
#print STDERR Dumper(\@changes,\@cmsg);
......@@ -108,9 +114,9 @@ my ( @c1, @c2 );
ok( ( @c1 = sort keys %{ $res->[0] } ), 'diff() detects changes in conf 1' );
ok( ( @c2 = sort keys %{ $res->[1] } ), 'diff() detects changes in conf 2' );
ok( @c1 == 12, '11 keys changed in conf 1' )
or print STDERR "Expect: 12 keys, get: " . join( ', ', @c1 ) . "\n";
or print STDERR "Expect: 12 keys, get: " . join( ', ', @c1 ) . "\n";
ok( @c2 == 16, '14 keys changed or created in conf 2' )
or print STDERR "Expect: 16 keys, get: " . join( ',', @c2 ) . "\n";
or print STDERR "Expect: 16 keys, get: " . join( ',', @c2 ) . "\n";
count(5);
......@@ -124,89 +130,112 @@ done_testing( count() );
sub changes {
return [
{ 'key' => 'portal',
{
'key' => 'portal',
'new' => 'http://auth2.example.com/',
'old' => 'http://auth.example.com/'
},
{ 'new' => 0,
{
'new' => 0,
'old' => 1,
'key' => 'portalDisplayLogout'
},
{ 'key' =>
'applicationList, Sample applications, Application Test 1, uri',
{
'key' =>
'applicationList, Sample applications, Application Test 1, uri',
'old' => 'http://test1.example.com/',
'new' => 'http://testex.example.com/'
},
{ 'new' => 'Application Test 3',
{
'new' => 'Application Test 3',
'key' => 'applicationList, Sample applications'
},
{ 'new' => 'Changes in cat(s)/app(s)',
{
'new' => 'Changes in cat(s)/app(s)',
'key' => 'applicationList',
},
{ 'key' => 'applicationList',
{
'key' => 'applicationList',
'old' => 'Documentation',
'new' => 'Administration',
},
{ 'key' => 'applicationList',
{
'key' => 'applicationList',
'old' => 'Administration',
'new' => 'Sample applications',
},
{ 'key' => 'applicationList',
{
'key' => 'applicationList',
'old' => 'Sample applications',
'new' => 'Documentation',
},
{ 'key' => 'userDB',
{
'key' => 'userDB',
'new' => 'LDAP',
'old' => 'Demo'
},
{ 'key' => 'passwordDB',
{
'key' => 'passwordDB',
'new' => 'LDAP',
'old' => 'Demo'
},
{ 'key' => 'openIdSPList',
{
'key' => 'openIdSPList',
'new' => '1;bad.com'
},
{ 'new' => 'Uid',
{
'new' => 'Uid',
'key' => 'exportedVars'
},
{ 'key' =>
'locationRules, test1.example.com, (?#Logout comment)^/logout',
{
'key' =>
'locationRules, test1.example.com, (?#Logout comment)^/logout',
'new' => 'logout_sso',
'old' => undef
},
{ 'old' => '^/logout',
{
'old' => '^/logout',
'key' => 'locationRules, test1.example.com'
},
{ 'key' => 'locationRules, test3.example.com, ^/logout',
{
'key' => 'locationRules, test3.example.com, ^/logout',
'new' => 'logout_sso',
'old' => undef
},
{ 'key' => 'locationRules, test3.example.com, default',
{
'key' => 'locationRules, test3.example.com, default',
'old' => undef,
'new' => 'accept'
},
{ 'key' => 'locationRules',
{
'key' => 'locationRules',
'new' => 'test3.example.com'
},
{ 'key' => 'exportedHeaders, test3.example.com, Auth-User',
{
'key' => 'exportedHeaders, test3.example.com, Auth-User',
'old' => undef,
'new' => '$uid'
},
{ 'new' => 'test3.example.com',
{
'new' => 'test3.example.com',
'key' => 'exportedHeaders'
},
{ 'key' => 'locationRules, test.ex.com, default',
{
'key' => 'locationRules, test.ex.com, default',
'old' => undef,
'new' => 'deny'
},
{ 'key' => 'locationRules',
{
'key' => 'locationRules',
'new' => 'test.ex.com'
},
{ 'key' => 'virtualHosts',
{
'key' => 'virtualHosts',
'new' => 'test3.example.com',
'old' => 'test2.example.com'
},
{ 'key' => 'virtualHosts',
{
'key' => 'virtualHosts',
'old' => 'test2.example.com'
},
{
......@@ -218,6 +247,6 @@ sub changes {
'new' => 0,
'key' => 'captcha_mail_enabled',
'old' => '1'
}
}
];
}
......@@ -19,27 +19,29 @@ mkdir 't/sessions';
my ( $res, $resBody );
ok( $res = &client->_post( '/confs/', 'cfgNum=1', &body, 'application/json' ),
"Request succeed"
);
"Request succeed" );
ok( $res->[0] == 200, "Result code is 200" );
ok( $resBody = from_json( $res->[2]->[0] ),
"Result body contains JSON text" );
ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" );
ok( $resBody->{result} == 1, "JSON response contains \"result:1\"" )
or print STDERR Dumper($resBody);
ok( @{ $resBody->{details}->{__warnings__} } == 2,
or print STDERR Dumper($resBody);
ok(
@{ $resBody->{details}->{__warnings__} } == 2,
'JSON response contains 2 warnings'
) or print STDERR Dumper($resBody);
foreach my $i (0 .. 1) {
ok( $resBody->{details}->{__warnings__}->[$i]->{message}
=~ /\b(unprotected|cross-domain-authentication)\b/,
foreach my $i ( 0 .. 1 ) {
ok(
$resBody->{details}->{__warnings__}->[$i]->{message} =~
/\b(unprotected|cross-domain-authentication)\b/,
"Warning with 'unprotect', 'CDA' or 'retries' found"
) or print STDERR Dumper($resBody);