Unit tests for importMetadata

This commit is contained in:
Maxime Besson 2022-03-22 18:13:27 +01:00
parent 27580ea4de
commit d2dce85e8c
3 changed files with 6186 additions and 0 deletions

View File

@ -0,0 +1,239 @@
#!/usr/bin/perl
use Test::More;
use strict;
use warnings;
use Storable qw/dclone/;
require_ok('./scripts/importMetadata');
my $xml;
{
local $/ = undef; # Slurp mode
open XML, "t/data/preview-all-test-metadata.xml" or die;
$xml = <XML>;
close XML;
}
subtest 'Ignore SP' => sub {
my $lmConf = {};
my $importConf = {
main => {
'ignore-sp' => [
"https://ucopia.univ-brest.fr/",
"http://icampus-test.univ-paris3.fr"
]
}
};
# Run import
my ( $spCounters, $idpCounters ) =
transform_config( $importConf, $lmConf, $xml );
is( $spCounters->{created}, 45 );
is( $spCounters->{ignored}, 2 );
is( $idpCounters->{created}, 12 );
is( $idpCounters->{ignored}, 0 );
};
subtest 'Ignore IDP' => sub {
my $lmConf = {};
my $importConf = {
main => {
'ignore-idp' => [
"https://serveur.uvs.sn/idp/shibboleth",
"https://idp-test.insa-rennes.fr/idp/shibboleth"
]
}
};
# Run import
my ( $spCounters, $idpCounters ) =
transform_config( $importConf, $lmConf, $xml );
is( $spCounters->{created}, 47 );
is( $spCounters->{ignored}, 0 );
is( $idpCounters->{created}, 10 );
is( $idpCounters->{ignored}, 2 );
};
subtest 'Conf Prefix' => sub {
my $lmConf = {};
my $importConf = {
main => {
'idpconfprefix' => 'renater-idp',
'spconfprefix' => 'renater-sp',
}
};
# Run import
transform_config( $importConf, $lmConf, $xml );
is( scalar grep( /^renater-sp/, keys( %{ $lmConf->{samlSPMetaDataXML} } ) ),
47 );
is(
scalar
grep( /^renater-idp/, keys( %{ $lmConf->{samlIDPMetaDataXML} } ) ),
12
);
};
# Make sure matching providers who are not in the metadata are removed
# but non-matching providers are left alone
subtest 'Remove' => sub {
my $lmConf = {
samlSPMetaDataXML => {
'sp-toremove' => { samlSPMetaDataXML => "removeme" },
'tokeep' => { samlSPMetaDataXML => "keepme" },
},
samlSPMetaDataExportedAttributes => {
'sp-toremove' => {},
'tokeep' => {},
},
samlSPMetaDataOptions => {
'sp-toremove' => {},
'tokeep' => {},
},
samlIDPMetaDataXML => {
'idp-toremove' => { samlSPMetaDataXML => "removeme" },
'tokeep' => { samlSPMetaDataXML => "keepme" },
},
samlIDPMetaDataExportedAttributes => {
'idp-toremove' => {},
'tokeep' => {},
},
samlIDPMetaDataOptions => {
'idp-toremove' => {},
'tokeep' => {},
},
};
my $importConf = {
main => {
'remove' => 1,
}
};
# Run import
transform_config( $importConf, $lmConf, $xml );
ok( !$lmConf->{samlSPMetaDataOptions}->{'sp-toremove'} );
ok( $lmConf->{samlSPMetaDataOptions}->{'tokeep'} );
ok( !$lmConf->{samlSPMetaDataExportedAttributes}->{'sp-toremove'} );
ok( $lmConf->{samlSPMetaDataExportedAttributes}->{'tokeep'} );
ok( !$lmConf->{samlSPMetaDataXML}->{'sp-toremove'} );
ok( $lmConf->{samlSPMetaDataXML}->{'tokeep'} );
ok( !$lmConf->{samlIDPMetaDataOptions}->{'idp-toremove'} );
ok( $lmConf->{samlIDPMetaDataOptions}->{'tokeep'} );
ok( !$lmConf->{samlIDPMetaDataExportedAttributes}->{'idp-toremove'} );
ok( $lmConf->{samlIDPMetaDataExportedAttributes}->{'tokeep'} );
ok( !$lmConf->{samlIDPMetaDataXML}->{'idp-toremove'} );
ok( $lmConf->{samlIDPMetaDataXML}->{'tokeep'} );
};
subtest 'IDP Exported attributes' => sub {
my $lmConf = {};
my $importConf = {
exportedAttributes => {
cn => '0;cn',
eduPersonPrincipalName => '1;eduPersonPrincipalName',
},
'https://univ-machineDebian.fr/idp/shibboleth' => {
exported_attribute_uid => '0;uid',
}
};
# Run import
transform_config( $importConf, $lmConf, $xml );
is_deeply(
$lmConf->{samlIDPMetaDataExportedAttributes}
->{'idp-idp-test-insa-rennes-fr-idp-shibboleth'},
{
cn => '0;cn',
eduPersonPrincipalName => '1;eduPersonPrincipalName',
}
);
is_deeply(
$lmConf->{samlIDPMetaDataExportedAttributes}
->{'idp-univ-machineDebian-fr-idp-shibboleth'},
{
cn => '0;cn',
eduPersonPrincipalName => '1;eduPersonPrincipalName',
uid => '0;uid',
}
);
};
subtest 'SP Exported attributes' => sub {
my $lmConf = {};
my $importConf = {
ALL => {
attribute_required => 0,
},
'https://ucopia.univ-brest.fr/' => {
attribute_required => 1,
attribute_required_uid => 0,
}
};
# Run import
transform_config( $importConf, $lmConf, $xml );
like(
$lmConf->{samlSPMetaDataExportedAttributes}
->{'sp-umr5557-kaa-univ-lyon1-fr-sp'}->{mail},
qr/^0/,
);
like(
$lmConf->{samlSPMetaDataExportedAttributes}
->{'sp-ucopia-univ-brest-fr'}->{mail},
qr/^1/,
);
like(
$lmConf->{samlSPMetaDataExportedAttributes}
->{'sp-ucopia-univ-brest-fr'}->{uid},
qr/^0/
);
};
subtest 'Options' => sub {
my $lmConf = {};
my $importConf = {
ALL => {
samlSPMetaDataOptionsCheckSSOMessageSignature => 0,
samlIDPMetaDataOptionsStoreSAMLToken => 1,
},
'https://ucopia.univ-brest.fr/' => {
samlSPMetaDataOptionsCheckSSOMessageSignature => 1
},
'https://univ-machineDebian.fr/idp/shibboleth' => {
samlIDPMetaDataOptionsForceAuthn => 1,
},
};
# Run import
transform_config( $importConf, $lmConf, $xml );
is(
$lmConf->{samlSPMetaDataOptions}->{'sp-ucopia-univ-brest-fr'}
->{samlSPMetaDataOptionsCheckSSOMessageSignature},
1
);
is(
$lmConf->{samlSPMetaDataOptions}->{'sp-wiki-uness-fr'}
->{samlSPMetaDataOptionsCheckSSOMessageSignature},
0
);
is(
$lmConf->{samlIDPMetaDataOptions}
->{'idp-shibboleth-2022-grenoble-archi-fr-idp'}
->{samlIDPMetaDataOptionsStoreSAMLToken},
1
);
is(
$lmConf->{samlIDPMetaDataOptions}
->{'idp-shibboleth-2022-grenoble-archi-fr-idp'}
->{samlIDPMetaDataOptionsForceAuthn},
0
);
is(
$lmConf->{samlIDPMetaDataOptions}
->{'idp-univ-machineDebian-fr-idp-shibboleth'}
->{samlIDPMetaDataOptionsForceAuthn},
1
);
};
done_testing();

