2016-01-07 12:40:24 +01:00
|
|
|
# Verify that a modified configuration can be saved and that all changes are
|
|
|
|
# detected
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
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:44:38 +02:00
|
|
|
|
2015-05-14 08:45:03 +02:00
|
|
|
my $struct = 't/jsonfiles/12-modified.json';
|
2017-01-27 12:58:46 +01:00
|
|
|
my $confFiles = [ 't/conf/lmConf-1.json', 't/conf/lmConf-2.json' ];
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
sub body {
|
|
|
|
return IO::File->new( $struct, 'r' );
|
|
|
|
}
|
|
|
|
|
2017-01-27 12:58:46 +01:00
|
|
|
# Delete lmConf-2.json if exists
|
2015-05-14 08:44:38 +02:00
|
|
|
eval { unlink $confFiles->[1]; };
|
2017-01-27 10:39:58 +01:00
|
|
|
mkdir 't/sessions';
|
2015-05-14 08:44:38 +02:00
|
|
|
|
|
|
|
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" );
|
2015-05-14 08:44:38 +02: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" );
|
2015-05-14 08:44:38 +02:00
|
|
|
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,
|
2019-05-08 23:20:39 +02:00
|
|
|
'JSON response contains 20 changes'
|
2018-12-29 22:04:44 +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);
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
ok( -f $confFiles->[1], 'File is created' );
|
2018-12-29 22:04:44 +01:00
|
|
|
count(4);
|
2015-05-14 08:44:38 +02:00
|
|
|
my @changes = @{&changes};
|
2015-12-25 11:45:51 +01:00
|
|
|
my @cmsg = @{ $resBody->{details}->{__changes__} };
|
2016-01-15 07:27:45 +01:00
|
|
|
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__} } ) {
|
2016-01-15 07:27:45 +01:00
|
|
|
my $cmp1 = @changes;
|
|
|
|
my $cmp2 = @cmsg;
|
|
|
|
|
2016-01-16 22:13:43 +01:00
|
|
|
my @d1 = grep { $_->{key} eq $c->{key} } @changes;
|
|
|
|
my @d2 = grep { $_->{key} eq $c->{key} } @cmsg;
|
2015-05-14 08:44:38 +02:00
|
|
|
@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' ) {
|
2018-08-16 07:34:30 +02:00
|
|
|
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
|
|
|
}
|
2016-01-15 07:27:45 +01:00
|
|
|
count(1);
|
|
|
|
}
|
|
|
|
ok( !@changes, 'All changes detected' ) or $bug = 1;
|
|
|
|
|
|
|
|
if ($bug) {
|
2016-01-16 22:13:43 +01:00
|
|
|
print STDERR 'Expected not found: '
|
2019-02-05 23:12:17 +01:00
|
|
|
. Dumper( \@changes )
|
|
|
|
. 'Changes announced and not found: '
|
|
|
|
. Dumper( \@cmsg );
|
2015-05-14 08:44:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#print STDERR Dumper(\@changes,\@cmsg);
|
|
|
|
|
2018-08-16 07:34:30 +02:00
|
|
|
count(6);
|
2015-05-14 08:44:38 +02:00
|
|
|
|
2016-03-20 10:07:33 +01:00
|
|
|
# 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 10:07:33 +01:00
|
|
|
|
2016-03-20 23:35:14 +01:00
|
|
|
count(5);
|
2016-03-20 10:07:33 +01:00
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
unlink $confFiles->[1];
|
2018-12-01 22:37:10 +01:00
|
|
|
|
2018-12-01 22:36:03 +01:00
|
|
|
#eval { rmdir 't/sessions'; };
|
2015-05-14 08:44:38 +02:00
|
|
|
done_testing( count() );
|
|
|
|
|
2018-12-01 22:36:03 +01:00
|
|
|
# Remove sessions directory
|
|
|
|
`rm -rf t/sessions`;
|
|
|
|
|
2015-05-14 08:44:38 +02:00
|
|
|
sub changes {
|
2019-02-07 09:27:56 +01:00
|
|
|
return [ {
|
2019-02-05 23:12:17 +01:00
|
|
|
'key' => 'portal',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => 'http://auth2.example.com/',
|
|
|
|
'old' => 'http://auth.example.com/'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'new' => 0,
|
2015-05-14 08:44:38 +02:00
|
|
|
'old' => 1,
|
|
|
|
'key' => 'portalDisplayLogout'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' =>
|
|
|
|
'applicationList, Sample applications, Application Test 1, uri',
|
2015-05-14 08:44:38 +02:00
|
|
|
'old' => 'http://test1.example.com/',
|
|
|
|
'new' => 'http://testex.example.com/'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'new' => 'Application Test 3',
|
2015-05-14 08:44:38 +02:00
|
|
|
'key' => 'applicationList, Sample applications'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'new' => 'Changes in cat(s)/app(s)',
|
2016-01-15 07:27:45 +01:00
|
|
|
'key' => 'applicationList',
|
2018-08-16 07:34:30 +02:00
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'applicationList',
|
2018-08-16 07:34:30 +02:00
|
|
|
'old' => 'Documentation',
|
|
|
|
'new' => 'Administration',
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'applicationList',
|
2018-08-16 07:34:30 +02:00
|
|
|
'old' => 'Administration',
|
|
|
|
'new' => 'Sample applications',
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'applicationList',
|
2018-08-16 07:34:30 +02:00
|
|
|
'old' => 'Sample applications',
|
|
|
|
'new' => 'Documentation',
|
2016-01-15 07:27:45 +01:00
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'userDB',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => 'LDAP',
|
|
|
|
'old' => 'Demo'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'passwordDB',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => 'LDAP',
|
|
|
|
'old' => 'Demo'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'openIdSPList',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => '1;bad.com'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'new' => 'Uid',
|
2015-05-14 08:44:38 +02:00
|
|
|
'key' => 'exportedVars'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' =>
|
|
|
|
'locationRules, test1.example.com, (?#Logout comment)^/logout',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => 'logout_sso',
|
|
|
|
'old' => undef
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'old' => '^/logout',
|
2015-05-14 08:44:38 +02:00
|
|
|
'key' => 'locationRules, test1.example.com'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'locationRules, test3.example.com, ^/logout',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => 'logout_sso',
|
|
|
|
'old' => undef
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'locationRules, test3.example.com, default',
|
2015-05-14 08:44:38 +02:00
|
|
|
'old' => undef,
|
|
|
|
'new' => 'accept'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'locationRules',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => 'test3.example.com'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'exportedHeaders, test3.example.com, Auth-User',
|
2015-05-14 08:44:38 +02:00
|
|
|
'old' => undef,
|
|
|
|
'new' => '$uid'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'new' => 'test3.example.com',
|
2015-05-14 08:44:38 +02:00
|
|
|
'key' => 'exportedHeaders'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'locationRules, test.ex.com, default',
|
2015-05-14 08:44:38 +02:00
|
|
|
'old' => undef,
|
|
|
|
'new' => 'deny'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'locationRules',
|
2015-05-14 08:44:38 +02:00
|
|
|
'new' => 'test.ex.com'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'virtualHosts',
|
2016-06-14 07:26:24 +02:00
|
|
|
'new' => 'test3.example.com',
|
|
|
|
'old' => 'test2.example.com'
|
|
|
|
},
|
2019-02-05 23:12:17 +01:00
|
|
|
{
|
|
|
|
'key' => 'virtualHosts',
|
2015-05-14 08:44:38 +02:00
|
|
|
'old' => 'test2.example.com'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|