Move Gitlab and Github authentication to external plugins

This commit is contained in:
Frederic Guillot
2016-01-29 23:59:58 -05:00
parent 04d8c6532c
commit 9b9d823f30
46 changed files with 6 additions and 1177 deletions

View File

@@ -1,89 +0,0 @@
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Auth\GithubAuth;
use Kanboard\Model\User;
class GithubAuthTest extends Base
{
public function testGetName()
{
$provider = new GithubAuth($this->container);
$this->assertEquals('Github', $provider->getName());
}
public function testAuthenticationSuccessful()
{
$profile = array(
'id' => 1234,
'email' => 'test@localhost',
'name' => 'Test',
);
$provider = $this
->getMockBuilder('\Kanboard\Auth\GithubAuth')
->setConstructorArgs(array($this->container))
->setMethods(array(
'getProfile',
))
->getMock();
$provider->expects($this->once())
->method('getProfile')
->will($this->returnValue($profile));
$this->assertInstanceOf('Kanboard\Auth\GithubAuth', $provider->setCode('1234'));
$this->assertTrue($provider->authenticate());
$user = $provider->getUser();
$this->assertInstanceOf('Kanboard\User\GithubUserProvider', $user);
$this->assertEquals('Test', $user->getName());
$this->assertEquals('', $user->getInternalId());
$this->assertEquals(1234, $user->getExternalId());
$this->assertEquals('', $user->getRole());
$this->assertEquals('', $user->getUsername());
$this->assertEquals('test@localhost', $user->getEmail());
$this->assertEquals('github_id', $user->getExternalIdColumn());
$this->assertEquals(array(), $user->getExternalGroupIds());
$this->assertEquals(array(), $user->getExtraAttributes());
$this->assertFalse($user->isUserCreationAllowed());
}
public function testAuthenticationFailed()
{
$provider = $this
->getMockBuilder('\Kanboard\Auth\GithubAuth')
->setConstructorArgs(array($this->container))
->setMethods(array(
'getProfile',
))
->getMock();
$provider->expects($this->once())
->method('getProfile')
->will($this->returnValue(array()));
$this->assertFalse($provider->authenticate());
$this->assertEquals(null, $provider->getUser());
}
public function testGetService()
{
$provider = new GithubAuth($this->container);
$this->assertInstanceOf('Kanboard\Core\Http\OAuth2', $provider->getService());
}
public function testUnlink()
{
$userModel = new User($this->container);
$provider = new GithubAuth($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'test', 'github_id' => '1234')));
$this->assertNotEmpty($userModel->getByExternalId('github_id', 1234));
$this->assertTrue($provider->unlink(2));
$this->assertEmpty($userModel->getByExternalId('github_id', 1234));
}
}

View File

@@ -1,89 +0,0 @@
<?php
require_once __DIR__.'/../Base.php';
use Kanboard\Auth\GitlabAuth;
use Kanboard\Model\User;
class GitlabAuthTest extends Base
{
public function testGetName()
{
$provider = new GitlabAuth($this->container);
$this->assertEquals('Gitlab', $provider->getName());
}
public function testAuthenticationSuccessful()
{
$profile = array(
'id' => 1234,
'email' => 'test@localhost',
'name' => 'Test',
);
$provider = $this
->getMockBuilder('\Kanboard\Auth\GitlabAuth')
->setConstructorArgs(array($this->container))
->setMethods(array(
'getProfile',
))
->getMock();
$provider->expects($this->once())
->method('getProfile')
->will($this->returnValue($profile));
$this->assertInstanceOf('Kanboard\Auth\GitlabAuth', $provider->setCode('1234'));
$this->assertTrue($provider->authenticate());
$user = $provider->getUser();
$this->assertInstanceOf('Kanboard\User\GitlabUserProvider', $user);
$this->assertEquals('Test', $user->getName());
$this->assertEquals('', $user->getInternalId());
$this->assertEquals(1234, $user->getExternalId());
$this->assertEquals('', $user->getRole());
$this->assertEquals('', $user->getUsername());
$this->assertEquals('test@localhost', $user->getEmail());
$this->assertEquals('gitlab_id', $user->getExternalIdColumn());
$this->assertEquals(array(), $user->getExternalGroupIds());
$this->assertEquals(array(), $user->getExtraAttributes());
$this->assertFalse($user->isUserCreationAllowed());
}
public function testAuthenticationFailed()
{
$provider = $this
->getMockBuilder('\Kanboard\Auth\GitlabAuth')
->setConstructorArgs(array($this->container))
->setMethods(array(
'getProfile',
))
->getMock();
$provider->expects($this->once())
->method('getProfile')
->will($this->returnValue(array()));
$this->assertFalse($provider->authenticate());
$this->assertEquals(null, $provider->getUser());
}
public function testGetService()
{
$provider = new GitlabAuth($this->container);
$this->assertInstanceOf('Kanboard\Core\Http\OAuth2', $provider->getService());
}
public function testUnlink()
{
$userModel = new User($this->container);
$provider = new GitlabAuth($this->container);
$this->assertEquals(2, $userModel->create(array('username' => 'test', 'gitlab_id' => '1234')));
$this->assertNotEmpty($userModel->getByExternalId('gitlab_id', 1234));
$this->assertTrue($provider->unlink(2));
$this->assertEmpty($userModel->getByExternalId('gitlab_id', 1234));
}
}

View File

@@ -10,6 +10,7 @@ use SimpleLogger\Logger;
use SimpleLogger\File;
use Kanboard\Core\Session\FlashMessage;
use Kanboard\Core\Session\SessionStorage;
use Kanboard\Core\Action\ActionManager;
class FakeHttpClient
{
@@ -104,6 +105,7 @@ abstract class Base extends PHPUnit_Framework_TestCase
->getMock();
$this->container['sessionStorage'] = new SessionStorage;
$this->container['actionManager'] = new ActionManager($this->container);
$this->container['flash'] = function($c) {
return new FlashMessage($c);