2014-04-16 05:50:58 -04:00
|
|
|
<?php
|
2015-02-04 04:46:36 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-04-16 05:50:58 -04:00
|
|
|
|
2015-06-02 03:58:57 -04:00
|
|
|
namespace Tests\Icinga\Forms\Config\UserBackend;
|
2014-04-16 05:50:58 -04:00
|
|
|
|
2014-04-25 10:39:54 -04:00
|
|
|
// Necessary as some of these tests disable phpunit's preservation
|
|
|
|
|
// of the global state (e.g. autoloaders are in the global state)
|
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../../../../bootstrap.php');
|
|
|
|
|
|
2014-04-16 10:41:23 -04:00
|
|
|
use Mockery;
|
2014-11-18 07:11:52 -05:00
|
|
|
use Icinga\Data\ConfigObject;
|
2014-04-16 05:50:58 -04:00
|
|
|
use Icinga\Test\BaseTestCase;
|
2015-06-02 03:58:57 -04:00
|
|
|
use Icinga\Forms\Config\UserBackend\LdapBackendForm;
|
2014-07-03 10:15:02 -04:00
|
|
|
use Icinga\Exception\AuthenticationException;
|
2014-04-16 05:50:58 -04:00
|
|
|
|
|
|
|
|
class LdapBackendFormTest extends BaseTestCase
|
|
|
|
|
{
|
2014-04-16 10:41:23 -04:00
|
|
|
public function tearDown()
|
|
|
|
|
{
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
Mockery::close(); // Necessary because some tests run in a separate process
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-16 05:50:58 -04:00
|
|
|
/**
|
|
|
|
|
* @runInSeparateProcess
|
2014-04-25 10:39:54 -04:00
|
|
|
* @preserveGlobalState disabled
|
2014-04-16 05:50:58 -04:00
|
|
|
*/
|
|
|
|
|
public function testValidBackendIsValid()
|
|
|
|
|
{
|
2015-06-05 11:20:31 -04:00
|
|
|
$ldapUserBackendMock = Mockery::mock('overload:Icinga\Authentication\User\LdapUserBackend');
|
|
|
|
|
$ldapUserBackendMock->shouldReceive('assertAuthenticationPossible')->andReturnNull();
|
|
|
|
|
$this->setUpUserBackendMock($ldapUserBackendMock);
|
2014-04-16 05:50:58 -04:00
|
|
|
|
2015-04-30 09:20:19 -04:00
|
|
|
// Passing array(null) is required to make Mockery call the constructor...
|
2015-06-02 03:58:57 -04:00
|
|
|
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null));
|
2015-03-04 03:43:37 -05:00
|
|
|
$form->shouldReceive('getView->escape')
|
|
|
|
|
->with(Mockery::type('string'))
|
|
|
|
|
->andReturnUsing(function ($s) { return $s; });
|
2014-09-09 04:36:42 -04:00
|
|
|
$form->setTokenDisabled();
|
|
|
|
|
$form->setResources(array('test_ldap_backend'));
|
|
|
|
|
$form->populate(array('resource' => 'test_ldap_backend'));
|
2014-04-16 05:50:58 -04:00
|
|
|
|
|
|
|
|
$this->assertTrue(
|
2015-06-02 03:58:57 -04:00
|
|
|
LdapBackendForm::isValidUserBackend($form),
|
|
|
|
|
'LdapBackendForm claims that a valid user backend with users is not valid'
|
2014-04-16 05:50:58 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @runInSeparateProcess
|
2014-04-25 10:39:54 -04:00
|
|
|
* @preserveGlobalState disabled
|
2014-04-16 05:50:58 -04:00
|
|
|
*/
|
|
|
|
|
public function testInvalidBackendIsNotValid()
|
|
|
|
|
{
|
2015-06-05 11:20:31 -04:00
|
|
|
$ldapUserBackendMock = Mockery::mock('overload:Icinga\Authentication\User\LdapUserBackend');
|
|
|
|
|
$ldapUserBackendMock->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException);
|
|
|
|
|
$this->setUpUserBackendMock($ldapUserBackendMock);
|
2014-04-16 05:50:58 -04:00
|
|
|
|
2015-04-30 09:20:19 -04:00
|
|
|
// Passing array(null) is required to make Mockery call the constructor...
|
2015-06-02 03:58:57 -04:00
|
|
|
$form = Mockery::mock('Icinga\Forms\Config\UserBackend\LdapBackendForm[getView]', array(null));
|
2015-03-04 03:43:37 -05:00
|
|
|
$form->shouldReceive('getView->escape')
|
|
|
|
|
->with(Mockery::type('string'))
|
|
|
|
|
->andReturnUsing(function ($s) { return $s; });
|
2014-09-09 04:36:42 -04:00
|
|
|
$form->setTokenDisabled();
|
|
|
|
|
$form->setResources(array('test_ldap_backend'));
|
|
|
|
|
$form->populate(array('resource' => 'test_ldap_backend'));
|
2014-04-16 05:50:58 -04:00
|
|
|
|
|
|
|
|
$this->assertFalse(
|
2015-06-02 03:58:57 -04:00
|
|
|
LdapBackendForm::isValidUserBackend($form),
|
|
|
|
|
'LdapBackendForm claims that an invalid user backend without users is valid'
|
2014-04-16 05:50:58 -04:00
|
|
|
);
|
|
|
|
|
}
|
2014-07-03 10:15:02 -04:00
|
|
|
|
2015-06-05 11:20:31 -04:00
|
|
|
protected function setUpUserBackendMock($ldapUserBackendMock)
|
2014-07-03 10:15:02 -04:00
|
|
|
{
|
2015-06-05 11:20:31 -04:00
|
|
|
Mockery::mock('alias:Icinga\Authentication\User\UserBackend')
|
|
|
|
|
->shouldReceive('create')
|
|
|
|
|
->andReturn($ldapUserBackendMock);
|
2014-07-03 10:15:02 -04:00
|
|
|
}
|
2014-04-16 05:50:58 -04:00
|
|
|
}
|