lemonldap-ng/lemonldap-ng-manager/t/70-viewer.t

80 lines
2.1 KiB
Perl
Raw Normal View History

2019-03-26 22:52:41 +01:00
# Test viewer API
use Test::More;
use strict;
use IO::String;
use JSON qw(from_json);
require 't/test-lib.pm';
2019-04-01 21:57:50 +02:00
my $struct = 't/jsonfiles/70-diff.json';
2019-04-11 11:08:52 +02:00
2020-01-27 18:32:59 +01:00
# Remove new conf
unlink 't/conf/lmConf-2.json';
2019-04-01 21:57:50 +02:00
sub body {
return IO::File->new( $struct, 'r' );
}
2019-03-26 22:52:41 +01:00
# Test that key value is sent
my $res = &client->jsonResponse('/view/1/portalDisplayOidcConsents');
2022-02-16 17:43:29 +01:00
ok( $res->{value} eq '$_oidcConsents && $_oidcConsents =~ /\\w+/',
'Key found' );
2019-03-26 22:52:41 +01:00
count(1);
# Test that hidden key values are NOT sent
$res = &client->jsonResponse('/view/1/portalDisplayLogout');
2019-04-11 11:08:52 +02:00
ok( $res->{value} eq '_Hidden_', 'Key is hidden' )
or explain( $res, 'value => "_Hidden_"' );
2019-03-26 22:52:41 +01:00
$res = &client->jsonResponse('/view/1/samlIDPMetaDataNodes');
2020-01-27 18:32:59 +01:00
ok( ref($res) eq 'HASH' and $res->{value} eq '_Hidden_', 'Key is hidden' )
2019-04-11 11:08:52 +02:00
or explain( $res, 'value => "_Hidden_"' );
2019-03-26 22:52:41 +01:00
count(2);
# Try to display latest conf
$res = &client->jsonResponse('/view/latest');
2020-02-20 23:34:02 +01:00
ok( $res->{cfgNum} eq '1', 'Latest conf loaded' )
or explain( $res, "cfgNum => 1" );
2019-03-26 22:52:41 +01:00
count(1);
2019-04-11 11:08:52 +02:00
ok(
$res = &client->_post(
'/confs/', 'cfgNum=1&force=1', &body, 'application/json'
),
"Request succeed"
);
2019-04-01 21:57:50 +02:00
ok( $res->[0] == 200, "Result code is 200" );
my $resBody;
ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" );
2019-03-26 22:52:41 +01:00
count(3);
2019-04-11 11:08:52 +02:00
2019-04-01 21:57:50 +02:00
foreach my $i ( 0 .. 1 ) {
ok(
$resBody->{details}->{__changes__}->[$i]->{key} =~
/\b(captcha_login_enabled|captcha_mail_enabled)\b/,
"Details with captcha 'login' or 'mail' found"
) or print STDERR Dumper($resBody);
}
count(2);
# Try to compare confs 1 & 2
$res = &client->jsonResponse('/view/diff/1/2');
2019-04-11 11:08:52 +02:00
2020-02-07 22:00:41 +01:00
ok( $res->[1]->{captcha_login_enabled} eq '1', 'Key found' );
2020-02-20 23:34:02 +01:00
ok( $res->[1]->{captcha_mail_enabled} eq '0', 'Key found' );
ok( 7 == keys %{ $res->[1] }, 'Right number of keys found' )
2020-02-07 22:00:41 +01:00
or print STDERR Dumper($res);
count(3);
2019-04-01 21:57:50 +02:00
# Try to display previous conf
$res = &client->jsonResponse('/view/1');
ok( $res->{cfgNum} eq '1', 'Browser is allowed' )
2019-05-11 20:18:43 +02:00
or print STDERR Dumper($res);
count(1);
2019-04-01 21:57:50 +02:00
# Remove new conf
2020-01-27 18:32:59 +01:00
unlink 't/conf/lmConf-2.json';
2019-03-26 22:52:41 +01:00
done_testing( count() );