1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00

Auth tests

This commit is contained in:
fogelito 2022-08-15 22:18:37 +03:00
parent 9b85a89e71
commit f52d28e75f
2 changed files with 13 additions and 13 deletions

View file

@ -207,7 +207,7 @@ class Auth
$token->isSet('expire') &&
$token->getAttribute('type') == $type &&
$token->getAttribute('secret') === self::hash($secret) &&
$token->getAttribute('expire') >= DateTime::now()
DateTime::formatTz($token->getAttribute('expire')) >= DateTime::formatTz(DateTime::now())
) {
return (string)$token->getId();
}
@ -226,7 +226,7 @@ class Auth
$token->isSet('expire') &&
$token->getAttribute('type') == Auth::TOKEN_TYPE_PHONE &&
$token->getAttribute('secret') === $secret &&
$token->getAttribute('expire') >= DateTime::now()
DateTime::formatTz($token->getAttribute('expire')) >= DateTime::formatTz(DateTime::now())
) {
return (string) $token->getId();
}
@ -252,7 +252,7 @@ class Auth
$session->isSet('expire') &&
$session->isSet('provider') &&
$session->getAttribute('secret') === self::hash($secret) &&
$session->getAttribute('expire') >= DateTime::now()
DateTime::formatTz($session->getAttribute('expire')) >= DateTime::formatTz(DateTime::now())
) {
return $session->getId();
}

View file

@ -74,14 +74,14 @@ class AuthTest extends TestCase
$tokens1 = [
new Document([
'$id' => ID::custom('token1'),
'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), 60 * 60 * 24)),
'secret' => $hash,
'provider' => Auth::SESSION_PROVIDER_EMAIL,
'providerUid' => 'test@example.com',
]),
new Document([
'$id' => ID::custom('token2'),
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)),
'secret' => 'secret2',
'provider' => Auth::SESSION_PROVIDER_EMAIL,
'providerUid' => 'test@example.com',
@ -91,14 +91,14 @@ class AuthTest extends TestCase
$tokens2 = [
new Document([ // Correct secret and type time, wrong expire time
'$id' => ID::custom('token1'),
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)),
'secret' => $hash,
'provider' => Auth::SESSION_PROVIDER_EMAIL,
'providerUid' => 'test@example.com',
]),
new Document([
'$id' => ID::custom('token2'),
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)),
'secret' => 'secret2',
'provider' => Auth::SESSION_PROVIDER_EMAIL,
'providerUid' => 'test@example.com',
@ -119,13 +119,13 @@ class AuthTest extends TestCase
new Document([
'$id' => ID::custom('token1'),
'type' => Auth::TOKEN_TYPE_RECOVERY,
'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), 60 * 60 * 24)),
'secret' => $hash,
]),
new Document([
'$id' => ID::custom('token2'),
'type' => Auth::TOKEN_TYPE_RECOVERY,
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)),
'secret' => 'secret2',
]),
];
@ -134,13 +134,13 @@ class AuthTest extends TestCase
new Document([ // Correct secret and type time, wrong expire time
'$id' => ID::custom('token1'),
'type' => Auth::TOKEN_TYPE_RECOVERY,
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)),
'secret' => $hash,
]),
new Document([
'$id' => ID::custom('token2'),
'type' => Auth::TOKEN_TYPE_RECOVERY,
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)),
'secret' => 'secret2',
]),
];
@ -149,13 +149,13 @@ class AuthTest extends TestCase
new Document([
'$id' => ID::custom('token1'),
'type' => Auth::TOKEN_TYPE_INVITE,
'expire' => DateTime::addSeconds(new \DateTime(), 60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), 60 * 60 * 24)),
'secret' => $hash,
]),
new Document([
'$id' => ID::custom('token2'),
'type' => Auth::TOKEN_TYPE_RECOVERY,
'expire' => DateTime::addSeconds(new \DateTime(), -60 * 60 * 24),
'expire' => DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -60 * 60 * 24)),
'secret' => 'secret2',
]),
];