lemonldap-ng/lemonldap-ng-manager/t/11-save-changed-conf-with-confirmation.t

250 lines
6.9 KiB
Perl
Raw Normal View History

2018-12-29 18:50:30 +01:00
# Verify that a modified configuration can be saved and that all changes are
# detected
use Test::More;
use strict;
use JSON;
require 't/test-lib.pm';
2019-07-02 20:03:40 +02:00
my $struct = 't/jsonfiles/11-modified-with-confirmation.json';
2018-12-29 18:50:30 +01:00
my $confFiles = [ 't/conf/lmConf-1.json', 't/conf/lmConf-2.json' ];
sub body {
return IO::File->new( $struct, 'r' );
}
# Delete lmConf-2.json if exists
eval { unlink $confFiles->[1]; };
mkdir 't/sessions';
my ( $res, $resBody );
ok( $res = &client->_post( '/confs/', 'cfgNum=1', &body, 'application/json' ),
2019-02-05 23:12:17 +01:00
"Request succeed" );
2022-02-16 17:43:29 +01:00
ok( $res->[0] == 200, "Result code is 200" );
2019-02-05 23:12:17 +01:00
ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" );
2018-12-29 18:50:30 +01:00
ok( $resBody->{result} == 0, "JSON response contains \"result:0\"" )
2019-02-05 23:12:17 +01:00
or print STDERR Dumper($resBody);
2018-12-29 18:50:30 +01:00
ok( $resBody->{needConfirm} == 1, "JSON response contains \"needConfirm:1\"" )
2019-02-05 23:12:17 +01:00
or print STDERR Dumper($resBody);
ok(
2020-12-02 08:04:52 +01:00
@{ $resBody->{details}->{__warnings__} } == 4,
'JSON response contains 4 warnings'
2018-12-29 18:50:30 +01:00
) or print STDERR Dumper($resBody);
2020-12-02 08:04:52 +01:00
count(6);
2018-12-29 18:50:30 +01:00
2020-12-02 08:04:52 +01:00
foreach my $i ( 0 .. 3 ) {
2019-02-05 23:12:17 +01:00
ok(
$resBody->{details}->{__warnings__}->[$i]->{message} =~
2022-02-16 17:43:29 +01:00
/\b(unprotected|cross-domain-authentication|retries|__badExpressionAssignment__)\b/,
"Warning with 'unprotect', 'CDA', 'assignment' or 'retries' found"
2018-12-29 18:50:30 +01:00
) or print STDERR Dumper($resBody);
2020-12-02 08:04:52 +01:00
count(1);
2018-12-29 18:50:30 +01:00
}
2019-02-05 23:12:17 +01:00
ok(
2020-12-02 08:04:52 +01:00
@{ $resBody->{details}->{__needConfirmation__} } == 1,
'JSON response contains 1 needConfirmation'
2018-12-29 18:50:30 +01:00
) or print STDERR Dumper($resBody);
2019-02-05 23:12:17 +01:00
ok(
@{ $resBody->{details}->{__changes__} } == 24,
'JSON response contains 24 changes'
2018-12-29 18:50:30 +01:00
) or print STDERR Dumper($resBody);
2019-02-05 23:12:17 +01:00
2018-12-29 22:04:44 +01:00
#print STDERR Dumper($resBody);
2019-02-05 23:12:17 +01:00
ok(
$res = &client->_post(
'/confs/', 'cfgNum=1&force=1', &body, 'application/json'
),
2018-12-29 18:50:30 +01:00
"Request succeed"
);
ok( -f $confFiles->[1], 'File is created' );
2020-10-30 14:21:42 +01:00
count(4);
2018-12-29 18:50:30 +01:00
my @changes = @{&changes};
my @cmsg = @{ $resBody->{details}->{__changes__} };
my $bug;
while ( my $c = shift @{ $resBody->{details}->{__changes__} } ) {
my $cmp1 = @changes;
my $cmp2 = @cmsg;
2019-09-16 17:43:27 +02:00
@changes = grep { ( $_->{key} || '' ) ne ( $c->{key} || '' ) } @changes;
@cmsg = grep { ( $_->{key} || '' ) ne ( $c->{key} || '' ) } @cmsg;
if ( $c->{key} and $c->{key} eq 'applicationList' ) {
2018-12-29 18:50:30 +01:00
pass qq("$c->{key}" found);
2019-09-16 17:43:27 +02:00
count(1);
2018-12-29 18:50:30 +01:00
}
2019-09-16 17:43:27 +02:00
elsif ( $c->{key} ) {
2018-12-29 18:50:30 +01:00
ok( ( $cmp1 - @changes ) == ( $cmp2 - @cmsg ), qq("$c->{key}" found) )
2019-02-05 23:12:17 +01:00
or print STDERR 'Expect: '
. ( $cmp1 - @changes )
. ', got: '
. ( $cmp2 - @cmsg )
2019-09-16 17:43:27 +02:00
. "\nChanges "
. Dumper( \@changes )
. "Cmsg: "
. Dumper( \@cmsg );
count(1);
2018-12-29 18:50:30 +01:00
}
}
ok( !@changes, 'All changes detected' ) or $bug = 1;
2020-12-02 08:04:52 +01:00
count(1);
2018-12-29 18:50:30 +01:00
if ($bug) {
print STDERR 'Expected not found: '
2019-02-05 23:12:17 +01:00
. Dumper( \@changes )
. 'Changes announced and not found: '
. Dumper( \@cmsg );
2018-12-29 18:50:30 +01:00
}
#print STDERR Dumper(\@changes,\@cmsg);
# TODO: check result of this
ok( $res = &client->jsonResponse('/diff/1/2'), 'Diff called' );
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' );
2019-09-01 21:41:41 +02:00
ok( @c1 == 12, '12 keys changed in conf 1' )
2019-02-05 23:12:17 +01:00
or print STDERR "Expect: 12 keys, get: " . join( ', ', @c1 ) . "\n";
ok( @c2 == 17, '17 keys changed or created in conf 2' )
or print STDERR "Expect: 17 keys, get: " . join( ',', @c2 ) . "\n";
2018-12-29 18:50:30 +01:00
count(5);
unlink $confFiles->[1];
#eval { rmdir 't/sessions'; };
done_testing( count() );
# Remove sessions directory
`rm -rf t/sessions`;
sub changes {
2019-02-07 09:27:56 +01:00
return [ {
2019-02-05 23:12:17 +01:00
'key' => 'portal',
2018-12-29 18:50:30 +01:00
'new' => 'http://auth2.example.com/',
'old' => 'http://auth.example.com/'
},
2019-02-05 23:12:17 +01:00
{
'new' => 0,
2018-12-29 18:50:30 +01:00
'old' => 1,
'key' => 'portalDisplayLogout'
},
2019-02-05 23:12:17 +01:00
{
'key' =>
'applicationList, Sample applications, Application Test 1, uri',
2018-12-29 18:50:30 +01:00
'old' => 'http://test1.example.com/',
'new' => 'http://testex.example.com/'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'Application Test 3',
2018-12-29 18:50:30 +01:00
'key' => 'applicationList, Sample applications'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'Changes in cat(s)/app(s)',
2018-12-29 18:50:30 +01:00
'key' => 'applicationList',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'applicationList',
2018-12-29 18:50:30 +01:00
'old' => 'Documentation',
'new' => 'Administration',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'applicationList',
2018-12-29 18:50:30 +01:00
'old' => 'Administration',
'new' => 'Sample applications',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'applicationList',
2018-12-29 18:50:30 +01:00
'old' => 'Sample applications',
'new' => 'Documentation',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'userDB',
2018-12-29 18:50:30 +01:00
'new' => 'LDAP',
'old' => 'Demo'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'passwordDB',
2018-12-29 18:50:30 +01:00
'new' => 'LDAP',
'old' => 'Demo'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'openIdSPList',
2018-12-29 18:50:30 +01:00
'new' => '1;bad.com'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'Uid',
2018-12-29 18:50:30 +01:00
'key' => 'exportedVars'
},
2019-02-05 23:12:17 +01:00
{
'key' =>
'locationRules, test1.example.com, (?#Logout comment)^/logout',
2018-12-29 18:50:30 +01:00
'new' => 'logout_sso',
'old' => undef
},
2019-02-05 23:12:17 +01:00
{
'old' => '^/logout',
2018-12-29 18:50:30 +01:00
'key' => 'locationRules, test1.example.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules, test3.example.com, ^/logout',
2018-12-29 18:50:30 +01:00
'new' => 'logout_sso',
'old' => undef
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules, test3.example.com, default',
2018-12-29 18:50:30 +01:00
'old' => undef,
'new' => 'accept'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules',
2018-12-29 18:50:30 +01:00
'new' => 'test3.example.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'exportedHeaders, test3.example.com, Auth-User',
2018-12-29 18:50:30 +01:00
'old' => undef,
'new' => '$uid'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'test3.example.com',
2018-12-29 18:50:30 +01:00
'key' => 'exportedHeaders'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules, test.ex.com, default',
2018-12-29 18:50:30 +01:00
'old' => undef,
'new' => 'deny'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules',
2018-12-29 18:50:30 +01:00
'new' => 'test.ex.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'virtualHosts',
2018-12-29 18:50:30 +01:00
'new' => 'test3.example.com',
'old' => 'test2.example.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'virtualHosts',
2018-12-29 18:50:30 +01:00
'old' => 'test2.example.com'
},
{
'new' => 1,
'key' => 'portalDisplayResetPassword',
'old' => 0
},
{
'new' => 0,
'key' => 'captcha_mail_enabled',
'old' => '1'
2019-09-01 21:41:41 +02:00
},
{
'confCompacted' => '1',
2020-02-20 23:34:02 +01:00
'removedKeys' => 'some; keys'
},
{
'new' => 1,
'key' => 'avoidAssignment',
'old' => '0'
2019-02-05 23:12:17 +01:00
}
2018-12-29 18:50:30 +01:00
];
}