Debian Codegraph @

lemonldap-ng-manager/t/71-viewer-without-diff.t

raw
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 # Load lemonldap-ng-noDiff.ini
16 my $client2;
17 ok(
18 $client2 = LLNG::Manager::Test->new(
19 ini => {
20 viewerAllowDiff => 0,
21 viewerHiddenKeys =>
22 "samlIDPMetaDataNodes samlSPMetaDataNodes portalDisplayLogout",
23 viewerAllowBrowser => '$env->{REMOTE_ADDR} ne "127.0.0.1"',
24 }
25 ),
26 'Client object'
27 );
28
29 # Try to compare confs 1 & 2
30 ok(
31 my $res = $client2->_post(
32 '/confs/', 'cfgNum=1&force=1', $body, 'application/json', $len
33 ),
34 "Request succeed"
35 );
36 ok( $res->[0] == 200, "Result code is 200" );
37 my $resBody;
38 ok( $resBody = from_json( $res->[2]->[0] ), "Result body contains JSON text" );
39 count(3);
40 foreach my $i ( 0 .. 1 ) {
41 ok(
42 $resBody->{details}->{__changes__}->[$i]->{key} =~
43 /\b(captcha_login_enabled|captcha_mail_enabled)\b/,
44 "Details with captcha 'login' or 'mail' found"
45 ) or print STDERR Dumper($resBody);
46 }
47 count(2);
48
49 # Test that Conf key value is sent
50 $res = $client2->jsonResponse('/view/2/portalDisplayOidcConsents');
51 ok( $res->{value} eq '$_oidcConsents && $_oidcConsents =~ /\\w+/', 'Key found' )
52 or print STDERR Dumper($res);
53 count(1);
54
55 # Test that hidden key values are NOT sent
56 $res = &client->jsonResponse('/view/2/portalDisplayLogout');
57 ok( $res->{value} eq '_Hidden_', 'Key is hidden' )
58 or explain( $res, 'value => "_Hidden_"' );
59 count(1);
60
61 # Browse confs is forbidden
62 $res = $client2->jsonResponse('/view/2');
63 ok( $res->{value} eq '_Hidden_', 'Key is hidden' )
64 or print STDERR Dumper($res);
65 count(1);
66
67 # Try to display latest conf
68 $res = &client->jsonResponse('/view/latest');
69 ok( $res->{cfgNum} eq '2', 'Latest conf loaded' );
70 count(1);
71
72 # Try to compare confs
73 $res = $client2->jsonResponse('/view/diff/1/2');
74 ok( $res->{value} eq '_Hidden_', 'Diff is NOT allowed' )
75 or print STDERR Dumper($res);
76 count(1);
77
78 # Try to display latest conf
79 $res = $client2->jsonResponse('/view/1');
80 ok( $res->{value} eq '_Hidden_', 'Browser is NOT allowed' )
81 or print STDERR Dumper($res);
82 count(2);
83
84 done_testing( count() );
85