Skip to content

Commit 36ecb1c

Browse files
committed
PHP7 production settings compiles out assert(), throw an exception on is_bool check specifically
1 parent 43756b3 commit 36ecb1c

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

lib/Saml2/Auth.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public function getSettings()
102102
*/
103103
public function setStrict($value)
104104
{
105-
assert('is_bool($value)');
105+
if (! (is_bool($value))) {
106+
throw new Exception('Invalid value passed to setStrict()');
107+
}
108+
106109
$this->_settings->setStrict($value);
107110
}
108111

lib/Saml2/Settings.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
2+
33
/**
44
* Configuration of the OneLogin PHP Toolkit
55
*
@@ -15,7 +15,7 @@ class OneLogin_Saml2_Settings
1515
private $_paths = array();
1616

1717
/**
18-
* Strict. If active, PHP Toolkit will reject unsigned or unencrypted messages
18+
* Strict. If active, PHP Toolkit will reject unsigned or unencrypted messages
1919
* if it expects them signed or encrypted. If not, the messages will be accepted
2020
* and some security issues will be also relaxed.
2121
*
@@ -209,7 +209,7 @@ public function getSchemasPath()
209209
* Loads settings info from a settings Array
210210
*
211211
* @param array $settings SAML Toolkit Settings
212-
*
212+
*
213213
* @return bool True if the settings info is valid
214214
*/
215215
private function _loadSettingsFromArray($settings)
@@ -698,7 +698,7 @@ public function getSPMetadata()
698698
OneLogin_Saml2_Error::PRIVATE_KEY_FILE_NOT_FOUND
699699
);
700700
}
701-
701+
702702
if (!$certMetadata) {
703703
throw new OneLogin_Saml2_Error(
704704
'Public cert file not found.',
@@ -719,7 +719,7 @@ public function getSPMetadata()
719719

720720
$keyMetadataFile = $this->_paths['cert'].$keyFileName;
721721
$certMetadataFile = $this->_paths['cert'].$certFileName;
722-
722+
723723

724724
if (!file_exists($keyMetadataFile)) {
725725
throw new OneLogin_Saml2_Error(
@@ -728,7 +728,7 @@ public function getSPMetadata()
728728
array($keyMetadataFile)
729729
);
730730
}
731-
731+
732732
if (!file_exists($certMetadataFile)) {
733733
throw new OneLogin_Saml2_Error(
734734
'Public cert file not found: %s',
@@ -835,7 +835,9 @@ public function getErrors()
835835
*/
836836
public function setStrict($value)
837837
{
838-
assert('is_bool($value)');
838+
if (! (is_bool($value))) {
839+
throw new Exception('Invalid value passed to setStrict()');
840+
}
839841

840842
$this->_strict = $value;
841843
}

tests/src/OneLogin/Saml2/AuthTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function setUp()
2323
/**
2424
* Tests the getSettings method of the OneLogin_Saml2_Auth class
2525
* Build a OneLogin_Saml2_Settings object with a setting array
26-
* and compare the value returned from the method of the
26+
* and compare the value returned from the method of the
2727
* $auth object
2828
*
2929
* @covers OneLogin_Saml2_Auth::getSettings
@@ -93,7 +93,7 @@ public function testProcessNoResponse()
9393
* @covers OneLogin_Saml2_Auth::getErrors
9494
* @covers OneLogin_Saml2_Auth::getSessionIndex
9595
* @covers OneLogin_Saml2_Auth::getSessionExpiration
96-
* @covers OneLogin_Saml2_Auth::getLastErrorReason
96+
* @covers OneLogin_Saml2_Auth::getLastErrorReason
9797
*/
9898
public function testProcessResponseInvalid()
9999
{
@@ -150,7 +150,7 @@ public function testProcessResponseInvalidRequestId()
150150
*
151151
* @covers OneLogin_Saml2_Auth::processResponse
152152
* @covers OneLogin_Saml2_Auth::isAuthenticated
153-
* @covers OneLogin_Saml2_Auth::getAttributes
153+
* @covers OneLogin_Saml2_Auth::getAttributes
154154
* @covers OneLogin_Saml2_Auth::getAttribute
155155
* @covers OneLogin_Saml2_Auth::getNameId
156156
* @covers OneLogin_Saml2_Auth::getSessionIndex
@@ -178,7 +178,7 @@ public function testProcessResponseValid()
178178

179179
/**
180180
* Tests the redirectTo method of the OneLogin_Saml2_Auth class
181-
* (phpunit raises an exception when a redirect is executed, the
181+
* (phpunit raises an exception when a redirect is executed, the
182182
* exception is catched and we check that the targetURL is correct)
183183
* Case redirect without url parameter
184184
*
@@ -205,7 +205,7 @@ public function testRedirectTo()
205205

206206
/**
207207
* Tests the redirectTo method of the OneLogin_Saml2_Auth class
208-
* (phpunit raises an exception when a redirect is executed, the
208+
* (phpunit raises an exception when a redirect is executed, the
209209
* exception is catched and we check that the targetURL is correct)
210210
* Case redirect with url parameter
211211
*
@@ -358,7 +358,7 @@ public function testProcessSLOResponseValid()
358358

359359
/**
360360
* Tests the processSLO method of the OneLogin_Saml2_Auth class
361-
* Case Valid Logout Response, validating deleting the local session
361+
* Case Valid Logout Response, validating deleting the local session
362362
*
363363
* @covers OneLogin_Saml2_Auth::processSLO
364364
*/
@@ -482,7 +482,7 @@ public function testProcessSLORequestInvalidValid()
482482
*
483483
* @covers OneLogin_Saml2_Auth::processSLO
484484
*/
485-
485+
486486
public function testProcessSLORequestNotOnOrAfterFailed()
487487
{
488488
$message = file_get_contents(TEST_ROOT . '/data/logout_requests/invalids/not_after_failed.xml.base64');
@@ -741,7 +741,7 @@ public function testLogin()
741741

742742
/**
743743
* Tests the login method of the OneLogin_Saml2_Auth class
744-
* Case Login with relayState. An AuthnRequest is built. GET with SAMLRequest,
744+
* Case Login with relayState. An AuthnRequest is built. GET with SAMLRequest,
745745
* and RelayState. A redirection is executed
746746
*
747747
* @covers OneLogin_Saml2_Auth::login
@@ -880,7 +880,7 @@ public function testLoginForceAuthN()
880880
$request = gzinflate($decoded);
881881
$this->assertNotContains('ForceAuthn="true"', $request);
882882
}
883-
883+
884884
try {
885885
// The Header of the redirect produces an Exception
886886
$returnTo = 'http://example.com/returnto';
@@ -962,7 +962,7 @@ public function testLoginIsPassive()
962962
$request = gzinflate($decoded);
963963
$this->assertNotContains('IsPassive="true"', $request);
964964
}
965-
965+
966966
try {
967967
// The Header of the redirect produces an Exception
968968
$returnTo = 'http://example.com/returnto';
@@ -1040,7 +1040,7 @@ public function testLoginNameIDPolicy()
10401040
$request = gzinflate($decoded);
10411041
$this->assertNotContains('<samlp:NameIDPolicy', $request);
10421042
}
1043-
1043+
10441044
try {
10451045
// The Header of the redirect produces an Exception
10461046
$returnTo = 'http://example.com/returnto';
@@ -1285,7 +1285,7 @@ public function testLogoutSigned()
12851285

12861286
/**
12871287
* Tests the logout method of the OneLogin_Saml2_Auth class
1288-
* Case IdP no SLO endpoint.
1288+
* Case IdP no SLO endpoint.
12891289
*
12901290
* @covers OneLogin_Saml2_Auth::logout
12911291
*/
@@ -1335,7 +1335,7 @@ public function testSetStrict()
13351335
$auth->setStrict('a');
13361336
$this->assertTrue(false);
13371337
} catch (Exception $e) {
1338-
$this->assertContains('Assertion "is_bool($value)" failed', $e->getMessage());
1338+
$this->assertContains('Invalid value passed to setStrict()', $e->getMessage());
13391339
}
13401340
}
13411341

tests/src/OneLogin/Saml2/SettingsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class OneLogin_Saml2_SettingsTest extends PHPUnit_Framework_TestCase
77
{
88

99
/**
10-
* Tests the OneLogin_Saml2_Settings Constructor.
10+
* Tests the OneLogin_Saml2_Settings Constructor.
1111
* Case load setting from array
1212
*
1313
* @covers OneLogin_Saml2_Settings
@@ -43,7 +43,7 @@ public function testLoadSettingsFromArray()
4343
}
4444

4545
/**
46-
* Tests the OneLogin_Saml2_Settings Constructor.
46+
* Tests the OneLogin_Saml2_Settings Constructor.
4747
* Case load setting from OneLogin_Saml_Settings's object
4848
*
4949
* @covers OneLogin_Saml2_Settings
@@ -60,7 +60,7 @@ public function testLoadSettingsFromObject()
6060
}
6161

6262
/**
63-
* Tests the OneLogin_Saml2_Settings Constructor.
63+
* Tests the OneLogin_Saml2_Settings Constructor.
6464
* Case load setting from file
6565
*
6666
* @covers OneLogin_Saml2_Settings
@@ -740,7 +740,7 @@ public function testSetStrict()
740740
$settings->setStrict('a');
741741
$this->assertTrue(false);
742742
} catch (Exception $e) {
743-
$this->assertContains('Assertion "is_bool($value)" failed', $e->getMessage());
743+
$this->assertContains('Invalid value passed to setStrict()', $e->getMessage());
744744
}
745745
}
746746

0 commit comments

Comments
 (0)