mirror of
https://github.com/RobThree/TwoFactorAuth.git
synced 2026-08-28 02:57:17 +00:00
* Fix PHP 5.3 array syntax in unittests
This commit is contained in:
@@ -17,23 +17,23 @@ class HttpTimeProvider implements ITimeProvider
|
||||
public function getTime() {
|
||||
try {
|
||||
$host = parse_url($this->url, PHP_URL_HOST);
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
$context = stream_context_create(array(
|
||||
'http' => array(
|
||||
'method' => 'HEAD',
|
||||
'follow_location' => false,
|
||||
'ignore_errors' => true,
|
||||
'max_redirects' => 0,
|
||||
'request_fulluri' => true,
|
||||
'header' => [
|
||||
'header' => array(
|
||||
'Connection: close',
|
||||
'User-agent: TwoFactorAuth HttpTimeProvider (https://github.com/RobThree/TwoFactorAuth)'
|
||||
]
|
||||
],
|
||||
'ssl' => [
|
||||
)
|
||||
),
|
||||
'ssl' => array(
|
||||
'SNI_enabled' => true,
|
||||
'SNI_server_name' => $host
|
||||
]
|
||||
]);
|
||||
'peer_name' => $host
|
||||
)
|
||||
));
|
||||
$fd = fopen($this->url, 'rb', false, $context);
|
||||
$headers = stream_get_meta_data($fd)['wrapper_data'];
|
||||
fclose($fd);
|
||||
|
||||
@@ -101,7 +101,7 @@ class TwoFactorAuthTest extends PHPUnit_Framework_TestCase
|
||||
$tpr2 = new TestTimeProvider(128);
|
||||
|
||||
$tfa = new TwoFactorAuth('Test', 6, 30, 'sha1', null, null, $tpr1);
|
||||
$tfa->ensureCorrectTime([$tpr2]); // 128 - 123 = 5 => within default leniency
|
||||
$tfa->ensureCorrectTime(array($tpr2)); // 128 - 123 = 5 => within default leniency
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,23 +112,23 @@ class TwoFactorAuthTest extends PHPUnit_Framework_TestCase
|
||||
$tpr2 = new TestTimeProvider(124);
|
||||
|
||||
$tfa = new TwoFactorAuth('Test', 6, 30, 'sha1', null, null, $tpr1);
|
||||
$tfa->ensureCorrectTime([$tpr2], 0); // We force a leniency of 0, 124-123 = 1 so this should throw
|
||||
$tfa->ensureCorrectTime(array($tpr2), 0); // We force a leniency of 0, 124-123 = 1 so this should throw
|
||||
}
|
||||
|
||||
|
||||
public function testEnsureDefaultTimeProviderReturnsCorrectTime() {
|
||||
$tfa = new TwoFactorAuth('Test', 6, 30, 'sha1');
|
||||
$tfa->ensureCorrectTime([new TestTimeProvider(time())], 1); // Use a leniency of 1, should the time change between both time() calls
|
||||
$tfa->ensureCorrectTime(array(new TestTimeProvider(time())), 1); // Use a leniency of 1, should the time change between both time() calls
|
||||
}
|
||||
|
||||
public function testEnsureAllTimeProvidersReturnCorrectTime() {
|
||||
$tfa = new TwoFactorAuth('Test', 6, 30, 'sha1');
|
||||
$tfa->ensureCorrectTime([
|
||||
$tfa->ensureCorrectTime(array(
|
||||
new RobThree\Auth\Providers\Time\ConvertUnixTimeDotComTimeProvider(),
|
||||
new RobThree\Auth\Providers\Time\HttpTimeProvider(), // Uses google.com by default
|
||||
new RobThree\Auth\Providers\Time\HttpTimeProvider('https://github.com'),
|
||||
new RobThree\Auth\Providers\Time\HttpTimeProvider('https://yahoo.com'),
|
||||
]);
|
||||
));
|
||||
}
|
||||
|
||||
public function testVerifyCodeWorksCorrectly() {
|
||||
|
||||
Reference in New Issue
Block a user