From bb512c1bf8c2b9bc87754dfe1c95daf435a33abf Mon Sep 17 00:00:00 2001 From: Ener-Getick Date: Tue, 20 Oct 2015 14:01:58 +0200 Subject: [PATCH] Fix several errors --- TOTP/TOTP.php | 2 +- TOTP/TOTPTimeManager.php | 2 +- TOTP/TOTPValidator.php | 6 +++++- {TOTP/Tests => Tests/TOTP}/KeyGenerationTest.php | 4 ++-- {TOTP/Tests => Tests/TOTP}/TimeManagerTest.php | 2 +- {TOTP/Tests => Tests/TOTP}/ValidatorTest.php | 2 +- phpunit.xml.dist | 2 -- 7 files changed, 11 insertions(+), 9 deletions(-) rename {TOTP/Tests => Tests/TOTP}/KeyGenerationTest.php (79%) rename {TOTP/Tests => Tests/TOTP}/TimeManagerTest.php (95%) rename {TOTP/Tests => Tests/TOTP}/ValidatorTest.php (97%) diff --git a/TOTP/TOTP.php b/TOTP/TOTP.php index 10db1e1..620c0a9 100644 --- a/TOTP/TOTP.php +++ b/TOTP/TOTP.php @@ -54,7 +54,7 @@ public static function generateTOTP($stamp, $key) */ public function validate($key, $totp, $stamp = null) { - return $this->validator($key, $totp, $stamp); + return $this->validator->validate($key, $totp, $stamp); } /** diff --git a/TOTP/TOTPTimeManager.php b/TOTP/TOTPTimeManager.php index adc4ba6..30859cc 100644 --- a/TOTP/TOTPTimeManager.php +++ b/TOTP/TOTPTimeManager.php @@ -41,7 +41,7 @@ public function setStampLength($stampLength = null) $stampLength = self::DEFAULT_STAMP_LENGTH; } $stampLength = intval($stampLength); - if (empty($stampLength) or $stampLength < 0) { + if (empty($stampLength) || $stampLength < 0) { throw new InvalidArgumentException('Stamp length must be greater than 0 and positive.'); } $this->stampLength = $stampLength; diff --git a/TOTP/TOTPValidator.php b/TOTP/TOTPValidator.php index a808fda..eec1f77 100644 --- a/TOTP/TOTPValidator.php +++ b/TOTP/TOTPValidator.php @@ -21,7 +21,11 @@ class TOTPValidator /** * @var TOTPTimeManager */ - protected $timeManager; + private $timeManager; + /** + * @var int|null + */ + private $window; /** * @param TOTPTimeManager|int|null $stampLength Stamp length in seconds diff --git a/TOTP/Tests/KeyGenerationTest.php b/Tests/TOTP/KeyGenerationTest.php similarity index 79% rename from TOTP/Tests/KeyGenerationTest.php rename to Tests/TOTP/KeyGenerationTest.php index a127835..bcc8531 100644 --- a/TOTP/Tests/KeyGenerationTest.php +++ b/Tests/TOTP/KeyGenerationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace EXSyst\Component\Security\TOTP\Tests; +namespace EXSyst\Component\Security\Tests\TOTP; use EXSyst\Component\Security\TOTP\TOTPKeyGenerator; @@ -22,7 +22,7 @@ public function testKeyGeneration() for ($i = 0; $i < 15; ++$i) { $length = rand(8, 100); $key = TOTPKeyGenerator::generate($length); - $this->assertRegExp(sprintf('#[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567]{%d}#', $length), $key); + $this->assertRegExp(sprintf('#[%s]{%d}#', $this->characters, $length), $key); } } } diff --git a/TOTP/Tests/TimeManagerTest.php b/Tests/TOTP/TimeManagerTest.php similarity index 95% rename from TOTP/Tests/TimeManagerTest.php rename to Tests/TOTP/TimeManagerTest.php index 9f84a53..ad15521 100644 --- a/TOTP/Tests/TimeManagerTest.php +++ b/Tests/TOTP/TimeManagerTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace EXSyst\Component\Security\TOTP\Tests; +namespace EXSyst\Component\Security\Tests\TOTP; use EXSyst\Component\Security\TOTP\TOTPTimeManager; diff --git a/TOTP/Tests/ValidatorTest.php b/Tests/TOTP/ValidatorTest.php similarity index 97% rename from TOTP/Tests/ValidatorTest.php rename to Tests/TOTP/ValidatorTest.php index e4a1347..8f5c789 100644 --- a/TOTP/Tests/ValidatorTest.php +++ b/Tests/TOTP/ValidatorTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace EXSyst\Component\Security\TOTP\Tests; +namespace EXSyst\Component\Security\Tests\TOTP; use EXSyst\Component\Security\TOTP\TOTPGenerator; use EXSyst\Component\Security\TOTP\TOTPKeyGenerator; diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 62f2afc..742701a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,7 +12,6 @@ ./Tests/ - ./TOTP/Tests/ @@ -21,7 +20,6 @@ ./vendor ./Tests/ - ./TOTP/Tests/