Skip to content

Commit 6f1e577

Browse files
committed
Raise coverage
1 parent 72c94de commit 6f1e577

4 files changed

Lines changed: 155 additions & 5 deletions

File tree

modules/core/src/Auth/Source/Selector/RequestedAuthnContextSelector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44

55
namespace SimpleSAML\Module\core\Auth\Source\Selector;
66

7-
use Exception;
87
use SAML2\Constants as C;
98
use SAML2\Exception\Protocol\NoAuthnContextException;
109
use SimpleSAML\Assert\Assert;
11-
use SimpleSAML\Error;
10+
use SimpleSAML\Error\Exception;
1211
use SimpleSAML\Logger;
1312
use SimpleSAML\Module\core\Auth\Source\AbstractSourceSelector;
1413

@@ -132,7 +131,7 @@ protected function selectAuthSource(array &$state): string
132131
case 'maximum':
133132
case 'better':
134133
// Not implemented
135-
throw new Error\Exception('Not implemented.');
134+
throw new Exception('Not implemented.');
136135
}
137136
}
138137

modules/core/src/Auth/Source/Selector/SourceIPSelector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace SimpleSAML\Module\core\Auth\Source\Selector;
66

7-
use Exception;
87
use SimpleSAML\Assert\Assert;
8+
use SimpleSAML\Error\Exception;
99
use SimpleSAML\Logger;
1010
use SimpleSAML\Module\core\Auth\Source\AbstractSourceSelector;
1111
use SimpleSAML\Utils;

tests/modules/core/src/Auth/Source/Selector/RequestedAuthnContextSelectorTest.php

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use SimpleSAML\Assert\AssertionFailedException;
1010
use SimpleSAML\Auth;
1111
use SimpleSAML\Configuration;
12+
use SimpleSAML\Error\Exception;
1213
use 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
}

tests/modules/core/src/Auth/Source/Selector/SourceIPSelectorTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use SimpleSAML\Assert\AssertionFailedException;
99
use SimpleSAML\Auth;
1010
use SimpleSAML\Configuration;
11+
use SimpleSAML\Error\Exception;
1112
use SimpleSAML\Module\core\Auth\Source\Selector\SourceIPSelector;
1213

1314
/**
@@ -159,6 +160,69 @@ public function selectAuthSource(array &$state): string
159160
}
160161

161162

163+
/**
164+
*/
165+
public function testIncompleteConfigurationThrowsExceptionVariant1(): void
166+
{
167+
$sourceConfig = Configuration::loadFromArray([
168+
'selector' => [
169+
'core:SourceIPSelector',
170+
171+
'zones' => [
172+
'internal' => [
173+
'subnet' => [
174+
'10.0.0.0/8',
175+
'2001:0DB8::/108',
176+
],
177+
],
178+
179+
'default' => 'external',
180+
],
181+
],
182+
]);
183+
184+
Configuration::setPreLoadedConfig($this->sourceConfig, 'authsources.php');
185+
186+
$info = ['AuthId' => 'selector'];
187+
$config = $sourceConfig->getArray('selector');
188+
189+
$this->expectException(Exception::class);
190+
$this->expectExceptionMessage("Incomplete zone-configuration 'internal' due to missing `source` key.");
191+
192+
new SourceIPSelector($info, $config);
193+
}
194+
195+
196+
/**
197+
*/
198+
public function testIncompleteConfigurationThrowsExceptionVariant2(): void
199+
{
200+
$sourceConfig = Configuration::loadFromArray([
201+
'selector' => [
202+
'core:SourceIPSelector',
203+
204+
'zones' => [
205+
'internal' => [
206+
'source' => 'internal',
207+
],
208+
209+
'default' => 'external',
210+
],
211+
],
212+
]);
213+
214+
Configuration::setPreLoadedConfig($this->sourceConfig, 'authsources.php');
215+
216+
$info = ['AuthId' => 'selector'];
217+
$config = $sourceConfig->getArray('selector');
218+
219+
$this->expectException(Exception::class);
220+
$this->expectExceptionMessage("Incomplete zone-configuration 'internal' due to missing `subnet` key.");
221+
222+
new SourceIPSelector($info, $config);
223+
}
224+
225+
162226
/**
163227
* @return array
164228
*/

0 commit comments

Comments
 (0)