diff options
author | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
---|---|---|
committer | Gerardo Zamudio <gerardozamudio@users.noreply.github.com> | 2016-02-24 23:48:50 -0600 |
commit | e4de6b3898b64b26d29aff31f21df5fda8055686 (patch) | |
tree | 575f8a65440f291d70a070d168eafca8c82a6459 /tests/units/Auth/TotpAuthTest.php | |
parent | d9ffbea174ea6524d0a22f8375ca8b3aa04a3c96 (diff) | |
parent | a6540bc604c837d92c9368540c145606723e97f7 (diff) |
Merge pull request #1 from fguillot/master
Update from upstream
Diffstat (limited to 'tests/units/Auth/TotpAuthTest.php')
-rw-r--r-- | tests/units/Auth/TotpAuthTest.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/units/Auth/TotpAuthTest.php b/tests/units/Auth/TotpAuthTest.php new file mode 100644 index 00000000..c8dcfb28 --- /dev/null +++ b/tests/units/Auth/TotpAuthTest.php @@ -0,0 +1,66 @@ +<?php + +require_once __DIR__.'/../Base.php'; + +use Kanboard\Auth\TotpAuth; + +class TotpAuthTest extends Base +{ + public function testGetName() + { + $provider = new TotpAuth($this->container); + $this->assertEquals('Time-based One-time Password Algorithm', $provider->getName()); + } + + public function testGetSecret() + { + $provider = new TotpAuth($this->container); + $this->assertEmpty($provider->getSecret()); + + $provider->generateSecret(); + $secret = $provider->getSecret(); + + $this->assertNotEmpty($secret); + $this->assertEquals($secret, $provider->getSecret()); + $this->assertEquals($secret, $provider->getSecret()); + } + + public function testSetSecret() + { + $provider = new TotpAuth($this->container); + $provider->setSecret('mySecret'); + $this->assertEquals('mySecret', $provider->getSecret()); + } + + public function testGetUrl() + { + $provider = new TotpAuth($this->container); + $this->assertEmpty($provider->getQrCodeUrl('me')); + $this->assertEmpty($provider->getKeyUrl('me')); + + $provider->setSecret('mySecret'); + $this->assertEquals( + 'https://chart.googleapis.com/chart?chs=200x200&cht=qr&chld=M|0&chl=otpauth%3A%2F%2Ftotp%2Fme%3Fsecret%3DmySecret', + $provider->getQrCodeUrl('me') + ); + + $this->assertEquals('otpauth://totp/me?secret=mySecret', $provider->getKeyUrl('me')); + } + + public function testAuthentication() + { + $provider = new TotpAuth($this->container); + + $secret = $provider->generateSecret(); + $this->assertNotEmpty($secret); + + $provider->setCode('1234'); + $this->assertFalse($provider->authenticate()); + + if (!!`which oathtool`) { + $code = shell_exec('oathtool --totp -b '.$secret); + $provider->setCode(trim($code)); + $this->assertTrue($provider->authenticate()); + } + } +} |