Debian Codegraph @

lemonldap-ng-common/t/45-importMetadata.t

raw
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 my $lmConf = {};
21 my $importConf = {};
22
23 # Run import
24 my ( $spCounters, $idpCounters ) =
25 transform_config( $importConf, $lmConf, $xml );
26
27 # Check statistics
28 is_deeply(
29 $spCounters,
30 {
31 'created' => $sp_in_file,
32 'found' => $sp_in_file + 1,
33 'ignored' => 0,
34 'rejected' => 1,
35 'removed' => 0,
36 'updated' => 0
37 },
38 "SP counters are expected"
39 );
40 is_deeply(
41 $idpCounters,
42 {
43 'created' => $idp_in_file,
44 'found' => $idp_in_file + 1,
45 'ignored' => 0,
46 'rejected' => 1,
47 'removed' => 0,
48 'updated' => 0
49 },
50 "IDP counters are expected"
51 );
52
53 is( keys %{ $lmConf->{samlIDPMetaDataXML} },
54 $idp_in_file, "Correct amount of providers" );
55 is( keys %{ $lmConf->{samlIDPMetaDataExportedAttributes} },
56 $idp_in_file, "Correct amount of providers" );
57 is( keys %{ $lmConf->{samlIDPMetaDataOptions} },
58 $idp_in_file, "Correct amount of providers" );
59 is( keys %{ $lmConf->{samlSPMetaDataXML} },
60 $sp_in_file, "Correct amount of providers" );
61 is( keys %{ $lmConf->{samlSPMetaDataExportedAttributes} },
62 $sp_in_file, "Correct amount of providers" );
63 is( keys %{ $lmConf->{samlSPMetaDataOptions} },
64 $sp_in_file, "Correct amount of providers" );
65
66 my $idp = "idp-idp-test-insa-rennes-fr-idp-shibboleth";
67 my $sp = "sp-ucopia-univ-brest-fr";
68 my $eduroam =
69 "sp-monitor-eduroam-org-sp-module-php-saml-sp-metadata-php-default-sp";
70
71 is(
72 $lmConf->{samlIDPMetaDataExportedAttributes}->{$idp}
73 ->{eduPersonPrincipalName},
74 '0;eduPersonPrincipalName', "Found exported attribute"
75 );
76
77 is(
78 $lmConf->{samlSPMetaDataExportedAttributes}->{$sp}->{supannEtablissement},
79 join( ';',
80 0,
81 'urn:oid:1.3.6.1.4.1.7135.1.2.1.14',
82 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri',
83 'supannEtablissement' ),
84 "Found optional attribute"
85 );
86
87 is(
88 $lmConf->{samlSPMetaDataExportedAttributes}->{$sp}->{uid},
89 join( ';',
90 1,
91 'urn:oid:0.9.2342.19200300.100.1.1',
92 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri', 'uid' ),
93 "Found required attribute"
94 );
95
96 is(
97
98 $lmConf->{samlSPMetaDataExportedAttributes}->{$eduroam}->{'subjectId'},
99 join( ';',
100 0,
101 'urn:oasis:names:tc:SAML:attribute:subject-id',
102 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri', 'subject-id' ),
103 "Found subject ID"
104 );
105
106 # Check update
107 $lmConf->{samlSPMetaDataOptions}->{$sp}
108 ->{samlSPMetaDataOptionsCheckSSOMessageSignature} = 0;
109 $lmConf->{samlIDPMetaDataOptions}->{$idp}
110 ->{samlIDPMetaDataOptionsAllowLoginFromIDP} = 1;
111 ( $spCounters, $idpCounters ) = transform_config( $importConf, $lmConf, $xml );
112
113 # Check statistics
114 is_deeply(
115 $spCounters,
116 {
117 'created' => 0,
118 'found' => $sp_in_file + 1,
119 'ignored' => 0,
120 'rejected' => 1,
121 'removed' => 0,
122 'updated' => 1
123 },
124 "SP counters are expected"
125 );
126 is_deeply(
127 $idpCounters,
128 {
129 'created' => 0,
130 'found' => $idp_in_file + 1,
131 'ignored' => 0,
132 'rejected' => 1,
133 'removed' => 0,
134 'updated' => 1
135 },
136 "IDP counters are expected"
137 );
138 is(
139 $lmConf->{samlSPMetaDataOptions}->{$sp}
140 ->{samlSPMetaDataOptionsCheckSSOMessageSignature},
141 1, "Configuration was updated"
142 );
143 is(
144 $lmConf->{samlIDPMetaDataOptions}->{$idp}
145 ->{samlIDPMetaDataOptionsAllowLoginFromIDP},
146 0, "Configuration was updated"
147 );
148
149 # Check idempotence
150 my $oldLmConf = dclone $lmConf;
151 ( $spCounters, $idpCounters ) = transform_config( $importConf, $lmConf, $xml );
152
153 is_deeply(
154 $spCounters,
155 {
156 'created' => 0,
157 'found' => $sp_in_file + 1,
158 'ignored' => 0,
159 'rejected' => 1,
160 'removed' => 0,
161 'updated' => 0
162 },
163 "SP counters are expected"
164 );
165 is_deeply(
166 $idpCounters,
167 {
168 'created' => 0,
169 'found' => $idp_in_file + 1,
170 'ignored' => 0,
171 'rejected' => 1,
172 'removed' => 0,
173 'updated' => 0
174 },
175 "IDP counters are expected"
176 );
177
178 is_deeply( $lmConf, $oldLmConf );
179 done_testing();