Commit 1a3e8032 authored by Christophe Maudoux's avatar Christophe Maudoux

Fix & improve units test (#1603)

parent 0abea4f1
Pipeline #3820 failed with stages
in 9 minutes
......@@ -193,6 +193,7 @@ t/05-rest-api.t
t/06-rest-api.t
t/07-utf8.t
t/10-save-unchanged-conf.t
t/11-save-changed-conf-with-confirmation.t
t/12-save-changed-conf.t
t/14-bad-changes-in-conf.t
t/15-combination.t
......@@ -207,6 +208,7 @@ t/conf/lmConf-1.json
t/jsonfiles/01-base-tree.json
t/jsonfiles/02-base-tree-all-nodes-opened.json
t/jsonfiles/12-modified.json
t/jsonfiles/13-modified-with-confirmation.json
t/jsonfiles/14-bad.json
t/jsonfiles/15-combination.json
t/lemonldap-ng.ini
......
# Verify that a modified configuration can be saved and that all changes are
# detected
use Test::More;
use strict;
use JSON;
require 't/test-lib.pm';
my $struct = 't/jsonfiles/13-modified-with-confirmation.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]; };
mkdir 't/sessions';
my ( $res, $resBody );
ok( $res = &client->_post( '/confs/', 'cfgNum=1', &body, 'application/json' ),
"Request succeed"
);
ok( $res->[0] == 200, "Result code is 200" );
ok( $resBody = from_json( $res->[2]->[0] ),
"Result body contains JSON text" );
ok( $resBody->{result} == 0, "JSON response contains \"result:0\"" )
or print STDERR Dumper($resBody);
ok( $resBody->{needConfirm} == 1, "JSON response contains \"needConfirm:1\"" )
or print STDERR Dumper($resBody);
ok( @{ $resBody->{details}->{__warnings__} } == 3,
'JSON response contains 3 warnings'
) or print STDERR Dumper($resBody);
foreach my $i (0 .. 2) {
ok( $resBody->{details}->{__warnings__}->[$i]->{message}
=~ /\b(unprotected|cross-domain-authentication|retries)\b/,
"Warning with 'unprotect', 'CDA' or 'retries' found"
) or print STDERR Dumper($resBody);
}
ok( @{ $resBody->{details}->{__needConfirmation__} } == 1,
'JSON response contains 1 needConfirmation'
) or print STDERR Dumper($resBody);
ok( $resBody->{details}->{__needConfirmation__}->[0]->{message}
=~ /\bplugin is enabled without CSRF Token or Captcha required\b/,
"Warning with confirmation needed found"
) or print STDERR Dumper($resBody);
ok( @{ $resBody->{details}->{__changes__} } == 24,
'JSON response contains 24 changes'
) or print STDERR Dumper($resBody);
ok( $res = &client->_post( '/confs/', 'cfgNum=1&force=1', &body, 'application/json' ),
"Request succeed"
);
ok( -f $confFiles->[1], 'File is created' );
count(3);
my @changes = @{&changes};
my @cmsg = @{ $resBody->{details}->{__changes__} };
my $bug;
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;
if ( $c->{key} eq 'applicationList' ) {
pass qq("$c->{key}" found);
}
else {
ok( ( $cmp1 - @changes ) == ( $cmp2 - @cmsg ), qq("$c->{key}" found) )
or print STDERR 'Expect: '
. ( $cmp1 - @changes )
. ', got: '
. ( $cmp2 - @cmsg )
. "\nExpect: "
. Dumper( \@d1 ) . "Got: "
. Dumper( \@d2 );
}
count(1);
}
ok( !@changes, 'All changes detected' ) or $bug = 1;
if ($bug) {
print STDERR 'Expected not found: '
. Dumper( \@changes )
. 'Changes announced and not found: '
. Dumper( \@cmsg );
}
#print STDERR Dumper(\@changes,\@cmsg);
count(6);
# TODO: check result of this
ok( $res = &client->jsonResponse('/diff/1/2'), 'Diff called' );
my ( @c1, @c2 );
ok( ( @c1 = sort keys %{ $res->[0] } ), 'diff() detects changes in conf 1' );
ok( ( @c2 = sort keys %{ $res->[1] } ), 'diff() detects changes in conf 2' );
ok( @c1 == 12, '11 keys changed in conf 1' )
or print STDERR "Expect: 12 keys, get: " . join( ', ', @c1 ) . "\n";
ok( @c2 == 16, '14 keys changed or created in conf 2' )
or print STDERR "Expect: 16 keys, get: " . join( ',', @c2 ) . "\n";
count(5);
unlink $confFiles->[1];
#eval { rmdir 't/sessions'; };
done_testing( count() );
# Remove sessions directory
`rm -rf t/sessions`;
sub changes {
return [
{ 'key' => 'portal',
'new' => 'http://auth2.example.com/',
'old' => 'http://auth.example.com/'
},
{ 'new' => 0,
'old' => 1,
'key' => 'portalDisplayLogout'
},
{ 'key' =>
'applicationList, Sample applications, Application Test 1, uri',
'old' => 'http://test1.example.com/',
'new' => 'http://testex.example.com/'
},
{ 'new' => 'Application Test 3',
'key' => 'applicationList, Sample applications'
},
{ 'new' => 'Changes in cat(s)/app(s)',
'key' => 'applicationList',
},
{ 'key' => 'applicationList',
'old' => 'Documentation',
'new' => 'Administration',
},
{ 'key' => 'applicationList',
'old' => 'Administration',
'new' => 'Sample applications',
},
{ 'key' => 'applicationList',
'old' => 'Sample applications',
'new' => 'Documentation',
},
{ 'key' => 'userDB',
'new' => 'LDAP',
'old' => 'Demo'
},
{ 'key' => 'passwordDB',
'new' => 'LDAP',
'old' => 'Demo'
},
{ 'key' => 'openIdSPList',
'new' => '1;bad.com'
},
{ 'new' => 'Uid',
'key' => 'exportedVars'
},
{ 'key' =>
'locationRules, test1.example.com, (?#Logout comment)^/logout',
'new' => 'logout_sso',
'old' => undef
},
{ 'old' => '^/logout',
'key' => 'locationRules, test1.example.com'
},
{ 'key' => 'locationRules, test3.example.com, ^/logout',
'new' => 'logout_sso',
'old' => undef
},
{ 'key' => 'locationRules, test3.example.com, default',
'old' => undef,
'new' => 'accept'
},
{ 'key' => 'locationRules',
'new' => 'test3.example.com'
},
{ 'key' => 'exportedHeaders, test3.example.com, Auth-User',
'old' => undef,
'new' => '$uid'
},
{ 'new' => 'test3.example.com',
'key' => 'exportedHeaders'
},
{ 'key' => 'locationRules, test.ex.com, default',
'old' => undef,
'new' => 'deny'
},
{ 'key' => 'locationRules',
'new' => 'test.ex.com'
},
{ 'key' => 'virtualHosts',
'new' => 'test3.example.com',
'old' => 'test2.example.com'
},
{ 'key' => 'virtualHosts',
'old' => 'test2.example.com'
},
{
'new' => 1,
'key' => 'portalDisplayResetPassword',
'old' => 0
},
{
'new' => 0,
'key' => 'captcha_mail_enabled',
'old' => '1'
}
];
}
......@@ -26,18 +26,29 @@ ok( $resBody = from_json( $res->[2]->[0] ),
"Result body contains JSON text" );
ok( $resBody->{result} == 1, "JSON response contains \"result:1\"" )
or print STDERR Dumper($resBody);
ok( $resBody->{details}->{__warnings__}
and @{ $resBody->{details}->{__warnings__} } == 2,
ok( @{ $resBody->{details}->{__warnings__} } == 2,
'JSON response contains 2 warnings'
) or print STDERR Dumper($resBody);
ok( $resBody->{details}->{__warnings__}->[0]->{message}
=~ /\b(unprotected|cross-domain-authentication)\b/,
"Warning with 'unprotect' or 'CDA' found"
) or print STDERR Dumper($resBody);
ok( $resBody->{details}->{__warnings__}->[1]->{message}
=~ /\b(unprotected|cross-domain-authentication)\b/,
"Warning with 'unprotect' or 'CDA' found"
) or print STDERR Dumper($resBody);
foreach my $i (0 .. 1) {
ok( $resBody->{details}->{__warnings__}->[$i]->{message}
=~ /\b(unprotected|cross-domain-authentication)\b/,
"Warning with 'unprotect', 'CDA' or 'retries' found"
) or print STDERR Dumper($resBody);
}
# ok( $resBody->{details}->{__warnings__}->[0]->{message}
# =~ /\b(unprotected|cross-domain-authentication)\b/,
# "Warning with 'unprotect' or 'CDA' found"
# ) or print STDERR Dumper($resBody);
# ok( $resBody->{details}->{__warnings__}->[1]->{message}
# =~ /\b(unprotected|cross-domain-authentication)\b/,
# "Warning with 'unprotect' or 'CDA' found"
# ) or print STDERR Dumper($resBody);
ok( -f $confFiles->[1], 'File is created' );
count(3);
my @changes = @{&changes};
......
......@@ -12,6 +12,7 @@ sub body {
}
unlink 't/conf/lmConf-2.json';
mkdir 't/sessions';
my ( $res, $resBody );
ok( $res = &client->_post( '/confs/', 'cfgNum=1', &body, 'application/json' ),
......@@ -37,8 +38,6 @@ count(9);
done_testing( count() );
unlink 't/conf/lmConf-2.json';
`rm t/sessions/*`;
\ No newline at end of file
`rm -rf t/sessions`;
\ No newline at end of file
[{
"id": "generalParameters",
"title": "generalParameters",
"nodes": [{
"id": "portalParams",
"title": "portalParams",
"nodes": [{
"default": "http://auth.example.com/",
"id": "portal",
"title": "portal",
"data": "http://auth2.example.com/"
}, {
"id": "portalMenu",
"title": "portalMenu",
"nodes": [{
"id": "portalModules",
"title": "portalModules",
"type": "simpleInputContainer",
"nodes": [{
"default": 1,
"id": "portalDisplayLogout",
"title": "portalDisplayLogout",
"type": "boolOrExpr",
"data": 0
}, {
"default": "$_auth =~ /^(LDAP|DBI|Demo)$/",
"id": "portalDisplayChangePassword",
"title": "portalDisplayChangePassword",
"type": "boolOrExpr",
"data": "$_auth =~ /^(LDAP|DBI|Demo)$/"
}, {
"default": 1,
"id": "portalDisplayAppslist",
"title": "portalDisplayAppslist",
"type": "boolOrExpr",
"data": 1
}, {
"default": 1,
"id": "portalDisplayLoginHistory",
"title": "portalDisplayLoginHistory",
"type": "boolOrExpr",
"data": 1
}]
}, {
"default": [{
"data": {
"catname": "Default category",
"type": "category"
},
"id": "applicationList/default",
"title": "default",
"type": "catAndAppList"
}],
"id": "applicationList",
"title": "applicationList",
"type": "catAndAppList",
"nodes": [{
"title": "Sample applications",
"nodes": [{
"title": "Application Test 1",
"id": "applicationList/0001-cat/0002-app",
"type": "menuApp",
"data": {
"uri": "http://testex.example.com/",
"logo": "demo.png",
"description": "A simple application displaying authenticated user",
"display": "auto"
}
}, {
"data": {
"display": "auto",
"logo": "thumbnail.png",
"description": "The same simple application displaying authenticated user",
"uri": "http://test2.example.com/"
},
"title": "Application Test 2",
"id": "applicationList/0001-cat/0003-app",
"type": "menuApp"
}, {
"data": {
"display": "auto",
"logo": "thumbnail.png",
"description": "The same simple application displaying authenticated user",
"uri": "http://test3.example.com/"
},
"title": "Application Test 3",
"id": "applicationList/0001-cat/n3",
"type": "menuApp"
}],
"id": "applicationList/0001-cat",
"type": "menuCat"
}, {
"type": "menuCat",
"id": "applicationList/0004-cat",
"nodes": [{
"title": "WebSSO Manager",
"id": "applicationList/0004-cat/0005-app",
"type": "menuApp",
"data": {
"display": "auto",
"uri": "http://manager.example.com/",
"logo": "configure.png",
"description": "Configure LemonLDAP::NG WebSSO"
}
}, {
"title": "Notifications explorer",
"type": "menuApp",
"id": "applicationList/0004-cat/0006-app",
"data": {
"display": "auto",
"uri": "http://manager.example.com/notifications",
"description": "Explore WebSSO notifications",
"logo": "database.png"
}
}, {
"data": {
"display": "auto",
"description": "Explore WebSSO sessions",
"logo": "database.png",
"uri": "http://manager.example.com/sessions"
},
"title": "Sessions explorer",
"type": "menuApp",
"id": "applicationList/0004-cat/0007-app"
}],
"title": "Administration"
}, {
"nodes": [{
"data": {
"uri": "http://manager.example.com/doc/",
"logo": "help.png",
"description": "Documentation supplied with LemonLDAP::NG",
"display": "on"
},
"title": "Local documentation",
"id": "applicationList/0008-cat/0009-app",
"type": "menuApp"
}, {
"title": "Offical Website",
"type": "menuApp",
"id": "applicationList/0008-cat/0010-app",
"data": {
"display": "on",
"description": "Official LemonLDAP::NG Website",
"logo": "network.png",
"uri": "http://lemonldap-ng.org/"
}
}],
"title": "Documentation",
"id": "applicationList/0008-cat",
"type": "menuCat"
}]
}]
}, {
"id": "portalCustomization",
"title": "portalCustomization",
"nodes": [{
"default": "bootstrap",
"id": "portalSkin",
"select": [{
"k": "bootstrap",
"v": "Bootstrap"
}, {
"k": "pastel",
"v": "Pastel"
}, {
"k": "impact",
"v": "Impact"
}, {
"k": "dark",
"v": "Dark"
}],
"title": "portalSkin",
"type": "portalskin",
"data": "bootstrap"
}, {
"id": "portalSkinRules",
"title": "portalSkinRules",
"type": "keyTextContainer",
"nodes": []
}, {
"id": "portalButtons",
"title": "portalButtons",
"type": "simpleInputContainer",
"nodes": [{
"default": 1,
"id": "portalCheckLogins",
"title": "portalCheckLogins",
"type": "bool",
"data": 1
}, {
"default": 0,
"id": "portalDisplayResetPassword",
"title": "portalDisplayResetPassword",
"type": "boolOrExpr",
"data": 1
}, {
"default": 1,
"id": "portalDisplayRegister",
"title": "portalDisplayRegister",
"type": "boolOrExpr",
"data": 1
}]
}, {
"id": "passwordManagement",
"title": "passwordManagement",
"type": "simpleInputContainer",
"nodes": [{
"default": 1,
"id": "portalRequireOldPassword",
"title": "portalRequireOldPassword",
"type": "bool",
"data": 1
}, {
"default": 0,
"id": "hideOldPassword",
"title": "hideOldPassword",
"type": "bool",
"data": 0
}, {
"default": 0,
"id": "mailOnPasswordChange",
"title": "mailOnPasswordChange",
"type": "bool",
"data": 0
}]
}, {
"id": "portalOther",
"title": "portalOther",
"type": "simpleInputContainer",
"nodes": [{
"default": "_user",
"id": "portalUserAttr",
"title": "portalUserAttr",
"data": "_user"
}, {
"default": 0,
"id": "portalOpenLinkInNewWindow",
"title": "portalOpenLinkInNewWindow",
"type": "bool",
"data": 0
}, {
"default": 1,
"id": "portalAntiFrame",
"title": "portalAntiFrame",
"type": "bool",
"data": 1
}, {
"default": 60000,
"id": "portalPingInterval",
"title": "portalPingInterval",
"type": "int",
"data": 60000
}]
}]
}, {
"id": "portalCaptcha",
"title": "portalCaptcha",
"nodes": [{
"default": 0,
"id": "captcha_login_enabled",
"title": "captcha_login_enabled",
"type": "bool",
"data": 0
}, {
"default": 1,
"id": "captcha_mail_enabled",
"title": "captcha_mail_enabled",
"type": "bool",
"data": 0
}, {
"default": 1,
"id": "captcha_register_enabled",
"title": "captcha_register_enabled",
"type": "bool",
"data": 1
}, {
"default": 6,
"id": "captcha_size",
"title": "captcha_size",
"type": "int",
"data": 6
}]
}]
}, {
"_nodes_filter": "authParams",
"id": "authParams",
"title": "authParams",
"type": "authParams",
"nodes": [{
"default": "LDAP",
"id": "authentication",
"select": [{
"k": "Apache",
"v": "Apache"
}, {
"k": "AD",
"v": "Active Directory"
}, {
"k": "BrowserID",
"v": "BrowserID (Mozilla Persona)"
}, {
"k": "Choice",
"v": "authChoice"
}, {
"k": "CAS",
"v": "Central Authentication Service (CAS)"
}, {
"k": "DBI",
"v": "Database (DBI)"
}, {
"k": "Demo",
"v": "Demonstration"
}, {
"k": "Facebook",
"v": "Facebook"
}, {
"k": "Google",
"v": "Google"
}, {
"k": "LDAP",
"v": "LDAP"
}, {
"k": "Multi",
"v": "Multiple"
}, {
"k": "Null",
"v": "None"
}, {
"k": "OpenID",
"v": "OpenID"
}, {
"k": "Proxy",
"v": "Proxy"
}, {
"k": "Radius",
"v": "Radius"
}, {
"k": "Remote",
"v": "Remote"
}, {
"k": "SAML",
"v": "SAML v2"
}, {
"k": "Slave",
"v": "Slave"
}, {
"k": "SSL",
"v": "SSL"
}, {
"k": "Twitter",
"v": "Twitter"
}, {
"k": "WebID",
"v": "WebID"
}, {
"k": "Yubikey",
"v": "Yubikey"
}],
"title": "authentication",
"type": "select",
"data": "Demo"
}, {
"default": "Same",
"id": "userDB",
"select": [{
"k": "Same",
"v": "Same as auth"
}, {
"k": "AD",
"v": "Active Directory"
}, {
"k": "DBI",
"v": "Database (DBI)"
}, {
"k": "LDAP",
"v": "LDAP"
}, {
"k": "Null",
"v": "None"
}],
"title": "userDB",
"type": "select",
"data": "LDAP"
}, {