summaryrefslogtreecommitdiff
path: root/tests/units/Auth/TotpAuthTest.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-12-05 20:31:27 -0500
committerFrederic Guillot <fred@kanboard.net>2015-12-05 20:31:27 -0500
commite9fedf3e5cd63aea4da7a71f6647ee427c62fa49 (patch)
treeabc2de5aebace4a2d7c94805552264dab6b10bc7 /tests/units/Auth/TotpAuthTest.php
parent346b8312e5ac877ce3192c2db3a26b500018bbb5 (diff)
Rewrite of the authentication and authorization system
Diffstat (limited to 'tests/units/Auth/TotpAuthTest.php')
-rw-r--r--tests/units/Auth/TotpAuthTest.php63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/units/Auth/TotpAuthTest.php b/tests/units/Auth/TotpAuthTest.php
new file mode 100644
index 00000000..fcb7ea31
--- /dev/null
+++ b/tests/units/Auth/TotpAuthTest.php
@@ -0,0 +1,63 @@
+<?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);
+ $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->getSecret();
+ $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());
+ }
+ }
+}