mirror of
https://github.com/elyby/accounts.git
synced 2025-02-05 00:19:40 +05:30
Исправлено поведение TOTP валидатора, если Closure для timestamp возвращает null
This commit is contained in:
parent
689919fc17
commit
40239b4ee5
@ -57,15 +57,16 @@ class TotpValidator extends Validator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getTimestamp(): ?int {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_callable($this->timestamp)) {
|
return (int)$timestamp;
|
||||||
return (int)call_user_func($this->timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (int)$this->timestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,13 @@ class TotpValidatorTest extends TestCase {
|
|||||||
$result = $this->callProtected($validator, 'validateValue', $controlTotp->at($at));
|
$result = $this->callProtected($validator, 'validateValue', $controlTotp->at($at));
|
||||||
$this->assertNull($result);
|
$this->assertNull($result);
|
||||||
|
|
||||||
|
$at = function() {
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
$validator->timestamp = $at;
|
||||||
|
$result = $this->callProtected($validator, 'validateValue', $controlTotp->now());
|
||||||
|
$this->assertNull($result);
|
||||||
|
|
||||||
$at = function() {
|
$at = function() {
|
||||||
return time() - 700;
|
return time() - 700;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user