diff options
author | RobThree <rob@devcorner.nl> | 2015-03-20 16:46:24 +0100 |
---|---|---|
committer | RobThree <rob@devcorner.nl> | 2015-03-20 16:46:24 +0100 |
commit | bfebb4b57d53d46ce69223b26daa2dfb65ec30f7 (patch) | |
tree | f0bafda052489cd48041fdadf3d76d44dbc023cb | |
parent | c02a8a5b843e4ae2a4d54e61a599d7b43ea1055c (diff) | |
download | TwoFactorAuth-bfebb4b57d53d46ce69223b26daa2dfb65ec30f7.zip TwoFactorAuth-bfebb4b57d53d46ce69223b26daa2dfb65ec30f7.tar.gz TwoFactorAuth-bfebb4b57d53d46ce69223b26daa2dfb65ec30f7.tar.bz2 |
* Added known testvectors from RFC 6238 to unittests
-rw-r--r-- | tests/TwoFactorAuthTest.php | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/TwoFactorAuthTest.php b/tests/TwoFactorAuthTest.php index 36d409e..a847e43 100644 --- a/tests/TwoFactorAuthTest.php +++ b/tests/TwoFactorAuthTest.php @@ -132,11 +132,48 @@ class TwoFactorAuthTest extends PHPUnit_Framework_TestCase */ public function testGetQRCodeImageAsDataUriThrowsOnInvalidSize() { $qr = new TestQrProvider(); - + $tfa = new \RobThree\Auth\TwoFactorAuth('Test', 6, 30, 'sha1', $qr); $tfa->getQRCodeImageAsDataUri('Test', 'VMR466AB62ZBOKHE', 0); } + public function testKnownTestVectors_sha1() { + //Known test vectors for SHA1: https://tools.ietf.org/html/rfc6238#page-15 + $secret = 'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ'; //== base32encode('12345678901234567890') + $tfa = new \RobThree\Auth\TwoFactorAuth('Test', 8, 30, 'sha1'); + $this->assertEquals('94287082', $tfa->getCode($secret, 59)); + $this->assertEquals('07081804', $tfa->getCode($secret, 1111111109)); + $this->assertEquals('14050471', $tfa->getCode($secret, 1111111111)); + $this->assertEquals('89005924', $tfa->getCode($secret, 1234567890)); + $this->assertEquals('69279037', $tfa->getCode($secret, 2000000000)); + $this->assertEquals('65353130', $tfa->getCode($secret, 20000000000)); + } + + public function testKnownTestVectors_sha256() { + //Known test vectors for SHA256: https://tools.ietf.org/html/rfc6238#page-15 + $secret = 'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZA'; //== base32encode('12345678901234567890123456789012') + $tfa = new \RobThree\Auth\TwoFactorAuth('Test', 8, 30, 'sha256'); + $this->assertEquals('46119246', $tfa->getCode($secret, 59)); + $this->assertEquals('68084774', $tfa->getCode($secret, 1111111109)); + $this->assertEquals('67062674', $tfa->getCode($secret, 1111111111)); + $this->assertEquals('91819424', $tfa->getCode($secret, 1234567890)); + $this->assertEquals('90698825', $tfa->getCode($secret, 2000000000)); + $this->assertEquals('77737706', $tfa->getCode($secret, 20000000000)); + } + + public function testKnownTestVectors_sha512() { + //Known test vectors for SHA512: https://tools.ietf.org/html/rfc6238#page-15 + $secret = 'GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQGEZDGNA'; //== base32encode('1234567890123456789012345678901234567890123456789012345678901234') + $tfa = new \RobThree\Auth\TwoFactorAuth('Test', 8, 30, 'sha512'); + $this->assertEquals('90693936', $tfa->getCode($secret, 59)); + $this->assertEquals('25091201', $tfa->getCode($secret, 1111111109)); + $this->assertEquals('99943326', $tfa->getCode($secret, 1111111111)); + $this->assertEquals('93441116', $tfa->getCode($secret, 1234567890)); + $this->assertEquals('38618901', $tfa->getCode($secret, 2000000000)); + $this->assertEquals('47863826', $tfa->getCode($secret, 20000000000)); + } + + private function DecodeDataUri($datauri) { if (preg_match('/data:(?P<mimetype>[\w\.\-\/]+);(?P<encoding>\w+),(?P<data>.*)/', $datauri, $m) === 1) { return array( |