Skip to content

Commit 26a656f

Browse files
committed
Make Saml2\Auth can accept the spValidationOnly param
1 parent 2dffd9c commit 26a656f

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

src/Saml2/Auth.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
use Exception;
1919

2020
/**
21-
<<<<<<< HEAD
22-
* Main class of PHP Toolkit
23-
=======
2421
* Main class of SAML PHP Toolkit
25-
>>>>>>> f338e1e... Remove references to onelogin support.
2622
*/
2723
class Auth
2824
{
@@ -169,14 +165,15 @@ class Auth
169165
/**
170166
* Initializes the SP SAML instance.
171167
*
172-
* @param array|null $settings Setting data
168+
* @param array|null $settings Setting data
169+
* @param bool $spValidationOnly Validate or not the IdP data
173170
*
174171
* @throws Exception
175172
* @throws Error
176173
*/
177-
public function __construct(array $settings = null)
174+
public function __construct(array $settings = null, $spValidationOnly = false)
178175
{
179-
$this->_settings = new Settings($settings);
176+
$this->_settings = new Settings($settings, $spValidationOnly);
180177
}
181178

182179
/**

tests/src/OneLogin/Saml2/AuthTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,35 @@ public function testGetSettings()
5252
$this->assertEquals($authSettings, $settings);
5353
}
5454

55+
/**
56+
* Tests the use of the spValidationOnly at OneLogin\Saml2\Auth
57+
*
58+
* @covers OneLogin\Saml2\Auth
59+
*/
60+
public function testSpValidateOnly()
61+
{
62+
$settingsDir = TEST_ROOT .'/settings/';
63+
include $settingsDir.'settings2.php';
64+
unset($settingsInfo['idp']);
65+
66+
$auth = new Auth($settingsInfo, true);
67+
$this->assertEmpty($auth->getErrors());
68+
69+
try {
70+
$auth2 = new Auth($settingsInfo, false);
71+
$this->fail('Error was not raised');
72+
} catch (Error $e) {
73+
$this->assertContains('idp_not_found', $e->getMessage());
74+
}
75+
76+
try {
77+
$auth3 = new Auth($settingsInfo);
78+
$this->fail('Error was not raised');
79+
} catch (Error $e) {
80+
$this->assertContains('idp_not_found', $e->getMessage());
81+
}
82+
}
83+
5584
/**
5685
* Tests the getLastRequestID method of the Auth class
5786
*

tests/src/OneLogin/Saml2/SettingsTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,35 @@ public function testLoadSettingsFromArray()
5151
$this->assertEmpty($settings3->getErrors());
5252
}
5353

54+
/**
55+
* Tests the use of the spValidationOnly at OneLogin\Saml2\Settings
56+
*
57+
* @covers OneLogin\Saml2\Settings
58+
*/
59+
public function testSpValidateOnly()
60+
{
61+
$settingsDir = TEST_ROOT .'/settings/';
62+
include $settingsDir.'settings2.php';
63+
unset($settingsInfo['idp']);
64+
65+
$settings = new Settings($settingsInfo, true);
66+
$this->assertEmpty($settings->getErrors());
67+
68+
try {
69+
$settings2 = new Settings($settingsInfo, false);
70+
$this->fail('Error was not raised');
71+
} catch (Error $e) {
72+
$this->assertContains('idp_not_found', $e->getMessage());
73+
}
74+
75+
try {
76+
$settings3 = new Settings($settingsInfo);
77+
$this->fail('Error was not raised');
78+
} catch (Error $e) {
79+
$this->assertContains('idp_not_found', $e->getMessage());
80+
}
81+
}
82+
5483
/**
5584
* Tests the Settings Constructor.
5685
* Case load setting from file

0 commit comments

Comments
 (0)