-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pascalockert/master
Additional method to get Key URI without Google Charts
- Loading branch information
Showing
4 changed files
with
68 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,17 @@ | |
|
||
require_once __DIR__ . '/../../src/Otp/GoogleAuthenticator.php'; | ||
|
||
require_once 'PHPUnit/Framework/TestCase.php'; | ||
|
||
use Otp\GoogleAuthenticator; | ||
|
||
/** | ||
* GoogleAuthenticator test case. | ||
*/ | ||
class GoogleAuthenticatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Tests getQrCodeUrl | ||
*/ | ||
public function testGetQrCodeUrl() | ||
/** | ||
* Tests getQrCodeUrl | ||
*/ | ||
public function testGetQrCodeUrl() | ||
{ | ||
$secret = 'MEP3EYVA6XNFNVNM'; // testing secret | ||
|
||
|
@@ -31,13 +29,36 @@ public function testGetQrCodeUrl() | |
); | ||
|
||
// totp, this time with a parameter for chaning the size of the QR | ||
$this->assertEquals( | ||
'https://chart.googleapis.com/chart?chs=300x300&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fuser%40host.com%3Fsecret%3DMEP3EYVA6XNFNVNM', | ||
GoogleAuthenticator::getQrCodeUrl('totp', '[email protected]', $secret, null, array('height' => 300, 'width' => 300)) | ||
$this->assertEquals( | ||
'https://chart.googleapis.com/chart?chs=300x300&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fuser%40host.com%3Fsecret%3DMEP3EYVA6XNFNVNM', | ||
GoogleAuthenticator::getQrCodeUrl('totp', '[email protected]', $secret, null, array('height' => 300, 'width' => 300)) | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Tests getKeyUri | ||
*/ | ||
public function testGetKeyUri() | ||
{ | ||
$secret = 'MEP3EYVA6XNFNVNM'; // testing secret | ||
|
||
// Standard totp case | ||
$this->assertEquals( | ||
'otpauth://totp/[email protected]?secret=MEP3EYVA6XNFNVNM', | ||
GoogleAuthenticator::getKeyUri('totp', '[email protected]', $secret) | ||
); | ||
|
||
// hotp (include a counter) | ||
$this->assertEquals( | ||
'otpauth://hotp/[email protected]?secret=MEP3EYVA6XNFNVNM&counter=1234', | ||
GoogleAuthenticator::getKeyUri('hotp', '[email protected]', $secret, 1234) | ||
); | ||
|
||
} | ||
|
||
/** | ||
* Tests generateRandom | ||
*/ | ||
public function testGenerateRandom() | ||
{ | ||
// contains numbers 2-7 and letters A-Z in large letters, 16 chars long | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters