summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/units/Auth/ApiAccessTokenAuthTest.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/units/Auth/ApiAccessTokenAuthTest.php b/tests/units/Auth/ApiAccessTokenAuthTest.php
new file mode 100644
index 00000000..22852805
--- /dev/null
+++ b/tests/units/Auth/ApiAccessTokenAuthTest.php
@@ -0,0 +1,71 @@
+<?php
+
+use Kanboard\Auth\ApiAccessTokenAuth;
+use Kanboard\Model\UserModel;
+
+require_once __DIR__.'/../Base.php';
+
+class ApiAccessTokenAuthTest extends Base
+{
+ public function testGetName()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+ $this->assertEquals('API Access Token', $provider->getName());
+ }
+
+ public function testAuthenticateWithoutToken()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+
+ $provider->setUsername('admin');
+ $provider->setPassword('admin');
+ $this->assertFalse($provider->authenticate());
+ $this->assertNull($provider->getUser());
+ }
+
+ public function testAuthenticateWithEmptyPassword()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+
+ $provider->setUsername('admin');
+ $provider->setPassword('');
+ $this->assertFalse($provider->authenticate());
+ }
+
+ public function testAuthenticateWithTokenAndNoScope()
+ {
+ $provider = new ApiAccessTokenAuth($this->container);
+ $userModel = new UserModel($this->container);
+
+ $userModel->update(array(
+ 'id' => 1,
+ 'api_access_token' => 'test',
+ ));
+
+ $provider->setUsername('admin');
+ $provider->setPassword('test');
+ $this->assertFalse($provider->authenticate());
+ }
+
+ public function testAuthenticateWithToken()
+ {
+ $this->container['sessionStorage']->scope = 'API';
+
+ $provider = new ApiAccessTokenAuth($this->container);
+ $userModel = new UserModel($this->container);
+
+ $userModel->update(array(
+ 'id' => 1,
+ 'api_access_token' => 'test',
+ ));
+
+ $provider->setUsername('admin');
+ $provider->setPassword('test');
+ $this->assertTrue($provider->authenticate());
+ $this->assertInstanceOf('Kanboard\User\DatabaseUserProvider', $provider->getUser());
+
+ $provider->setUsername('admin');
+ $provider->setPassword('something else');
+ $this->assertFalse($provider->authenticate());
+ }
+}