Skip to content

Commit

Permalink
Make Saml2\Auth can accept the param
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed May 30, 2024
1 parent 2dffd9c commit 89b18c8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/Saml2/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/src/OneLogin/Saml2/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
29 changes: 29 additions & 0 deletions tests/src/OneLogin/Saml2/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 89b18c8

Please sign in to comment.