Skip to content

Commit 7971760

Browse files
committed
Use DateTime/DateTimeZone classes
1 parent 52d583d commit 7971760

4 files changed

Lines changed: 4 additions & 11 deletions

File tree

lib/Saml2/Metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static function builder($sp, $authnsign = false, $wsign = false, $validUn
4444
if (!isset($validUntil)) {
4545
$validUntil = time() + self::TIME_VALID;
4646
}
47-
$validUntilTime = gmdate('Y-m-d\TH:i:s\Z', $validUntil);
47+
$validUntilTime = OneLogin_Saml2_Utils::parseTime2SAML($validUntil);
4848

4949
if (!isset($cacheDuration)) {
5050
$cacheDuration = self::TIME_CACHED;

lib/Saml2/Utils.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,8 @@ public static function generateUniqueID()
676676
*/
677677
public static function parseTime2SAML($time)
678678
{
679-
$defaultTimezone = date_default_timezone_get();
680-
date_default_timezone_set('UTC');
681-
$timestamp = strftime("%Y-%m-%dT%H:%M:%SZ", $time);
682-
date_default_timezone_set($defaultTimezone);
679+
$date = new DateTime("@$time", new DateTimeZone('UTC'));
680+
$timestamp = $date->format("Y-m-d\TH:i:s\Z");
683681
return $timestamp;
684682
}
685683

tests/src/OneLogin/Saml2/ResponseTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,6 @@ public function testGetIssuers()
535535
}
536536
}
537537

538-
539-
540-
541538
/**
542539
* Tests the getSessionIndex method of the OneLogin_Saml2_Response
543540
*
@@ -556,7 +553,6 @@ public function testGetSessionIndex()
556553
$this->assertEquals('_7164a9a9f97828bfdb8d0ebc004a05d2e7d873f70c', $response2->getSessionIndex());
557554
}
558555

559-
560556
/**
561557
* Tests the getAttributes method of the OneLogin_Saml2_Response
562558
*
@@ -1194,7 +1190,6 @@ public function testIsInValidRequestId()
11941190
$this->assertContains('No Signature found. SAML Response rejected', $response2->getError());
11951191
}
11961192

1197-
11981193
/**
11991194
* Tests the isValid method of the OneLogin_Saml2_Response class
12001195
* Case Invalid Response, Invalid signing issues

tests/src/OneLogin/Saml2/UtilsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ public function testParseTime2SAML()
714714
OneLogin_Saml2_Utils::parseTime2SAML('invalidtime');
715715
$this->fail('Exception was not raised');
716716
} catch (Exception $e) {
717-
$this->assertContains('strftime() expects parameter 2 to be', $e->getMessage());
717+
$this->assertContains('Failed to parse time string', $e->getMessage());
718718
}
719719
}
720720

0 commit comments

Comments
 (0)