Skip to content

Commit

Permalink
Add more tests to cover spValidationOnly param
Browse files Browse the repository at this point in the history
  • Loading branch information
pitbulk committed May 30, 2024
1 parent f43b388 commit d86ee7d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/Saml2/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class OneLogin_Saml2_Auth
/**
* Initializes the SP SAML instance.
*
* @param array|object|null $oldSettings Setting data (You can provide a OneLogin_Saml_Settings, the settings object of the Saml folder implementation)
* @param bool $spValidationOnly if you only as an SP , you should set it to false if not you should set it to true
* @param array|object|null $oldSettings Setting data (You can provide a OneLogin_Saml_Settings, the settings object of the Saml folder implementation)
* @param bool $spValidationOnly If true, The library will only validate the SAML SP settings
*
* @throws OneLogin_Saml2_Error
*/
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 @@ -39,6 +39,35 @@ public function testGetSettings()
$this->assertEquals($authSettings, $settings);
}

/**
* Tests the use of the spValidationOnly at OneLogin_Saml2_Auth
*
* @covers OneLogin_Saml2_Auth
*/
public function testSpValidateOnly()
{
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings2.php';
unset($settingsInfo['idp']);

$auth = new OneLogin_Saml2_Auth($settingsInfo, true);
$this->assertEmpty($auth->getErrors());

try {
$auth2 = new OneLogin_Saml2_Auth($settingsInfo, false);
$this->fail('Error was not raised');
} catch (OneLogin_Saml2_Error $e) {
$this->assertContains('idp_not_found', $e->getMessage());
}

try {
$auth3 = new OneLogin_Saml2_Auth($settingsInfo);
$this->fail('Error was not raised');
} catch (OneLogin_Saml2_Error $e) {
$this->assertContains('idp_not_found', $e->getMessage());
}
}

/**
* Tests the getLastRequestID method of the OneLogin_Saml2_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 @@ -74,6 +74,35 @@ public function testLoadSettingsFromFile()
$this->assertEmpty($settings->getErrors());
}

/**
* Tests the use of the spValidationOnly at OneLogin_Saml2_Settings
*
* @covers OneLogin_Saml2_Settings
*/
public function testSpValidateOnly()
{
$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings2.php';
unset($settingsInfo['idp']);

$settings = new OneLogin_Saml2_Settings($settingsInfo, true);
$this->assertEmpty($settings->getErrors());

try {
$settings2 = new OneLogin_Saml2_Settings($settingsInfo, false);
$this->fail('Error was not raised');
} catch (OneLogin_Saml2_Error $e) {
$this->assertContains('idp_not_found', $e->getMessage());
}

try {
$settings3 = new OneLogin_Saml2_Settings($settingsInfo);
$this->fail('Error was not raised');
} catch (OneLogin_Saml2_Error $e) {
$this->assertContains('idp_not_found', $e->getMessage());
}
}

/**
* Tests getCertPath method of the OneLogin_Saml2_Settings
*
Expand Down

0 comments on commit d86ee7d

Please sign in to comment.