2014-04-16 11:50:58 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
|
|
|
namespace Tests\Icinga\Form\Config\Authentication;
|
|
|
|
|
2014-04-25 16:39:54 +02: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 16:41:23 +02:00
|
|
|
use Mockery;
|
2014-04-16 11:50:58 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
|
|
|
use Icinga\Form\Config\Authentication\LdapBackendForm;
|
2014-07-03 16:15:02 +02:00
|
|
|
use Icinga\Exception\AuthenticationException;
|
2014-04-16 11:50:58 +02:00
|
|
|
|
|
|
|
class LdapBackendFormTest extends BaseTestCase
|
|
|
|
{
|
2014-04-16 16:41:23 +02:00
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
parent::tearDown();
|
|
|
|
Mockery::close(); // Necessary because some tests run in a separate process
|
|
|
|
}
|
|
|
|
|
2014-04-16 11:50:58 +02:00
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
2014-04-25 16:39:54 +02:00
|
|
|
* @preserveGlobalState disabled
|
2014-04-16 11:50:58 +02:00
|
|
|
*/
|
|
|
|
public function testValidBackendIsValid()
|
|
|
|
{
|
2014-07-03 16:15:02 +02:00
|
|
|
$this->setUpResourceFactoryMock();
|
|
|
|
Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend')
|
|
|
|
->shouldReceive('assertAuthenticationPossible')->andReturn(null);
|
2014-04-16 11:50:58 +02:00
|
|
|
|
|
|
|
$form = new LdapBackendForm();
|
|
|
|
$form->setBackendName('test');
|
|
|
|
$form->setResources(array('test_ldap_backend' => null));
|
|
|
|
$form->create();
|
|
|
|
$form->populate(array('backend_test_resource' => 'test_ldap_backend'));
|
|
|
|
|
|
|
|
$this->assertTrue(
|
|
|
|
$form->isValidAuthenticationBackend(),
|
|
|
|
'LdapBackendForm claims that a valid authentication backend with users is not valid'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @runInSeparateProcess
|
2014-04-25 16:39:54 +02:00
|
|
|
* @preserveGlobalState disabled
|
2014-04-16 11:50:58 +02:00
|
|
|
*/
|
|
|
|
public function testInvalidBackendIsNotValid()
|
|
|
|
{
|
2014-07-03 16:15:02 +02:00
|
|
|
$this->setUpResourceFactoryMock();
|
|
|
|
Mockery::mock('overload:Icinga\Authentication\Backend\LdapUserBackend')
|
|
|
|
->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException);
|
2014-04-16 11:50:58 +02:00
|
|
|
|
|
|
|
$form = new LdapBackendForm();
|
|
|
|
$form->setBackendName('test');
|
|
|
|
$form->setResources(array('test_ldap_backend' => null));
|
|
|
|
$form->create();
|
|
|
|
$form->populate(array('backend_test_resource' => 'test_ldap_backend'));
|
|
|
|
|
|
|
|
$this->assertFalse(
|
|
|
|
$form->isValidAuthenticationBackend(),
|
|
|
|
'LdapBackendForm claims that an invalid authentication backend without users is valid'
|
|
|
|
);
|
|
|
|
}
|
2014-07-03 16:15:02 +02:00
|
|
|
|
|
|
|
protected function setUpResourceFactoryMock()
|
|
|
|
{
|
|
|
|
Mockery::mock('alias:Icinga\Data\ResourceFactory')
|
|
|
|
->shouldReceive('ldapAvailable')
|
|
|
|
->andReturn(true)
|
|
|
|
->shouldReceive('getResourceConfig')
|
|
|
|
->andReturn(new \Zend_Config(array()))
|
|
|
|
->shouldReceive('createResource')
|
|
|
|
->with(Mockery::type('\Zend_Config'))
|
|
|
|
->andReturn(Mockery::mock('Icinga\Protocol\Ldap\Connection'));
|
|
|
|
}
|
2014-04-16 11:50:58 +02:00
|
|
|
}
|