diff options
author | therealssj <mehul.guptagm@gmail.com> | 2016-06-09 19:11:17 +0530 |
---|---|---|
committer | therealssj <mehul.guptagm@gmail.com> | 2016-06-09 19:11:17 +0530 |
commit | 352d99292defaee6b704084d2cea45b8836a90fd (patch) | |
tree | 8f8b91369b20d9c165a3247a52ecef6dc5eaec46 | |
parent | 4bc07118e008c5b07a1f923a980c6be6f09e0cb4 (diff) | |
download | otp-352d99292defaee6b704084d2cea45b8836a90fd.zip otp-352d99292defaee6b704084d2cea45b8836a90fd.tar.gz otp-352d99292defaee6b704084d2cea45b8836a90fd.tar.bz2 |
Add Unit Tests for HotpResync
-rw-r--r-- | tests/OtpTest.php | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/OtpTest.php b/tests/OtpTest.php index fe606e2..3b59e2c 100644 --- a/tests/OtpTest.php +++ b/tests/OtpTest.php @@ -120,4 +120,45 @@ class OtpTest extends \PHPUnit_Framework_TestCase $this->Otp->hotp($this->secret, 'a'); } + /** + * Tests Otp->checkHotpResync() + */ + public function testHotpResync() + { + $secret = $this->secret; + + // test default counter window + $this->assertEquals(0, $this->Otp->checkHotpResync($secret, 0, '755224')); + $this->assertEquals(1, $this->Otp->checkHotpResync($secret, 0, '287082')); + $this->assertEquals(2, $this->Otp->checkHotpResync($secret, 0, '359152')); + + // test provided counter window + $this->assertEquals(3, $this->Otp->checkHotpResync($secret, 0, '969429', 3)); + $this->assertEquals(4, $this->Otp->checkHotpResync($secret, 0, '338314', 4)); + $this->assertEquals(5, $this->Otp->checkHotpResync($secret, 0, '254676', 5)); + + // test failures + $this->assertFalse($this->Otp->checkHotpResync($secret, 7, '287922')); + $this->assertFalse($this->Otp->checkHotpResync($secret, 8, '162583')); + $this->assertFalse($this->Otp->checkHotpResync($secret, 9, '399871')); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Counter must be integer + */ + public function testHotpResyncInvalidCounter() + { + $this->Otp->checkHotpResync($this->secret, 'a', '755224'); + } + + /** + * @expectedException InvalidArgumentException + * @expectedExceptionMessage Invalid counterwindow supplied + */ + public function testHotpResyncInvalidCounterWindow() + { + $this->Otp->checkHotpResync($this->secret, 0, '755224', 'a'); + } + } |