PHP Censor fixes
This commit is contained in:
parent
9db4b09bd9
commit
b1d5c9cec2
15 changed files with 164 additions and 161 deletions
86
tests/PHPCensor/Security/Authentication/ServiceTest.php
Normal file
86
tests/PHPCensor/Security/Authentication/ServiceTest.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace Tests\PHPCensor\Security\Authentication;
|
||||
|
||||
use PHPCensor\Security\Authentication\Service;
|
||||
|
||||
class ServiceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Service::getInstance
|
||||
*/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('\PHPCensor\Security\Authentication\Service', Service::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Service::buildProvider
|
||||
*/
|
||||
public function testBuildBuiltinProvider()
|
||||
{
|
||||
$provider = Service::buildProvider('test', ['internal' => ['type' => 'internal']]);
|
||||
|
||||
$this->assertInstanceOf('\PHPCensor\Security\Authentication\UserProvider\Internal', $provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Service::buildProvider
|
||||
*/
|
||||
public function testBuildAnyProvider()
|
||||
{
|
||||
$config = array('type' => '\PHPCensor\Security\Authentication\Tests\DummyProvider');
|
||||
$provider = Service::buildProvider("test", $config);
|
||||
|
||||
$this->assertInstanceOf('\PHPCensor\Security\Authentication\Tests\DummyProvider', $provider);
|
||||
$this->assertEquals('test', $provider->key);
|
||||
$this->assertEquals($config, $provider->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Service::getProviders
|
||||
*/
|
||||
public function testGetProviders()
|
||||
{
|
||||
$a = $this->prophesize('\PHPCensor\Security\Authentication\UserProvider')->reveal();
|
||||
$b = $this->prophesize('\PHPCensor\Security\Authentication\UserProvider')->reveal();
|
||||
$providers = array('a' => $a, 'b' => $b);
|
||||
|
||||
$service = new Service($providers);
|
||||
|
||||
$this->assertEquals($providers, $service->getProviders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Service::getLoginPasswordProviders
|
||||
*/
|
||||
public function testGetLoginPasswordProviders()
|
||||
{
|
||||
$a = $this->prophesize('\PHPCensor\Security\Authentication\UserProvider')->reveal();
|
||||
$b = $this->prophesize('\PHPCensor\Security\Authentication\LoginPasswordProvider')->reveal();
|
||||
$providers = array('a' => $a, 'b' => $b);
|
||||
|
||||
$service = new Service($providers);
|
||||
|
||||
$this->assertEquals(array('b' => $b), $service->getLoginPasswordProviders());
|
||||
}
|
||||
}
|
||||
|
||||
class DummyProvider
|
||||
{
|
||||
public $key;
|
||||
public $config;
|
||||
public function __construct($key, array $config)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->config = $config;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace Tests\PHPCensor\Security\Authentication\UserProvider;
|
||||
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Security\Authentication\UserProvider\Internal;
|
||||
|
||||
class InternalTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Internal
|
||||
*/
|
||||
protected $provider;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->provider = new Internal("internal");
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Internal::verifyPassword
|
||||
*/
|
||||
public function testVerifyPassword()
|
||||
{
|
||||
$user = new User();
|
||||
$password = 'bla';
|
||||
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
|
||||
|
||||
$this->assertTrue($this->provider->verifyPassword($user, $password));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Internal::verifyPassword
|
||||
*/
|
||||
public function testVerifyInvaldPassword()
|
||||
{
|
||||
$user = new User();
|
||||
$password = 'foo';
|
||||
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
|
||||
|
||||
$this->assertFalse($this->provider->verifyPassword($user, 'bar'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Internal::checkRequirements
|
||||
*/
|
||||
public function testCheckRequirements()
|
||||
{
|
||||
$this->provider->checkRequirements();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Internal::provisionUser
|
||||
*/
|
||||
public function testProvisionUser()
|
||||
{
|
||||
$this->assertNull($this->provider->provisionUser('john@doe.com'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue