diff --git a/api/validators/TotpValidator.php b/api/validators/TotpValidator.php index 9b5f277..e436d0c 100644 --- a/api/validators/TotpValidator.php +++ b/api/validators/TotpValidator.php @@ -57,15 +57,16 @@ class TotpValidator extends Validator { } private function getTimestamp(): ?int { - if ($this->timestamp === null) { + $timestamp = $this->timestamp; + if (is_callable($timestamp)) { + $timestamp = call_user_func($this->timestamp); + } + + if ($timestamp === null) { return null; } - if (is_callable($this->timestamp)) { - return (int)call_user_func($this->timestamp); - } - - return (int)$this->timestamp; + return (int)$timestamp; } } diff --git a/tests/codeception/api/unit/validators/TotpValidatorTest.php b/tests/codeception/api/unit/validators/TotpValidatorTest.php index 9385356..dfc0bd3 100644 --- a/tests/codeception/api/unit/validators/TotpValidatorTest.php +++ b/tests/codeception/api/unit/validators/TotpValidatorTest.php @@ -39,6 +39,13 @@ class TotpValidatorTest extends TestCase { $result = $this->callProtected($validator, 'validateValue', $controlTotp->at($at)); $this->assertNull($result); + $at = function() { + return null; + }; + $validator->timestamp = $at; + $result = $this->callProtected($validator, 'validateValue', $controlTotp->now()); + $this->assertNull($result); + $at = function() { return time() - 700; };