| 1 |
# Test viewer API |
| 2 |
|
| 3 |
use warnings; |
| 4 |
use Test::More; |
| 5 |
use strict; |
| 6 |
use IO::String; |
| 7 |
use JSON qw(from_json); |
| 8 |
|
| 9 |
require 't/test-lib.pm'; |
| 10 |
|
| 11 |
my $struct = 't/jsonfiles/70-diff.json'; |
| 12 |
|
| 13 |
my ( $len, $body ) = substitute_io_handle($struct); |
| 14 |
|
| 15 |
# Test that key value is sent |
| 16 |
my $res = &client->jsonResponse('/view/1/portalDisplayOidcConsents'); |
| 17 |
ok( $res->{value} eq '$_oidcConsents && $_oidcConsents =~ /\\w+/', |
| 18 |
'Key found' ); |
| 19 |
count(1); |
| 20 |
|
| 21 |
# Test that hidden key values are NOT sent |
| 22 |
$res = &client->jsonResponse('/view/1/portalDisplayLogout'); |
| 23 |
ok( $res->{value} eq '_Hidden_', 'Key is hidden' ) |
| 24 |
or explain( $res, 'value => "_Hidden_"' ); |
| 25 |
$res = &client->jsonResponse('/view/1/samlIDPMetaDataNodes'); |
| 26 |
ok( ref($res) eq 'HASH' && $res->{value} eq '_Hidden_', 'Key is hidden' ) |
| 27 |
or explain( $res, 'value => "_Hidden_"' ); |
| 28 |
count(2); |
| 29 |
|
| 30 |
# Try to display latest conf |
| 31 |
$res = &client->jsonResponse('/view/latest'); |
| 32 |
ok( $res->{cfgNum} eq '1', 'Latest conf loaded' ) |
| 33 |
or explain( $res, "cfgNum => 1" ); |
| 34 |
count(1); |
| 35 |
|
| 36 |
ok( |
| 37 |
$res = &client->_post( |
| 38 |
'/confs/', 'cfgNum=1&force=1', $body, 'application/json', $len |
| 39 |
), |
| 40 |
"Request succeed" |
| 41 |
); |
| 42 |
ok( $res->[0] == 200, "Result code is 200" ); |
| 43 |
my $resBody; |
| 44 |
ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" ); |
| 45 |
count(3); |
| 46 |
|
| 47 |
foreach my $i ( 0 .. 1 ) { |
| 48 |
ok( |
| 49 |
$resBody->{details}->{__changes__}->[$i]->{key} =~ |
| 50 |
/\b(captcha_login_enabled|captcha_mail_enabled)\b/, |
| 51 |
"Details with captcha 'login' or 'mail' found" |
| 52 |
) or print STDERR Dumper($resBody); |
| 53 |
} |
| 54 |
count(2); |
| 55 |
|
| 56 |
# Try to compare confs 1 & 2 |
| 57 |
$res = &client->jsonResponse('/view/diff/1/2'); |
| 58 |
|
| 59 |
ok( $res->[1]->{captcha_login_enabled} eq '1', 'Key found' ); |
| 60 |
ok( $res->[1]->{captcha_mail_enabled} eq '0', 'Key found' ); |
| 61 |
ok( 7 == keys %{ $res->[1] }, 'Right number of keys found' ) |
| 62 |
or print STDERR Dumper($res); |
| 63 |
count(3); |
| 64 |
|
| 65 |
# Try to display previous conf |
| 66 |
$res = &client->jsonResponse('/view/1'); |
| 67 |
ok( $res->{cfgNum} eq '1', 'Browser is allowed' ) |
| 68 |
or print STDERR Dumper($res); |
| 69 |
count(1); |
| 70 |
|
| 71 |
done_testing( count() ); |
| 72 |
|