99use SimpleSAML \Assert \AssertionFailedException ;
1010use SimpleSAML \Auth ;
1111use SimpleSAML \Configuration ;
12+ use SimpleSAML \Error \Exception ;
1213use SimpleSAML \Module \core \Auth \Source \Selector \RequestedAuthnContextSelector ;
1314
1415/**
@@ -93,6 +94,7 @@ public static function doAuthentication(Auth\Source $as, array $state): void
9394 {
9495 // Dummy
9596 }
97+
9698 /**
9799 * @param array &$state
98100 * @return void
@@ -109,6 +111,62 @@ public function authenticate(array &$state): void
109111 }
110112
111113
114+ /**
115+ */
116+ public function testIncompleteConfigurationThrowsExceptionVariant1 (): void
117+ {
118+ $ sourceConfig = Configuration::loadFromArray ([
119+ 'selector ' => [
120+ 'core:RequestedAuthnContextSelector ' ,
121+
122+ 'contexts ' => [
123+ 10 => [
124+ 'identifier ' => 'urn:x-simplesamlphp:loa1 ' ,
125+ ],
126+ ],
127+ ],
128+ ]);
129+
130+ Configuration::setPreLoadedConfig ($ this ->sourceConfig , 'authsources.php ' );
131+
132+ $ info = ['AuthId ' => 'selector ' ];
133+ $ config = $ sourceConfig ->getArray ('selector ' );
134+
135+ $ this ->expectException (Exception::class);
136+ $ this ->expectExceptionMessage ("Incomplete context '10' due to missing `source` key. " );
137+
138+ new RequestedAuthnContextSelector ($ info , $ config );
139+ }
140+
141+
142+ /**
143+ */
144+ public function testIncompleteConfigurationThrowsExceptionVariant2 (): void
145+ {
146+ $ sourceConfig = Configuration::loadFromArray ([
147+ 'selector ' => [
148+ 'core:RequestedAuthnContextSelector ' ,
149+
150+ 'contexts ' => [
151+ 10 => [
152+ 'source ' => 'loa1 ' ,
153+ ],
154+ ],
155+ ],
156+ ]);
157+
158+ Configuration::setPreLoadedConfig ($ this ->sourceConfig , 'authsources.php ' );
159+
160+ $ info = ['AuthId ' => 'selector ' ];
161+ $ config = $ sourceConfig ->getArray ('selector ' );
162+
163+ $ this ->expectException (Exception::class);
164+ $ this ->expectExceptionMessage ("Incomplete context '10' due to missing `identifier` key. " );
165+
166+ new RequestedAuthnContextSelector ($ info , $ config );
167+ }
168+
169+
112170 /**
113171 * @dataProvider provideRequestedAuthnContext
114172 * @param array $requestedAuthnContext The RequestedAuthnContext
@@ -130,7 +188,7 @@ public function selectAuthSource(array &$state): string
130188
131189 try {
132190 $ source = $ selector ->selectAuthSource ($ state );
133- } catch (AssertionFailedException | NoAuthnContextException $ e ) {
191+ } catch (AssertionFailedException | NoAuthnContextException | Exception $ e ) {
134192 $ source = $ e ::class;
135193 }
136194
@@ -204,6 +262,35 @@ public function provideRequestedAuthnContext(): array
204262 ],
205263 AssertionFailedException::class,
206264 ],
265+
266+ // Non-implemented comparison requested
267+ [
268+ [
269+ 'AuthnContextClassRef ' => [
270+ 'urn:x-simplesamlphp:loa2 ' ,
271+ ],
272+ 'Comparison ' => 'minimum ' ,
273+ ],
274+ Exception::class,
275+ ],
276+ [
277+ [
278+ 'AuthnContextClassRef ' => [
279+ 'urn:x-simplesamlphp:loa2 ' ,
280+ ],
281+ 'Comparison ' => 'maximum ' ,
282+ ],
283+ Exception::class,
284+ ],
285+ [
286+ [
287+ 'AuthnContextClassRef ' => [
288+ 'urn:x-simplesamlphp:loa2 ' ,
289+ ],
290+ 'Comparison ' => 'better ' ,
291+ ],
292+ Exception::class,
293+ ],
207294 ];
208295 }
209296}
0 commit comments