View File

@ -0,0 +1,163 @@
#!/usr/bin/perl
use Test::More;
use strict;
use warnings;
use Storable qw/dclone/;
require_ok('./scripts/importMetadata');
my $xml;
{
local $/ = undef; # Slurp mode
open XML, "t/data/preview-all-test-metadata.xml" or die;
$xml = <XML>;
close XML;
}
my $lmConf = {};
my $importConf = {};
# Run import
my ( $spCounters, $idpCounters ) =
transform_config( $importConf, $lmConf, $xml );
# Check statistics
is_deeply(
$spCounters,
{
'created' => 47,
'found' => 48,
'ignored' => 0,
'rejected' => 1,
'removed' => 0,
'updated' => 0
},
"SP counters are expected"
);
is_deeply(
$idpCounters,
{
'created' => 12,
'found' => 13,
'ignored' => 0,
'rejected' => 1,
'removed' => 0,
'updated' => 0
},
"IDP counters are expected"
);
is( keys %{ $lmConf->{samlIDPMetaDataXML} }, 12,
"Correct amount of providers" );
is( keys %{ $lmConf->{samlIDPMetaDataExportedAttributes} },
12, "Correct amount of providers" );
is( keys %{ $lmConf->{samlIDPMetaDataOptions} },
12, "Correct amount of providers" );
is( keys %{ $lmConf->{samlSPMetaDataXML} }, 47, "Correct amount of providers" );
is( keys %{ $lmConf->{samlSPMetaDataExportedAttributes} },
47, "Correct amount of providers" );
is( keys %{ $lmConf->{samlSPMetaDataOptions} },
47, "Correct amount of providers" );
my $idp = "idp-idp-test-insa-rennes-fr-idp-shibboleth";
my $sp = "sp-ucopia-univ-brest-fr";
is(
$lmConf->{samlIDPMetaDataExportedAttributes}->{$idp}
->{eduPersonPrincipalName},
'0;eduPersonPrincipalName', "Found exported attribute"
);
is(
$lmConf->{samlSPMetaDataExportedAttributes}->{$sp}->{supannEtablissement},
join( ';',
0,
'urn:oid:1.3.6.1.4.1.7135.1.2.1.14',
'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
'supannEtablissement' ),
"Found optional attribute"
);
is(
$lmConf->{samlSPMetaDataExportedAttributes}->{$sp}->{uid},
join( ';',
1,
'urn:oid:0.9.2342.19200300.100.1.1',
'urn:oasis:names:tc:SAML:2.0:attrname-format:uri', 'uid' ),
"Found required attribute"
);
# Check update
$lmConf->{samlSPMetaDataOptions}->{$sp}
->{samlSPMetaDataOptionsCheckSSOMessageSignature} = 0;
$lmConf->{samlIDPMetaDataOptions}->{$idp}
->{samlIDPMetaDataOptionsAllowProxiedAuthn} = 1;
( $spCounters, $idpCounters ) = transform_config( $importConf, $lmConf, $xml );
# Check statistics
is_deeply(
$spCounters,
{
'created' => 0,
'found' => 48,
'ignored' => 0,
'rejected' => 1,
'removed' => 0,
'updated' => 1
},
"SP counters are expected"
);
is_deeply(
$idpCounters,
{
'created' => 0,
'found' => 13,
'ignored' => 0,
'rejected' => 1,
'removed' => 0,
'updated' => 1
},
"IDP counters are expected"
);
is(
$lmConf->{samlSPMetaDataOptions}->{$sp}
->{samlSPMetaDataOptionsCheckSSOMessageSignature},
1, "Configuration was updated"
);
is(
$lmConf->{samlIDPMetaDataOptions}->{$idp}
->{samlIDPMetaDataOptionsAllowProxiedAuthn},
0, "Configuration was updated"
);
# Check idempotence
my $oldLmConf = dclone $lmConf;
( $spCounters, $idpCounters ) = transform_config( $importConf, $lmConf, $xml );
is_deeply(
$spCounters,
{
'created' => 0,
'found' => 48,
'ignored' => 0,
'rejected' => 1,
'removed' => 0,
'updated' => 0
},
"SP counters are expected"
);
is_deeply(
$idpCounters,
{
'created' => 0,
'found' => 13,
'ignored' => 0,
'rejected' => 1,
'removed' => 0,
'updated' => 0
},
"IDP counters are expected"
);
is_deeply( $lmConf, $oldLmConf );
done_testing();

File diff suppressed because it is too large Load Diff