PHP Censor fixes
This commit is contained in:
parent
9db4b09bd9
commit
b1d5c9cec2
15 changed files with 164 additions and 161 deletions
|
|
@ -1,89 +0,0 @@
|
|||
<?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 PHPCI\Security\Authentication\Tests;
|
||||
|
||||
use PHPCI\Security\Authentication\Service;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
|
||||
class ServiceTest extends \Prophecy\PhpUnit\ProphecyTestCase
|
||||
{
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\Service::getInstance
|
||||
* @todo Implement testGetInstance().
|
||||
*/
|
||||
public function testGetInstance()
|
||||
{
|
||||
$this->assertInstanceOf('PHPCI\Security\Authentication\Service', Service::getInstance());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\Service::buildProvider
|
||||
*/
|
||||
public function testBuildBuiltinProvider()
|
||||
{
|
||||
$provider = Service::buildProvider("test", array('type' => 'internal'));
|
||||
|
||||
$this->assertInstanceOf('PHPCI\Security\Authentication\UserProvider\Internal', $provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\Service::buildProvider
|
||||
*/
|
||||
public function testBuildAnyProvider()
|
||||
{
|
||||
$config = array('type' => 'PHPCI\Security\Authentication\Tests\DummyProvider');
|
||||
$provider = Service::buildProvider("test", $config);
|
||||
|
||||
$this->assertInstanceOf('PHPCI\Security\Authentication\Tests\DummyProvider', $provider);
|
||||
$this->assertEquals('test', $provider->key);
|
||||
$this->assertEquals($config, $provider->config);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\Service::getProviders
|
||||
*/
|
||||
public function testGetProviders()
|
||||
{
|
||||
$a = $this->prophesize('PHPCI\Security\Authentication\UserProvider')->reveal();
|
||||
$b = $this->prophesize('PHPCI\Security\Authentication\UserProvider')->reveal();
|
||||
$providers = array('a' => $a, 'b' => $b);
|
||||
|
||||
$service = new Service($providers);
|
||||
|
||||
$this->assertEquals($providers, $service->getProviders());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\Service::getLoginPasswordProviders
|
||||
* @todo Implement testGetLoginPasswordProviders().
|
||||
*/
|
||||
public function testGetLoginPasswordProviders()
|
||||
{
|
||||
$a = $this->prophesize('PHPCI\Security\Authentication\UserProvider')->reveal();
|
||||
$b = $this->prophesize('PHPCI\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;
|
||||
}
|
||||
}
|
||||
|
|
@ -40,6 +40,9 @@
|
|||
<testsuite name="PHP Censor ProcessControl Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/ProcessControl</directory>
|
||||
</testsuite>
|
||||
<testsuite name="PHP Censor Security Test Suite">
|
||||
<directory suffix="Test.php">./tests/PHPCensor/Security</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Command;
|
||||
namespace PHPCensor\Command;
|
||||
|
||||
use PHPCI\Service\UserService;
|
||||
use PHPCI\Helper\Lang;
|
||||
use PHPCI\Store\UserStore;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Service\UserService;
|
||||
use PHPCensor\Store\UserStore;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
|
@ -43,7 +43,7 @@ class RegisterLdapUserCommand extends Command
|
|||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('phpci:register-ldap-user')
|
||||
->setName('php-censor:register-ldap-user')
|
||||
->setDescription(Lang::get('register_ldap_user'));
|
||||
}
|
||||
|
||||
|
|
@ -7,11 +7,11 @@
|
|||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Command;
|
||||
namespace PHPCensor\Command;
|
||||
|
||||
use PHPCI\Service\UserService;
|
||||
use PHPCI\Helper\Lang;
|
||||
use PHPCI\Store\UserStore;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Service\UserService;
|
||||
use PHPCensor\Store\UserStore;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
|
@ -42,7 +42,7 @@ class RegisterUserCommand extends Command
|
|||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('phpci:register-user')
|
||||
->setName('php-censor:register-user')
|
||||
->setDescription(Lang::get('register_user'));
|
||||
}
|
||||
|
||||
|
|
@ -14,6 +14,8 @@ use b8;
|
|||
use PHPCensor\Helper\Email;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\Security\Authentication\Service;
|
||||
use PHPCensor\Store\UserStore;
|
||||
|
||||
/**
|
||||
* Session Controller - Handles user login / logout.
|
||||
|
|
@ -25,12 +27,12 @@ use PHPCensor\Controller;
|
|||
class SessionController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Store\UserStore
|
||||
* @var UserStore
|
||||
*/
|
||||
protected $userStore;
|
||||
|
||||
/**
|
||||
* @var \PHPCI\Security\Authentication\Service
|
||||
* @var Service
|
||||
*/
|
||||
protected $authentication;
|
||||
|
||||
|
|
@ -41,7 +43,7 @@ class SessionController extends Controller
|
|||
{
|
||||
$this->response->disableLayout();
|
||||
$this->userStore = b8\Store\Factory::getStore('User');
|
||||
$this->authentication = \PHPCI\Security\Authentication\Service::getInstance();
|
||||
$this->authentication = Service::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -119,10 +119,12 @@ class Email
|
|||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function send(Builder $builder)
|
||||
public function send(Builder $builder = null)
|
||||
{
|
||||
$smtpServer = $this->config->get('php-censor.email_settings.smtp_address');
|
||||
$builder->logDebug(sprintf("SMTP: '%s'", !empty($smtpServer) ? 'true' : 'false'));
|
||||
if (null !== $builder) {
|
||||
$builder->logDebug(sprintf("SMTP: '%s'", !empty($smtpServer) ? 'true' : 'false'));
|
||||
}
|
||||
|
||||
$factory = new MailerFactory($this->config->get('php-censor'));
|
||||
$mailer = $factory->getSwiftMailerFromConfig();
|
||||
|
|
|
|||
|
|
@ -3,16 +3,16 @@
|
|||
/**
|
||||
* 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/
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Security\Authentication\UserProvider;
|
||||
namespace PHPCensor\Security\Authentication\UserProvider;
|
||||
|
||||
use b8\Config;
|
||||
use PHPCI\Model\User;
|
||||
use PHPCI\Security\Authentication\LoginPasswordProvider;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Security\Authentication\LoginPasswordProvider;
|
||||
|
||||
/**
|
||||
* Ldap user provider.
|
||||
|
|
@ -24,7 +24,7 @@ class Ldap extends AbstractProvider implements LoginPasswordProvider
|
|||
|
||||
public function verifyPassword(User $user, $password)
|
||||
{
|
||||
$config = Config::getInstance()->get('phpci.security.ldap', []);
|
||||
$config = Config::getInstance()->get('php-censor.security.ldap', []);
|
||||
$server = $config["server"];
|
||||
$mailAttribute = $config["mailAttribute"];
|
||||
$ldap = ldap_connect($server);
|
||||
|
|
@ -3,19 +3,19 @@
|
|||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Security\Authentication;
|
||||
namespace PHPCensor\Security\Authentication;
|
||||
|
||||
use PHPCI\Model\User;
|
||||
use PHPCensor\Model\User;
|
||||
|
||||
/**
|
||||
* User provider which authenticiation using a password.
|
||||
*
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
interface LoginPasswordProvider extends UserProvider
|
||||
{
|
||||
|
|
@ -3,19 +3,19 @@
|
|||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Security\Authentication;
|
||||
namespace PHPCensor\Security\Authentication;
|
||||
|
||||
use b8\Config;
|
||||
|
||||
/**
|
||||
* Authentication facade.
|
||||
*
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
class Service
|
||||
{
|
||||
|
|
@ -33,7 +33,7 @@ class Service
|
|||
{
|
||||
if (self::$instance === null) {
|
||||
$config = Config::getInstance()->get(
|
||||
'phpci.security.authentication',
|
||||
'php-censor.security.authentication',
|
||||
['internal' => ['type' => 'internal']]
|
||||
);
|
||||
|
||||
|
|
@ -43,6 +43,7 @@ class Service
|
|||
}
|
||||
self::$instance = new self($providers);
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +56,8 @@ class Service
|
|||
public static function buildProvider($key, $config)
|
||||
{
|
||||
$class = ucfirst($config['type']);
|
||||
if (class_exists('\\PHPCI\\Security\\Authentication\\UserProvider\\' . $class)) {
|
||||
$class = '\\PHPCI\\Security\\Authentication\\UserProvider\\' . $class;
|
||||
if (class_exists('\\PHPCensor\\Security\\Authentication\\UserProvider\\' . $class)) {
|
||||
$class = '\\PHPCensor\\Security\\Authentication\\UserProvider\\' . $class;
|
||||
}
|
||||
|
||||
return new $class($key, $config);
|
||||
|
|
@ -3,14 +3,14 @@
|
|||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
* @copyright Copyright 2015, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Security\Authentication;
|
||||
namespace PHPCensor\Security\Authentication;
|
||||
|
||||
use PHPCI\Model\User;
|
||||
use PHPCensor\Model\User;
|
||||
|
||||
/**
|
||||
* User provider interface.
|
||||
|
|
@ -22,7 +22,7 @@ interface UserProvider
|
|||
|
||||
/** Check if all software requirements are met (libraries, extensions, ...)
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function checkRequirements();
|
||||
|
||||
|
|
@ -3,19 +3,19 @@
|
|||
/**
|
||||
* 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/
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Security\Authentication\UserProvider;
|
||||
namespace PHPCensor\Security\Authentication\UserProvider;
|
||||
|
||||
use PHPCI\Security\Authentication\UserProvider;
|
||||
use PHPCensor\Security\Authentication\UserProvider;
|
||||
|
||||
/**
|
||||
* Abstract user provider.
|
||||
*
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
abstract class AbstractProvider implements UserProvider
|
||||
{
|
||||
|
|
@ -3,19 +3,20 @@
|
|||
/**
|
||||
* 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/
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Security\Authentication\UserProvider;
|
||||
namespace PHPCensor\Security\Authentication\UserProvider;
|
||||
|
||||
use PHPCI\Model\User;
|
||||
use PHPCI\Security\Authentication\LoginPasswordProvider;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Security\Authentication\LoginPasswordProvider;
|
||||
|
||||
/**
|
||||
* Internal user provider.
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
* Internal user provider
|
||||
*
|
||||
* @author Adirelle <adirelle@gmail.com>
|
||||
*/
|
||||
class Internal extends AbstractProvider implements LoginPasswordProvider
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,20 +3,17 @@
|
|||
/**
|
||||
* 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/
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Security\Authentication\UserProvider\Tests;
|
||||
namespace Tests\PHPCensor\Security\Authentication\UserProvider;
|
||||
|
||||
use PHPCI\Security\Authentication\UserProvider\Internal;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Security\Authentication\UserProvider\Internal;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2015-03-08 at 18:26:51.
|
||||
*/
|
||||
class InternalTest extends PHPUnit_Framework_TestCase
|
||||
class InternalTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Internal
|
||||
|
|
@ -29,11 +26,11 @@ class InternalTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\UserProvider\Internal::verifyPassword
|
||||
* @covers Internal::verifyPassword
|
||||
*/
|
||||
public function testVerifyPassword()
|
||||
{
|
||||
$user = new \PHPCI\Model\User;
|
||||
$user = new User();
|
||||
$password = 'bla';
|
||||
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
|
||||
|
||||
|
|
@ -41,11 +38,11 @@ class InternalTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\UserProvider\Internal::verifyPassword
|
||||
* @covers Internal::verifyPassword
|
||||
*/
|
||||
public function testVerifyInvaldPassword()
|
||||
{
|
||||
$user = new \PHPCI\Model\User;
|
||||
$user = new User();
|
||||
$password = 'foo';
|
||||
$user->setHash(password_hash($password, PASSWORD_DEFAULT));
|
||||
|
||||
|
|
@ -53,7 +50,7 @@ class InternalTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\UserProvider\Internal::checkRequirements
|
||||
* @covers Internal::checkRequirements
|
||||
*/
|
||||
public function testCheckRequirements()
|
||||
{
|
||||
|
|
@ -61,7 +58,7 @@ class InternalTest extends PHPUnit_Framework_TestCase
|
|||
}
|
||||
|
||||
/**
|
||||
* @covers PHPCI\Security\Authentication\UserProvider\Internal::provisionUser
|
||||
* @covers Internal::provisionUser
|
||||
*/
|
||||
public function testProvisionUser()
|
||||
{
|
||||
Loading…
Add table
Add a link
Reference in a new issue