From 40239b4ee52583c37752d3ef4fba554fb7ae4010 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Thu, 23 Feb 2017 02:18:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20TOTP=20=D0=B2=D0=B0=D0=BB=D0=B8=D0=B4=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B0,=20=D0=B5=D1=81=D0=BB=D0=B8=20Closure?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20timestamp=20=D0=B2=D0=BE=D0=B7=D0=B2?= =?UTF-8?q?=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D1=82=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/validators/TotpValidator.php | 13 +++++++------ .../api/unit/validators/TotpValidatorTest.php | 7 +++++++ 2 files changed, 14 insertions(+), 6 deletions(-) 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; };