| 1 |
use warnings; |
| 2 |
use Test::More; |
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
use Storable qw/dclone/; |
| 6 |
require_ok('./scripts/importMetadata'); |
| 7 |
|
| 8 |
my $xml; |
| 9 |
{ |
| 10 |
local $/ = undef; # Slurp mode |
| 11 |
open XML, "t/data/preview-all-test-metadata.xml" or die; |
| 12 |
$xml = <XML>; |
| 13 |
close XML; |
| 14 |
} |
| 15 |
|
| 16 |
# Update this if you change the content of the file |
| 17 |
my $idp_in_file = 12; |
| 18 |
my $sp_in_file = 48; |
| 19 |
|
| 20 |
subtest 'Ignore SP' => sub { |
| 21 |
my $lmConf = {}; |
| 22 |
my $importConf = { |
| 23 |
main => { |
| 24 |
'ignore-sp' => [ |
| 25 |
"https://ucopia.univ-brest.fr/", |
| 26 |
"http://icampus-test.univ-paris3.fr" |
| 27 |
] |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
# Run import |
| 32 |
my ( $spCounters, $idpCounters ) = |
| 33 |
transform_config( $importConf, $lmConf, $xml ); |
| 34 |
is( $spCounters->{created}, $sp_in_file - 2 ); |
| 35 |
is( $spCounters->{ignored}, 2 ); |
| 36 |
is( $idpCounters->{created}, $idp_in_file ); |
| 37 |
is( $idpCounters->{ignored}, 0 ); |
| 38 |
}; |
| 39 |
|
| 40 |
subtest 'Ignore IDP' => sub { |
| 41 |
my $lmConf = {}; |
| 42 |
my $importConf = { |
| 43 |
main => { |
| 44 |
'ignore-idp' => [ |
| 45 |
"https://serveur.uvs.sn/idp/shibboleth", |
| 46 |
"https://idp-test.insa-rennes.fr/idp/shibboleth" |
| 47 |
] |
| 48 |
} |
| 49 |
}; |
| 50 |
|
| 51 |
# Run import |
| 52 |
my ( $spCounters, $idpCounters ) = |
| 53 |
transform_config( $importConf, $lmConf, $xml ); |
| 54 |
is( $spCounters->{created}, $sp_in_file ); |
| 55 |
is( $spCounters->{ignored}, 0 ); |
| 56 |
is( $idpCounters->{created}, $idp_in_file - 2 ); |
| 57 |
is( $idpCounters->{ignored}, 2 ); |
| 58 |
}; |
| 59 |
|
| 60 |
subtest 'Conf Prefix' => sub { |
| 61 |
my $lmConf = {}; |
| 62 |
my $importConf = { |
| 63 |
main => { |
| 64 |
'idpconfprefix' => 'renater-idp', |
| 65 |
'spconfprefix' => 'renater-sp', |
| 66 |
} |
| 67 |
}; |
| 68 |
|
| 69 |
# Run import |
| 70 |
transform_config( $importConf, $lmConf, $xml ); |
| 71 |
is( scalar grep( /^renater-sp/, keys( %{ $lmConf->{samlSPMetaDataXML} } ) ), |
| 72 |
$sp_in_file ); |
| 73 |
is( |
| 74 |
scalar |
| 75 |
grep( /^renater-idp/, keys( %{ $lmConf->{samlIDPMetaDataXML} } ) ), |
| 76 |
$idp_in_file |
| 77 |
); |
| 78 |
}; |
| 79 |
|
| 80 |
# Make sure matching providers who are not in the metadata are removed |
| 81 |
# but non-matching providers are left alone |
| 82 |
subtest 'Remove' => sub { |
| 83 |
my $lmConf = { |
| 84 |
samlSPMetaDataXML => { |
| 85 |
'sp-toremove' => { samlSPMetaDataXML => "removeme" }, |
| 86 |
'tokeep' => { samlSPMetaDataXML => "keepme" }, |
| 87 |
}, |
| 88 |
samlSPMetaDataExportedAttributes => { |
| 89 |
'sp-toremove' => {}, |
| 90 |
'tokeep' => {}, |
| 91 |
}, |
| 92 |
samlSPMetaDataOptions => { |
| 93 |
'sp-toremove' => {}, |
| 94 |
'tokeep' => {}, |
| 95 |
}, |
| 96 |
samlIDPMetaDataXML => { |
| 97 |
'idp-toremove' => { samlSPMetaDataXML => "removeme" }, |
| 98 |
'tokeep' => { samlSPMetaDataXML => "keepme" }, |
| 99 |
}, |
| 100 |
samlIDPMetaDataExportedAttributes => { |
| 101 |
'idp-toremove' => {}, |
| 102 |
'tokeep' => {}, |
| 103 |
}, |
| 104 |
samlIDPMetaDataOptions => { |
| 105 |
'idp-toremove' => {}, |
| 106 |
'tokeep' => {}, |
| 107 |
}, |
| 108 |
}; |
| 109 |
my $importConf = { |
| 110 |
main => { |
| 111 |
'remove' => 1, |
| 112 |
} |
| 113 |
}; |
| 114 |
|
| 115 |
# Run import |
| 116 |
transform_config( $importConf, $lmConf, $xml ); |
| 117 |
ok( !$lmConf->{samlSPMetaDataOptions}->{'sp-toremove'} ); |
| 118 |
ok( $lmConf->{samlSPMetaDataOptions}->{'tokeep'} ); |
| 119 |
ok( !$lmConf->{samlSPMetaDataExportedAttributes}->{'sp-toremove'} ); |
| 120 |
ok( $lmConf->{samlSPMetaDataExportedAttributes}->{'tokeep'} ); |
| 121 |
ok( !$lmConf->{samlSPMetaDataXML}->{'sp-toremove'} ); |
| 122 |
ok( $lmConf->{samlSPMetaDataXML}->{'tokeep'} ); |
| 123 |
ok( !$lmConf->{samlIDPMetaDataOptions}->{'idp-toremove'} ); |
| 124 |
ok( $lmConf->{samlIDPMetaDataOptions}->{'tokeep'} ); |
| 125 |
ok( !$lmConf->{samlIDPMetaDataExportedAttributes}->{'idp-toremove'} ); |
| 126 |
ok( $lmConf->{samlIDPMetaDataExportedAttributes}->{'tokeep'} ); |
| 127 |
ok( !$lmConf->{samlIDPMetaDataXML}->{'idp-toremove'} ); |
| 128 |
ok( $lmConf->{samlIDPMetaDataXML}->{'tokeep'} ); |
| 129 |
}; |
| 130 |
|
| 131 |
subtest 'IDP Exported attributes' => sub { |
| 132 |
my $lmConf = {}; |
| 133 |
my $importConf = { |
| 134 |
exportedAttributes => { |
| 135 |
cn => '0;cn', |
| 136 |
eduPersonPrincipalName => '1;eduPersonPrincipalName', |
| 137 |
}, |
| 138 |
'https://univ-machineDebian.fr/idp/shibboleth' => { |
| 139 |
exported_attribute_uid => '0;uid', |
| 140 |
} |
| 141 |
}; |
| 142 |
|
| 143 |
# Run import |
| 144 |
transform_config( $importConf, $lmConf, $xml ); |
| 145 |
is_deeply( |
| 146 |
$lmConf->{samlIDPMetaDataExportedAttributes} |
| 147 |
->{'idp-idp-test-insa-rennes-fr-idp-shibboleth'}, |
| 148 |
{ |
| 149 |
cn => '0;cn', |
| 150 |
eduPersonPrincipalName => '1;eduPersonPrincipalName', |
| 151 |
} |
| 152 |
); |
| 153 |
is_deeply( |
| 154 |
$lmConf->{samlIDPMetaDataExportedAttributes} |
| 155 |
->{'idp-univ-machineDebian-fr-idp-shibboleth'}, |
| 156 |
{ |
| 157 |
cn => '0;cn', |
| 158 |
eduPersonPrincipalName => '1;eduPersonPrincipalName', |
| 159 |
uid => '0;uid', |
| 160 |
} |
| 161 |
); |
| 162 |
}; |
| 163 |
|
| 164 |
subtest 'SP Exported attributes' => sub { |
| 165 |
my $lmConf = {}; |
| 166 |
my $importConf = { |
| 167 |
ALL => { |
| 168 |
attribute_required => 0, |
| 169 |
}, |
| 170 |
'https://ucopia.univ-brest.fr/' => { |
| 171 |
attribute_required => 1, |
| 172 |
attribute_required_uid => 0, |
| 173 |
} |
| 174 |
}; |
| 175 |
|
| 176 |
# Run import |
| 177 |
transform_config( $importConf, $lmConf, $xml ); |
| 178 |
like( |
| 179 |
$lmConf->{samlSPMetaDataExportedAttributes} |
| 180 |
->{'sp-umr5557-kaa-univ-lyon1-fr-sp'}->{mail}, |
| 181 |
qr/^0/, |
| 182 |
); |
| 183 |
like( |
| 184 |
$lmConf->{samlSPMetaDataExportedAttributes} |
| 185 |
->{'sp-ucopia-univ-brest-fr'}->{mail}, |
| 186 |
qr/^1/, |
| 187 |
); |
| 188 |
like( |
| 189 |
$lmConf->{samlSPMetaDataExportedAttributes} |
| 190 |
->{'sp-ucopia-univ-brest-fr'}->{uid}, |
| 191 |
qr/^0/ |
| 192 |
); |
| 193 |
}; |
| 194 |
|
| 195 |
subtest 'Options' => sub { |
| 196 |
my $lmConf = {}; |
| 197 |
my $importConf = { |
| 198 |
ALL => { |
| 199 |
samlSPMetaDataOptionsCheckSSOMessageSignature => 0, |
| 200 |
samlIDPMetaDataOptionsStoreSAMLToken => 1, |
| 201 |
}, |
| 202 |
'https://ucopia.univ-brest.fr/' => { |
| 203 |
samlSPMetaDataOptionsCheckSSOMessageSignature => 1 |
| 204 |
}, |
| 205 |
'https://univ-machineDebian.fr/idp/shibboleth' => { |
| 206 |
samlIDPMetaDataOptionsForceAuthn => 1, |
| 207 |
}, |
| 208 |
}; |
| 209 |
|
| 210 |
# Run import |
| 211 |
transform_config( $importConf, $lmConf, $xml ); |
| 212 |
is( |
| 213 |
$lmConf->{samlSPMetaDataOptions}->{'sp-ucopia-univ-brest-fr'} |
| 214 |
->{samlSPMetaDataOptionsCheckSSOMessageSignature}, |
| 215 |
1 |
| 216 |
); |
| 217 |
is( |
| 218 |
$lmConf->{samlSPMetaDataOptions}->{'sp-wiki-uness-fr'} |
| 219 |
->{samlSPMetaDataOptionsCheckSSOMessageSignature}, |
| 220 |
0 |
| 221 |
); |
| 222 |
is( |
| 223 |
$lmConf->{samlIDPMetaDataOptions} |
| 224 |
->{'idp-shibboleth-2022-grenoble-archi-fr-idp'} |
| 225 |
->{samlIDPMetaDataOptionsStoreSAMLToken}, |
| 226 |
1 |
| 227 |
); |
| 228 |
is( |
| 229 |
$lmConf->{samlIDPMetaDataOptions} |
| 230 |
->{'idp-shibboleth-2022-grenoble-archi-fr-idp'} |
| 231 |
->{samlIDPMetaDataOptionsForceAuthn}, |
| 232 |
0 |
| 233 |
); |
| 234 |
is( |
| 235 |
$lmConf->{samlIDPMetaDataOptions} |
| 236 |
->{'idp-univ-machineDebian-fr-idp-shibboleth'} |
| 237 |
->{samlIDPMetaDataOptionsForceAuthn}, |
| 238 |
1 |
| 239 |
); |
| 240 |
}; |
| 241 |
|
| 242 |
done_testing(); |