lemonldap-ng/lemonldap-ng-manager/t/12-save-changed-conf.t

220 lines
6.0 KiB
Perl
Raw Normal View History

2016-01-07 12:40:24 +01:00
# Verify that a modified configuration can be saved and that all changes are
# detected
use Test::More;
use strict;
2016-01-13 20:47:56 +01:00
use JSON;
2015-05-14 08:45:03 +02:00
require 't/test-lib.pm';
2015-05-14 08:45:03 +02:00
my $struct = 't/jsonfiles/12-modified.json';
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]; };
2017-01-27 10:39:58 +01:00
mkdir 't/sessions';
my ( $res, $resBody );
2016-01-01 20:55:35 +01:00
ok( $res = &client->_post( '/confs/', 'cfgNum=1', &body, 'application/json' ),
2019-02-05 23:12:17 +01:00
"Request succeed" );
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" );
ok( $resBody->{result} == 1, "JSON response contains \"result:1\"" )
2019-02-05 23:12:17 +01:00
or print STDERR Dumper($resBody);
ok(
@{ $resBody->{details}->{__warnings__} } == 2,
2018-12-01 22:40:22 +01:00
'JSON response contains 2 warnings'
) or print STDERR Dumper($resBody);
2018-12-29 18:50:30 +01:00
2019-02-05 23:12:17 +01:00
foreach my $i ( 0 .. 1 ) {
ok(
$resBody->{details}->{__warnings__}->[$i]->{message} =~
/\b(unprotected|cross-domain-authentication)\b/,
2018-12-29 18:50:30 +01:00
"Warning with 'unprotect', 'CDA' or 'retries' found"
) or print STDERR Dumper($resBody);
}
2019-02-05 23:12:17 +01:00
ok(
@{ $resBody->{details}->{__changes__} } == 20,
2018-12-29 22:04:44 +01:00
'JSON response contains 24 changes'
) 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);
ok( -f $confFiles->[1], 'File is created' );
2018-12-29 22:04:44 +01:00
count(4);
my @changes = @{&changes};
2015-12-25 11:45:51 +01:00
my @cmsg = @{ $resBody->{details}->{__changes__} };
my $bug;
2018-12-01 22:37:10 +01:00
2015-12-25 11:45:51 +01:00
while ( my $c = shift @{ $resBody->{details}->{__changes__} } ) {
my $cmp1 = @changes;
my $cmp2 = @cmsg;
my @d1 = grep { $_->{key} eq $c->{key} } @changes;
my @d2 = grep { $_->{key} eq $c->{key} } @cmsg;
@changes = grep { $_->{key} ne $c->{key} } @changes;
@cmsg = grep { $_->{key} ne $c->{key} } @cmsg;
2018-08-30 07:40:51 +02:00
if ( $c->{key} eq 'applicationList' ) {
pass qq("$c->{key}" found);
}
else {
2018-08-30 07:40:51 +02: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 )
. "\nExpect: "
. Dumper( \@d1 ) . "Got: "
. Dumper( \@d2 );
2018-08-30 07:40:51 +02:00
}
count(1);
}
ok( !@changes, 'All changes detected' ) or $bug = 1;
if ($bug) {
print STDERR 'Expected not found: '
2019-02-05 23:12:17 +01:00
. Dumper( \@changes )
. 'Changes announced and not found: '
. Dumper( \@cmsg );
}
#print STDERR Dumper(\@changes,\@cmsg);
count(6);
# TODO: check result of this
2016-03-20 23:35:14 +01:00
ok( $res = &client->jsonResponse('/diff/1/2'), 'Diff called' );
my ( @c1, @c2 );
2017-01-12 07:05:06 +01:00
ok( ( @c1 = sort keys %{ $res->[0] } ), 'diff() detects changes in conf 1' );
ok( ( @c2 = sort keys %{ $res->[1] } ), 'diff() detects changes in conf 2' );
2017-03-31 18:15:38 +02:00
ok( @c1 == 11, '11 keys changed in conf 1' )
2019-02-05 23:12:17 +01:00
or print STDERR "Expect: 11 keys, get: " . join( ', ', @c1 ) . "\n";
2017-03-16 13:25:36 +01:00
ok( @c2 == 14, '14 keys changed or created in conf 2' )
2019-02-05 23:12:17 +01:00
or print STDERR "Expect: 14 keys, get: " . join( ',', @c2 ) . "\n";
2016-03-20 23:35:14 +01:00
count(5);
unlink $confFiles->[1];
2018-12-01 22:37:10 +01:00
2018-12-01 22:36:03 +01:00
#eval { rmdir 't/sessions'; };
done_testing( count() );
2018-12-01 22:36:03 +01:00
# 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',
'new' => 'http://auth2.example.com/',
'old' => 'http://auth.example.com/'
},
2019-02-05 23:12:17 +01:00
{
'new' => 0,
'old' => 1,
'key' => 'portalDisplayLogout'
},
2019-02-05 23:12:17 +01:00
{
'key' =>
'applicationList, Sample applications, Application Test 1, uri',
'old' => 'http://test1.example.com/',
'new' => 'http://testex.example.com/'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'Application Test 3',
'key' => 'applicationList, Sample applications'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'Changes in cat(s)/app(s)',
'key' => 'applicationList',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'applicationList',
'old' => 'Documentation',
'new' => 'Administration',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'applicationList',
'old' => 'Administration',
'new' => 'Sample applications',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'applicationList',
'old' => 'Sample applications',
'new' => 'Documentation',
},
2019-02-05 23:12:17 +01:00
{
'key' => 'userDB',
'new' => 'LDAP',
'old' => 'Demo'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'passwordDB',
'new' => 'LDAP',
'old' => 'Demo'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'openIdSPList',
'new' => '1;bad.com'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'Uid',
'key' => 'exportedVars'
},
2019-02-05 23:12:17 +01:00
{
'key' =>
'locationRules, test1.example.com, (?#Logout comment)^/logout',
'new' => 'logout_sso',
'old' => undef
},
2019-02-05 23:12:17 +01:00
{
'old' => '^/logout',
'key' => 'locationRules, test1.example.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules, test3.example.com, ^/logout',
'new' => 'logout_sso',
'old' => undef
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules, test3.example.com, default',
'old' => undef,
'new' => 'accept'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules',
'new' => 'test3.example.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'exportedHeaders, test3.example.com, Auth-User',
'old' => undef,
'new' => '$uid'
},
2019-02-05 23:12:17 +01:00
{
'new' => 'test3.example.com',
'key' => 'exportedHeaders'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules, test.ex.com, default',
'old' => undef,
'new' => 'deny'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'locationRules',
'new' => 'test.ex.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'virtualHosts',
'new' => 'test3.example.com',
'old' => 'test2.example.com'
},
2019-02-05 23:12:17 +01:00
{
'key' => 'virtualHosts',
'old' => 'test2.example.com'
}
];
}