Skip to content

Commit d86ee7d

Browse files
committed
Add more tests to cover spValidationOnly param
1 parent f43b388 commit d86ee7d

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

lib/Saml2/Auth.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ class OneLogin_Saml2_Auth
143143
/**
144144
* Initializes the SP SAML instance.
145145
*
146-
* @param array|object|null $oldSettings Setting data (You can provide a OneLogin_Saml_Settings, the settings object of the Saml folder implementation)
147-
* @param bool $spValidationOnly if you only as an SP , you should set it to false if not you should set it to true
146+
* @param array|object|null $oldSettings Setting data (You can provide a OneLogin_Saml_Settings, the settings object of the Saml folder implementation)
147+
* @param bool $spValidationOnly If true, The library will only validate the SAML SP settings
148148
*
149149
* @throws OneLogin_Saml2_Error
150150
*/

tests/src/OneLogin/Saml2/AuthTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@ public function testGetSettings()
3939
$this->assertEquals($authSettings, $settings);
4040
}
4141

42+
/**
43+
* Tests the use of the spValidationOnly at OneLogin_Saml2_Auth
44+
*
45+
* @covers OneLogin_Saml2_Auth
46+
*/
47+
public function testSpValidateOnly()
48+
{
49+
$settingsDir = TEST_ROOT .'/settings/';
50+
include $settingsDir.'settings2.php';
51+
unset($settingsInfo['idp']);
52+
53+
$auth = new OneLogin_Saml2_Auth($settingsInfo, true);
54+
$this->assertEmpty($auth->getErrors());
55+
56+
try {
57+
$auth2 = new OneLogin_Saml2_Auth($settingsInfo, false);
58+
$this->fail('Error was not raised');
59+
} catch (OneLogin_Saml2_Error $e) {
60+
$this->assertContains('idp_not_found', $e->getMessage());
61+
}
62+
63+
try {
64+
$auth3 = new OneLogin_Saml2_Auth($settingsInfo);
65+
$this->fail('Error was not raised');
66+
} catch (OneLogin_Saml2_Error $e) {
67+
$this->assertContains('idp_not_found', $e->getMessage());
68+
}
69+
}
70+
4271
/**
4372
* Tests the getLastRequestID method of the OneLogin_Saml2_Auth class
4473
*

tests/src/OneLogin/Saml2/SettingsTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,35 @@ public function testLoadSettingsFromFile()
7474
$this->assertEmpty($settings->getErrors());
7575
}
7676

77+
/**
78+
* Tests the use of the spValidationOnly at OneLogin_Saml2_Settings
79+
*
80+
* @covers OneLogin_Saml2_Settings
81+
*/
82+
public function testSpValidateOnly()
83+
{
84+
$settingsDir = TEST_ROOT .'/settings/';
85+
include $settingsDir.'settings2.php';
86+
unset($settingsInfo['idp']);
87+
88+
$settings = new OneLogin_Saml2_Settings($settingsInfo, true);
89+
$this->assertEmpty($settings->getErrors());
90+
91+
try {
92+
$settings2 = new OneLogin_Saml2_Settings($settingsInfo, false);
93+
$this->fail('Error was not raised');
94+
} catch (OneLogin_Saml2_Error $e) {
95+
$this->assertContains('idp_not_found', $e->getMessage());
96+
}
97+
98+
try {
99+
$settings3 = new OneLogin_Saml2_Settings($settingsInfo);
100+
$this->fail('Error was not raised');
101+
} catch (OneLogin_Saml2_Error $e) {
102+
$this->assertContains('idp_not_found', $e->getMessage());
103+
}
104+
}
105+
77106
/**
78107
* Tests getCertPath method of the OneLogin_Saml2_Settings
79108
*

0 commit comments

Comments
 (0)