From 89b18c81eb78eb3071d229902717cf547ef77971 Mon Sep 17 00:00:00 2001 From: Sixto Martin Date: Thu, 30 May 2024 12:29:34 +0200 Subject: [PATCH] Make Saml2\Auth can accept the param --- src/Saml2/Auth.php | 11 ++++----- tests/src/OneLogin/Saml2/AuthTest.php | 29 +++++++++++++++++++++++ tests/src/OneLogin/Saml2/SettingsTest.php | 29 +++++++++++++++++++++++ 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/Saml2/Auth.php b/src/Saml2/Auth.php index f8038daf..ab927af4 100644 --- a/src/Saml2/Auth.php +++ b/src/Saml2/Auth.php @@ -18,11 +18,7 @@ use Exception; /** -<<<<<<< HEAD - * Main class of PHP Toolkit -======= * Main class of SAML PHP Toolkit ->>>>>>> f338e1e... Remove references to onelogin support. */ class Auth { @@ -169,14 +165,15 @@ class Auth /** * Initializes the SP SAML instance. * - * @param array|null $settings Setting data + * @param array|null $settings Setting data + * @param bool $spValidationOnly Validate or not the IdP data * * @throws Exception * @throws Error */ - public function __construct(array $settings = null) + public function __construct(array $settings = null, $spValidationOnly = false) { - $this->_settings = new Settings($settings); + $this->_settings = new Settings($settings, $spValidationOnly); } /** diff --git a/tests/src/OneLogin/Saml2/AuthTest.php b/tests/src/OneLogin/Saml2/AuthTest.php index 5e8aaa67..c0d45dd2 100644 --- a/tests/src/OneLogin/Saml2/AuthTest.php +++ b/tests/src/OneLogin/Saml2/AuthTest.php @@ -52,6 +52,35 @@ public function testGetSettings() $this->assertEquals($authSettings, $settings); } + /** + * Tests the use of the spValidationOnly at OneLogin\Saml2\Auth + * + * @covers OneLogin\Saml2\Auth + */ + public function testSpValidateOnlyIsTrue() + { + $settingsDir = TEST_ROOT .'/settings/'; + include $settingsDir.'settings2.php'; + unset($settingsInfo['idp']); + + $auth = new Auth($settingsInfo, true); + $this->assertEmpty($auth->getErrors()); + + try { + $auth2 = new Auth($settingsInfo, false); + $this->fail('Error was not raised'); + } catch (Error $e) { + $this->assertContains('idp_not_found', $e->getMessage()); + } + + try { + $auth3 = new Auth($settingsInfo); + $this->fail('Error was not raised'); + } catch (Error $e) { + $this->assertContains('idp_not_found', $e->getMessage()); + } + } + /** * Tests the getLastRequestID method of the Auth class * diff --git a/tests/src/OneLogin/Saml2/SettingsTest.php b/tests/src/OneLogin/Saml2/SettingsTest.php index e3061bff..83c7049e 100644 --- a/tests/src/OneLogin/Saml2/SettingsTest.php +++ b/tests/src/OneLogin/Saml2/SettingsTest.php @@ -51,6 +51,35 @@ public function testLoadSettingsFromArray() $this->assertEmpty($settings3->getErrors()); } + /** + * Tests the use of the spValidationOnly at OneLogin\Saml2\Settings + * + * @covers OneLogin\Saml2\Settings + */ + public function testSpValidateOnlyIsTrue() + { + $settingsDir = TEST_ROOT .'/settings/'; + include $settingsDir.'settings2.php'; + unset($settingsInfo['idp']); + + $settings = new Settings($settingsInfo, true); + $this->assertEmpty($settings->getErrors()); + + try { + $settings2 = new Settings($settingsInfo, false); + $this->fail('Error was not raised'); + } catch (Error $e) { + $this->assertContains('idp_not_found', $e->getMessage()); + } + + try { + $settings3 = new Settings($settingsInfo); + $this->fail('Error was not raised'); + } catch (Error $e) { + $this->assertContains('idp_not_found', $e->getMessage()); + } + } + /** * Tests the Settings Constructor. * Case load setting from file