Refactor authentication config form tests and fix auth backend validation
refs #6011 fixes #5712
This commit is contained in:
parent
2abd96de39
commit
aaa6a56146
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
// @codingStandardsIgnoreStart
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
/**
|
||||
* This file is part of Icinga Web 2.
|
||||
|
@ -31,13 +30,10 @@ use \Icinga\Web\Controller\BaseConfigController;
|
|||
use \Icinga\Web\Widget\Tab;
|
||||
use \Icinga\Web\Widget\AlertMessageBox;
|
||||
use \Icinga\Web\Url;
|
||||
use \Icinga\Web\Hook\Configuration\ConfigurationTabBuilder;
|
||||
use \Icinga\User\Message;
|
||||
use \Icinga\Application\Icinga;
|
||||
use \Icinga\Application\Config as IcingaConfig;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
use \Icinga\Form\Config\GeneralForm;
|
||||
use \Icinga\Authentication\Manager as AuthenticationManager;
|
||||
use \Icinga\Form\Config\Authentication\ReorderForm;
|
||||
use \Icinga\Form\Config\Authentication\LdapBackendForm;
|
||||
use \Icinga\Form\Config\Authentication\DbBackendForm;
|
||||
|
@ -207,36 +203,38 @@ class ConfigController extends BaseConfigController
|
|||
/**
|
||||
* Action for creating a new authentication backend
|
||||
*/
|
||||
public function authenticationAction($showOnly = false)
|
||||
public function authenticationAction()
|
||||
{
|
||||
$config = IcingaConfig::app('authentication', true);
|
||||
$this->view->tabs->activate('authentication');
|
||||
|
||||
$order = array_keys($config->toArray());
|
||||
$this->view->backends = array();
|
||||
$this->view->messageBox = new AlertMessageBox(true);
|
||||
|
||||
foreach ($config as $backend=>$backendConfig) {
|
||||
$backends = array();
|
||||
foreach ($order as $backend) {
|
||||
$form = new ReorderForm();
|
||||
$form->setName('form_reorder_backend_' . $backend);
|
||||
$form->setAuthenticationBackend($backend);
|
||||
$form->setBackendName($backend);
|
||||
$form->setCurrentOrder($order);
|
||||
$form->setRequest($this->_request);
|
||||
|
||||
if (!$showOnly && $form->isSubmittedAndValid()) {
|
||||
if ($form->isSubmittedAndValid()) {
|
||||
if ($this->writeAuthenticationFile($form->getReorderedConfig($config))) {
|
||||
$this->addSuccessMessage('Authentication Order Updated');
|
||||
$this->redirectNow('config/authentication');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->view->backends[] = (object) array(
|
||||
'name' => $backend,
|
||||
'reorderForm' => $form
|
||||
$backends[] = (object) array(
|
||||
'name' => $backend,
|
||||
'reorderForm' => $form
|
||||
);
|
||||
}
|
||||
$this->render('authentication');
|
||||
|
||||
$this->view->backends = $backends;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -558,4 +556,3 @@ class ConfigController extends BaseConfigController
|
|||
}
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
|
|
@ -30,9 +30,10 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form\Decorator\HelpText;
|
||||
use \Icinga\Data\ResourceFactory;
|
||||
use \Icinga\Web\Form;
|
||||
use \Zend_Form_Element_Checkbox;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Web\Form\Decorator\HelpText;
|
||||
|
||||
/**
|
||||
* Base form for authentication backend forms
|
||||
|
@ -46,26 +47,26 @@ abstract class BaseBackendForm extends Form
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $backendName = '';
|
||||
protected $backendName = '';
|
||||
|
||||
/**
|
||||
* The backend configuration as a Zend_Config object
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $backend;
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* The resources to use instead of the factory provided ones (use for testing)
|
||||
*
|
||||
* @var Zend_Config
|
||||
*/
|
||||
private $resources;
|
||||
protected $resources;
|
||||
|
||||
/**
|
||||
* Set the name of the currently displayed backend
|
||||
*
|
||||
* @param string $name The name to be stored as the section when persisting
|
||||
* @param string $name The name to be stored as the section when persisting
|
||||
*/
|
||||
public function setBackendName($name)
|
||||
{
|
||||
|
@ -75,7 +76,7 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Return the backend name of this form
|
||||
*
|
||||
* @return string
|
||||
* @return string
|
||||
*/
|
||||
public function getBackendName()
|
||||
{
|
||||
|
@ -85,7 +86,7 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Return the backend configuration or a empty Zend_Config object if none is given
|
||||
*
|
||||
* @return Zend_Config
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public function getBackend()
|
||||
{
|
||||
|
@ -95,7 +96,7 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Set the backend configuration for initial population
|
||||
*
|
||||
* @param Zend_Config $backend The backend to display in this form
|
||||
* @param Zend_Config $backend The backend to display in this form
|
||||
*/
|
||||
public function setBackend(Zend_Config $backend)
|
||||
{
|
||||
|
@ -104,9 +105,8 @@ abstract class BaseBackendForm extends Form
|
|||
|
||||
/**
|
||||
* Set an alternative array of resources that should be used instead of the DBFactory resource set
|
||||
* (used for testing)
|
||||
*
|
||||
* @param array $resources The resources to use for populating the db selection field
|
||||
* @param array $resources The resources to use for populating the db selection field
|
||||
*/
|
||||
public function setResources(array $resources)
|
||||
{
|
||||
|
@ -114,9 +114,9 @@ abstract class BaseBackendForm extends Form
|
|||
}
|
||||
|
||||
/**
|
||||
* Return content of the resources.ini or previously set resources for displaying in the database selection field
|
||||
* Return content of the resources.ini or previously set resources
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
|
@ -130,13 +130,13 @@ abstract class BaseBackendForm extends Form
|
|||
/**
|
||||
* Add checkbox at the beginning of the form which allows to skip logic connection validation
|
||||
*/
|
||||
private function addForceCreationCheckbox()
|
||||
protected function addForceCreationCheckbox()
|
||||
{
|
||||
$checkbox = new \Zend_Form_Element_Checkbox(
|
||||
$checkbox = new Zend_Form_Element_Checkbox(
|
||||
array(
|
||||
'name' => 'backend_force_creation',
|
||||
'label' => 'Force Changes',
|
||||
'helptext' => 'Check this box to enforce changes without connectivity validation',
|
||||
'label' => t('Force Changes'),
|
||||
'helptext' => t('Check this box to enforce changes without connectivity validation'),
|
||||
'order' => 0
|
||||
)
|
||||
);
|
||||
|
@ -150,16 +150,16 @@ abstract class BaseBackendForm extends Form
|
|||
* If logic validation fails, the 'backend_force_creation' checkbox is prepended to the form to allow users to
|
||||
* skip the logic connection validation.
|
||||
*
|
||||
* @param array $data The form input to validate
|
||||
* @param array $data The form input to validate
|
||||
*
|
||||
* @return bool True when validation succeeded, false if not
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
public function isValid($data)
|
||||
{
|
||||
if (!parent::isValid($data)) {
|
||||
return false;
|
||||
}
|
||||
if ($this->getRequest()->getPost('backend_force_creation')) {
|
||||
if (isset($data['backend_force_creation']) && $data['backend_force_creation']) {
|
||||
return true;
|
||||
}
|
||||
if (!$this->isValidAuthenticationBackend()) {
|
||||
|
@ -173,7 +173,7 @@ abstract class BaseBackendForm extends Form
|
|||
* Return an array containing all sections defined by this form as the key and all settings
|
||||
* as an key-value sub-array
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getConfig();
|
||||
|
||||
|
@ -183,7 +183,7 @@ abstract class BaseBackendForm extends Form
|
|||
* An implementation should not throw any exception, but use the add/setErrorMessages method of
|
||||
* Zend_Form. If the 'backend_force_creation' checkbox is set, this method won't be called.
|
||||
*
|
||||
* @return bool True when validation succeeded, otherwise false
|
||||
* @return bool Whether validation succeeded or not
|
||||
*/
|
||||
abstract public function isValidAuthenticationBackend();
|
||||
}
|
||||
|
|
|
@ -29,8 +29,10 @@
|
|||
|
||||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Icinga\Authentication\Backend\DbUserBackend;
|
||||
use \Exception;
|
||||
use \Zend_Config;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
|
||||
/**
|
||||
* Form class for adding/modifying database authentication backends
|
||||
|
@ -38,21 +40,23 @@ use \Zend_Config;
|
|||
class DbBackendForm extends BaseBackendForm
|
||||
{
|
||||
/**
|
||||
* Return a list of all database resource ready to be used as the multiOptions
|
||||
* attribute in a Zend_Form_Element_Select object
|
||||
* Return content of the resources.ini or previously set resources
|
||||
*
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
private function getDatabaseResources()
|
||||
public function getResources()
|
||||
{
|
||||
$backends = array();
|
||||
foreach ($this->getResources() as $resname => $resource) {
|
||||
if ($resource['type'] !== 'db') {
|
||||
continue;
|
||||
if ($this->resources === null) {
|
||||
$res = ResourceFactory::getResourceConfigs('db')->toArray();
|
||||
|
||||
foreach (array_keys($res) as $key) {
|
||||
$res[$key] = $key;
|
||||
}
|
||||
$backends[$resname] = $resname;
|
||||
|
||||
return $res;
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
return $backends;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,9 +74,9 @@ class DbBackendForm extends BaseBackendForm
|
|||
'backend_' . $name . '_name',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => 'Backend Name',
|
||||
'helptext' => 'The name of this authentication provider',
|
||||
'allowEmpty' => false,
|
||||
'label' => t('Backend Name'),
|
||||
'helptext' => t('The name of this authentication provider'),
|
||||
'value' => $this->getBackendName()
|
||||
)
|
||||
);
|
||||
|
@ -81,12 +85,12 @@ class DbBackendForm extends BaseBackendForm
|
|||
'select',
|
||||
'backend_' . $name . '_resource',
|
||||
array(
|
||||
'label' => 'Database Connection',
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'helptext' => 'The database connection to use for authenticating with this provider',
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => $this->getDatabaseResources()
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => t('Database Connection'),
|
||||
'helptext' => t('The database connection to use for authenticating with this provider'),
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => $this->getResources()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -112,53 +116,39 @@ class DbBackendForm extends BaseBackendForm
|
|||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$name = $this->getBackendName();
|
||||
$prefix = 'backend_' . $this->filterName($name) . '_';
|
||||
|
||||
$prefix = 'backend_' . $this->filterName($this->getBackendName()) . '_';
|
||||
$section = $this->getValue($prefix . 'name');
|
||||
$cfg = array(
|
||||
'backend' => 'db',
|
||||
'target' => 'user',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
);
|
||||
return array(
|
||||
$section => $cfg
|
||||
'backend' => 'db',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
);
|
||||
|
||||
return array($section => $cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the current configuration by creating a backend and requesting the user count
|
||||
*
|
||||
* @return bool True when the backend is valid, false otherwise
|
||||
* @return bool Whether validation succeeded or not
|
||||
*
|
||||
* @see BaseBackendForm::isValidAuthenticationBackend
|
||||
*/
|
||||
public function isValidAuthenticationBackend()
|
||||
{
|
||||
// @TODO fix validation of authentication backends (AK #5712)
|
||||
return true;
|
||||
try {
|
||||
$name = $this->getBackendName();
|
||||
$dbBackend = new DbUserBackend(
|
||||
new Zend_Config(
|
||||
array(
|
||||
'backend' => 'db',
|
||||
'target' => 'user',
|
||||
'resource' => $this->getValue('backend_' . $this->filterName($name) . '_resource'),
|
||||
)
|
||||
)
|
||||
);
|
||||
$dbBackend->connect();
|
||||
if ($dbBackend->getUserCount() < 1) {
|
||||
$this->addErrorMessage("No users found under the specified database backend");
|
||||
$cfg = $this->getConfig();
|
||||
$backendName = key($cfg);
|
||||
$testConn = UserBackend::create($backendName, new Zend_Config($cfg[$backendName]));
|
||||
|
||||
if ($testConn->count() === 0) {
|
||||
$this->addErrorMessage(t('No users found under the specified database backend'));
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->addErrorMessage("Using the specified backend failed: " . $e->getMessage());
|
||||
return false;
|
||||
} catch (\Zend_Db_Statement_Exception $e) {
|
||||
$this->addErrorMessage("Using the specified backend failed: " . $e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
$this->addErrorMessage(sprintf(t('Using the specified backend failed: %s'), $e->getMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,11 +30,10 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Exception;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Authentication\Backend\LdapUserBackend;
|
||||
use \Icinga\Protocol\Ldap\Connection as LdapConnection;
|
||||
use Icinga\Web\Form;
|
||||
use Icinga\Data\ResourceFactory;
|
||||
use Icinga\Authentication\UserBackend;
|
||||
|
||||
/**
|
||||
* Form for adding or modifying LDAP authentication backends
|
||||
|
@ -42,14 +41,31 @@ use \Icinga\Protocol\Ldap\Connection as LdapConnection;
|
|||
class LdapBackendForm extends BaseBackendForm
|
||||
{
|
||||
/**
|
||||
* Create this form and add all required elements
|
||||
* Return content of the resources.ini or previously set resources
|
||||
*
|
||||
* @param $options Only useful for testing purposes:
|
||||
* 'resources' => All available resources.
|
||||
* @return array
|
||||
*/
|
||||
public function getResources()
|
||||
{
|
||||
if ($this->resources === null) {
|
||||
$res = ResourceFactory::getResourceConfigs('ldap')->toArray();
|
||||
|
||||
foreach (array_keys($res) as $key) {
|
||||
$res[$key] = $key;
|
||||
}
|
||||
|
||||
return $res;
|
||||
} else {
|
||||
return $this->resources;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this form and add all required elements
|
||||
*
|
||||
* @see Form::create()
|
||||
*/
|
||||
public function create($options = array())
|
||||
public function create()
|
||||
{
|
||||
$this->setName('form_modify_backend');
|
||||
$name = $this->filterName($this->getBackendName());
|
||||
|
@ -57,12 +73,12 @@ class LdapBackendForm extends BaseBackendForm
|
|||
|
||||
$this->addElement(
|
||||
'text',
|
||||
'backend_'.$name.'_name',
|
||||
'backend_' . $name . '_name',
|
||||
array(
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => 'Backend Name',
|
||||
'helptext' => 'The name of this authentication backend',
|
||||
'allowEmpty' => false,
|
||||
'label' => t('Backend Name'),
|
||||
'helptext' => t('The name of this authentication backend'),
|
||||
'value' => $this->getBackendName()
|
||||
)
|
||||
);
|
||||
|
@ -71,13 +87,12 @@ class LdapBackendForm extends BaseBackendForm
|
|||
'select',
|
||||
'backend_' . $name . '_resource',
|
||||
array(
|
||||
'label' => 'Database Connection',
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'helptext' => 'The database connection to use for authenticating with this provider',
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => array_key_exists('resources', $options) ?
|
||||
$options['resources'] : $this->getLdapResources()
|
||||
'required' => true,
|
||||
'allowEmpty' => false,
|
||||
'label' => t('LDAP resource'),
|
||||
'helptext' => t('The resource to use for authenticating with this provider'),
|
||||
'value' => $this->getBackend()->get('resource'),
|
||||
'multiOptions' => $this->getResources()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -85,10 +100,10 @@ class LdapBackendForm extends BaseBackendForm
|
|||
'text',
|
||||
'backend_' . $name . '_user_class',
|
||||
array(
|
||||
'label' => 'LDAP User Object Class',
|
||||
'value' => $backend->get('user_class', 'inetOrgPerson'),
|
||||
'helptext' => 'The object class used for storing users on the ldap server',
|
||||
'required' => true
|
||||
'required' => true,
|
||||
'label' => t('LDAP User Object Class'),
|
||||
'helptext' => t('The object class used for storing users on the ldap server'),
|
||||
'value' => $backend->get('user_class', 'inetOrgPerson')
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -96,10 +111,10 @@ class LdapBackendForm extends BaseBackendForm
|
|||
'text',
|
||||
'backend_' . $name . '_user_name_attribute',
|
||||
array(
|
||||
'label' => 'LDAP User Name Attribute',
|
||||
'value' => $backend->get('user_name_attribute', 'uid'),
|
||||
'helptext' => 'The attribute name used for storing the user name on the ldap server',
|
||||
'required' => true
|
||||
'required' => true,
|
||||
'label' => t('LDAP User Name Attribute'),
|
||||
'helptext' => t('The attribute name used for storing the user name on the ldap server'),
|
||||
'value' => $backend->get('user_name_attribute', 'uid')
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -125,52 +140,41 @@ class LdapBackendForm extends BaseBackendForm
|
|||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
$name = $this->getBackendName();
|
||||
$prefix = 'backend_' . $this->filterName($name) . '_';
|
||||
|
||||
$prefix = 'backend_' . $this->filterName($this->getBackendName()) . '_';
|
||||
$section = $this->getValue($prefix . 'name');
|
||||
$cfg = array(
|
||||
'target' => 'user',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
'user_class' => $this->getValue($prefix . 'user_class'),
|
||||
'user_name_attribute' => $this->getValue($prefix . 'user_name_attribute')
|
||||
);
|
||||
return array(
|
||||
$section => $cfg
|
||||
'backend' => 'ldap',
|
||||
'resource' => $this->getValue($prefix . 'resource'),
|
||||
'user_class' => $this->getValue($prefix . 'user_class'),
|
||||
'user_name_attribute' => $this->getValue($prefix . 'user_name_attribute')
|
||||
);
|
||||
|
||||
return array($section => $cfg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the current configuration by creating a backend and requesting the user count
|
||||
*
|
||||
* @return bool True when the backend is valid, false otherwise
|
||||
* @return bool Whether validation succeeded or not
|
||||
*
|
||||
* @see BaseBackendForm::isValidAuthenticationBacken
|
||||
*/
|
||||
public function isValidAuthenticationBackend()
|
||||
{
|
||||
try {
|
||||
$cfg = $this->getConfig();
|
||||
$backendName = 'backend_' . $this->filterName($this->getBackendName()) . '_name';
|
||||
$backendConfig = new Zend_Config($cfg[$this->getValue($backendName)]);
|
||||
$testConn = new LdapUserBackend($backendConfig);
|
||||
if ($testConn->getUserCount() === 0) {
|
||||
throw new Exception('No Users Found On Directory Server');
|
||||
$backendName = key($cfg);
|
||||
$testConn = UserBackend::create($backendName, new Zend_Config($cfg[$backendName]));
|
||||
|
||||
if ($testConn->count() === 0) {
|
||||
$this->addErrorMessage(t('No users found on directory server'));
|
||||
return false;
|
||||
}
|
||||
} catch (Exception $exc) {
|
||||
$this->addErrorMessage(
|
||||
'Connection Validation Failed:' . $exc->getMessage()
|
||||
);
|
||||
$this->addErrorMessage(sprintf(t('Connection validation failed: %s'), $exc->getMessage()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function getLdapResources()
|
||||
{
|
||||
$res = ResourceFactory::getResourceConfigs('ldap')->toArray();
|
||||
foreach ($res as $key => $value) {
|
||||
$res[$key] = $key;
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,10 @@
|
|||
namespace Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Zend_Config;
|
||||
use \Icinga\Web\Form;
|
||||
use \Icinga\Web\Url;
|
||||
use Icinga\Web\Form;
|
||||
|
||||
/**
|
||||
* Form for modifying the authentication provider order.
|
||||
*
|
||||
* Form for modifying the authentication provider order
|
||||
*/
|
||||
class ReorderForm extends Form
|
||||
{
|
||||
|
@ -44,19 +42,20 @@ class ReorderForm extends Form
|
|||
*
|
||||
* @var string
|
||||
*/
|
||||
private $backend = null;
|
||||
protected $backend;
|
||||
|
||||
/**
|
||||
* The current ordering of all backends, required to determine possible changes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $currentOrder = array();
|
||||
protected $currentOrder = array();
|
||||
|
||||
/**
|
||||
* Set an array with the current order of all backends
|
||||
*
|
||||
* @param array $order An array containing backend names in the order they are defined in the authentication.ini
|
||||
* @param array $order An array containing backend names in the order
|
||||
* they are defined in the authentication.ini
|
||||
*/
|
||||
public function setCurrentOrder(array $order)
|
||||
{
|
||||
|
@ -66,20 +65,17 @@ class ReorderForm extends Form
|
|||
/**
|
||||
* Set the name of the authentication backend for which to create the form
|
||||
*
|
||||
* @param string $backend The name of the authentication backend
|
||||
* @param string $backend The name of the authentication backend
|
||||
*/
|
||||
public function setAuthenticationBackend($backend)
|
||||
public function setBackendName($backend)
|
||||
{
|
||||
$this->backend = $backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the currently set backend as it will appear in the forms
|
||||
* Return the name of the currently set backend as it will appear in the form
|
||||
*
|
||||
* This calls the Zend Filtername function in order to filter specific chars
|
||||
*
|
||||
* @return string The filtered name of the backend
|
||||
* @see Form::filterName()
|
||||
* @return string The name of the backend
|
||||
*/
|
||||
public function getBackendName()
|
||||
{
|
||||
|
@ -87,28 +83,24 @@ class ReorderForm extends Form
|
|||
}
|
||||
|
||||
/**
|
||||
* Create this form.
|
||||
*
|
||||
* Note: The form action will be set here to the authentication overview
|
||||
* Create this form
|
||||
*
|
||||
* @see Form::create
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->upForm = new Form();
|
||||
$this->downForm = new Form();
|
||||
|
||||
if ($this->moveElementUp($this->backend, $this->currentOrder) !== $this->currentOrder) {
|
||||
$upForm = new Form();
|
||||
|
||||
$this->upForm->addElement(
|
||||
$upForm->addElement(
|
||||
'hidden',
|
||||
'form_backend_order',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => join(',', $this->moveElementUp($this->backend, $this->currentOrder))
|
||||
'value' => join(',', $this->moveElementUp($this->backend, $this->currentOrder))
|
||||
)
|
||||
);
|
||||
$this->upForm->addElement(
|
||||
$upForm->addElement(
|
||||
'button',
|
||||
'btn_' . $this->getBackendName() . '_reorder_up',
|
||||
array(
|
||||
|
@ -116,21 +108,25 @@ class ReorderForm extends Form
|
|||
'escape' => false,
|
||||
'value' => 'btn_' . $this->getBackendName() . '_reorder_up',
|
||||
'name' => 'btn_' . $this->getBackendName() . '_reorder_up',
|
||||
'label' => $this->getView()->icon('up.png', 'Move up in authentication order'),
|
||||
'label' => $this->getView()->icon('up.png', t('Move up in authentication order'))
|
||||
)
|
||||
);
|
||||
|
||||
$this->addSubForm($upForm, 'btn_reorder_up');
|
||||
}
|
||||
|
||||
if ($this->moveElementDown($this->backend, $this->currentOrder) !== $this->currentOrder) {
|
||||
$this->downForm->addElement(
|
||||
$downForm = new Form();
|
||||
|
||||
$downForm->addElement(
|
||||
'hidden',
|
||||
'form_backend_order',
|
||||
array(
|
||||
'required' => true,
|
||||
'value' => join(',', $this->moveElementDown($this->backend, $this->currentOrder))
|
||||
'value' => join(',', $this->moveElementDown($this->backend, $this->currentOrder))
|
||||
)
|
||||
);
|
||||
$this->downForm->addElement(
|
||||
$downForm->addElement(
|
||||
'button',
|
||||
'btn_' . $this->getBackendName() . '_reorder_down',
|
||||
array(
|
||||
|
@ -138,72 +134,68 @@ class ReorderForm extends Form
|
|||
'escape' => false,
|
||||
'value' => 'btn_' . $this->getBackendName() . '_reorder_down',
|
||||
'name' => 'btn_' . $this->getBackendName() . '_reorder_down',
|
||||
'label' => $this->getView()->icon('down.png', 'Move down in authentication order'),
|
||||
|
||||
'label' => $this->getView()->icon('down.png', t('Move down in authentication order'))
|
||||
)
|
||||
);
|
||||
|
||||
$this->addSubForm($downForm, 'btn_reorder_down');
|
||||
}
|
||||
$this->setAction(Url::fromPath("config/authentication", array())->getAbsoluteUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result of $this->getValues but flatten the result
|
||||
* Return the flattened result of $this->getValues
|
||||
*
|
||||
* The result will be a key=>value array without subarrays
|
||||
* @return array The currently set values
|
||||
*
|
||||
* @param bool $supressArrayNotation passed to getValues
|
||||
*
|
||||
* @return array The currently set values
|
||||
* @see Form::getValues()
|
||||
*/
|
||||
public function getFlattenedValues($supressArrayNotation = false)
|
||||
protected function getFlattenedValues()
|
||||
{
|
||||
$values = parent::getValues($supressArrayNotation);
|
||||
$result = array();
|
||||
foreach ($values as $key => &$value) {
|
||||
foreach (parent::getValues() as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$result += $value;
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether this form is submitted by testing the submit buttons of both subforms
|
||||
*
|
||||
* @return bool True when the form is submitted, otherwise false
|
||||
* @return bool Whether the form has been submitted or not
|
||||
*/
|
||||
public function isSubmitted()
|
||||
{
|
||||
$checkData = $this->getRequest()->getParams();
|
||||
return isset ($checkData['btn_' . $this->getBackendName() . '_reorder_up']) ||
|
||||
isset ($checkData['btn_' . $this->getBackendName() . '_reorder_down']);
|
||||
return isset($checkData['btn_' . $this->getBackendName() . '_reorder_up']) ||
|
||||
isset($checkData['btn_' . $this->getBackendName() . '_reorder_down']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the reordered configuration after a reorder button has been submited
|
||||
* Return the reordered configuration after a reorder button has been submitted
|
||||
*
|
||||
* @param Zend_Config $config The configuration to reorder
|
||||
* @param Zend_Config $config The configuration to reorder
|
||||
*
|
||||
* @return array An array containing the reordered configuration
|
||||
* @return array An array containing the reordered configuration
|
||||
*/
|
||||
public function getReorderedConfig(Zend_Config $config)
|
||||
{
|
||||
$originalConfig = $config->toArray();
|
||||
$reordered = array();
|
||||
$newOrder = $this->getFlattenedValues();
|
||||
$order = explode(',', $newOrder['form_backend_order']);
|
||||
|
||||
$reordered = array();
|
||||
foreach ($order as $key) {
|
||||
if (!isset($originalConfig[$key])) {
|
||||
continue;
|
||||
if (isset($originalConfig[$key])) {
|
||||
$reordered[$key] = $originalConfig[$key];
|
||||
}
|
||||
$reordered[$key] = $originalConfig[$key];
|
||||
}
|
||||
|
||||
return $reordered;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,28 +208,27 @@ class ReorderForm extends Form
|
|||
* moveElementUp('third', $array); // returns ['first', 'third', 'second']
|
||||
* </pre>
|
||||
*
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
*
|
||||
* @return array The modified array
|
||||
* @return array The modified array
|
||||
*/
|
||||
private static function moveElementUp($key, array $array)
|
||||
protected static function moveElementUp($key, array $array)
|
||||
{
|
||||
$swap = null;
|
||||
for ($i=0; $i<count($array)-1; $i++) {
|
||||
if ($array[$i+1] !== $key) {
|
||||
continue;
|
||||
for ($i = 0; $i < count($array) - 1; $i++) {
|
||||
if ($array[$i + 1] === $key) {
|
||||
$swap = $array[$i];
|
||||
$array[$i] = $array[$i + 1];
|
||||
$array[$i + 1] = $swap;
|
||||
return $array;
|
||||
}
|
||||
$swap = $array[$i];
|
||||
$array[$i] = $array[$i+1];
|
||||
$array[$i+1] = $swap;
|
||||
return $array;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Static helper for moving an element in an array one slot up, if possible
|
||||
* Static helper for moving an element in an array one slot down, if possible
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
|
@ -246,23 +237,22 @@ class ReorderForm extends Form
|
|||
* moveElementDown('first', $array); // returns ['second', 'first', 'third']
|
||||
* </pre>
|
||||
*
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
* @param string $key The key to bubble up one slot
|
||||
* @param array $array The array to work with
|
||||
*
|
||||
* @return array The modified array
|
||||
* @return array The modified array
|
||||
*/
|
||||
private static function moveElementDown($key, array $array)
|
||||
protected static function moveElementDown($key, array $array)
|
||||
{
|
||||
$swap = null;
|
||||
for ($i=0; $i<count($array)-1; $i++) {
|
||||
if ($array[$i] !== $key) {
|
||||
continue;
|
||||
for ($i = 0; $i < count($array) - 1; $i++) {
|
||||
if ($array[$i] === $key) {
|
||||
$swap = $array[$i + 1];
|
||||
$array[$i + 1] = $array[$i];
|
||||
$array[$i] = $swap;
|
||||
return $array;
|
||||
}
|
||||
$swap = $array[$i+1];
|
||||
$array[$i+1] = $array[$i];
|
||||
$array[$i] = $swap;
|
||||
return $array;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,384 @@
|
|||
./modules/doc/application/controllers/IndexController.php
|
||||
./modules/doc/application/controllers/ModuleController.php
|
||||
./modules/doc/library/Doc/DocParser.php
|
||||
./modules/doc/library/Doc/Controller.php
|
||||
./modules/doc/library/Doc/DocException.php
|
||||
./modules/doc/library/Doc/MarkdownFileIterator.php
|
||||
./modules/translation/application/clicommands/CompileCommand.php
|
||||
./modules/translation/application/clicommands/RefreshCommand.php
|
||||
./modules/translation/library/Translation/Cli/TranslationCommand.php
|
||||
./modules/translation/library/Translation/Util/GettextTranslationHelper.php
|
||||
./modules/monitoring/application/forms/Config/Backend/EditBackendForm.php
|
||||
./modules/monitoring/application/forms/Config/Backend/CreateBackendForm.php
|
||||
./modules/monitoring/application/forms/Config/ConfirmRemovalForm.php
|
||||
./modules/monitoring/application/forms/Config/Instance/CreateInstanceForm.php
|
||||
./modules/monitoring/application/forms/Config/Instance/EditInstanceForm.php
|
||||
./modules/monitoring/application/forms/Command/DelayNotificationForm.php
|
||||
./modules/monitoring/application/forms/Command/SubmitPassiveCheckResultForm.php
|
||||
./modules/monitoring/application/forms/Command/CommandForm.php
|
||||
./modules/monitoring/application/forms/Command/WithChildrenCommandForm.php
|
||||
./modules/monitoring/application/forms/Command/CustomNotificationForm.php
|
||||
./modules/monitoring/application/forms/Command/AcknowledgeForm.php
|
||||
./modules/monitoring/application/forms/Command/CommentForm.php
|
||||
./modules/monitoring/application/forms/Command/MultiCommandFlagForm.php
|
||||
./modules/monitoring/application/forms/Command/RescheduleNextCheckForm.php
|
||||
./modules/monitoring/application/forms/Command/ScheduleDowntimeForm.php
|
||||
./modules/monitoring/application/forms/Command/SingleArgumentCommandForm.php
|
||||
./modules/monitoring/application/forms/Command/DisableNotificationWithExpireForm.php
|
||||
./modules/monitoring/application/views/helpers/MonitoringFlags.php
|
||||
./modules/monitoring/application/views/helpers/MonitoringProperties.php
|
||||
./modules/monitoring/application/views/helpers/CommandForm.php
|
||||
./modules/monitoring/application/views/helpers/RuntimeVariables.php
|
||||
./modules/monitoring/application/views/helpers/CheckPerformance.php
|
||||
./modules/monitoring/application/views/helpers/PluginOutput.php
|
||||
./modules/monitoring/application/views/helpers/Perfdata.php
|
||||
./modules/monitoring/application/views/helpers/_RenderServicePerfdata.php
|
||||
./modules/monitoring/application/views/helpers/SelectionToolbar.php
|
||||
./modules/monitoring/application/views/helpers/ContactFlags.php
|
||||
./modules/monitoring/application/views/helpers/ResolveMacros.php
|
||||
./modules/monitoring/application/views/helpers/MonitoringState.php
|
||||
./modules/monitoring/application/views/helpers/ResolveComments.php
|
||||
./modules/monitoring/application/clicommands/NrpeCommand.php
|
||||
./modules/monitoring/application/clicommands/ConferenceCommand.php
|
||||
./modules/monitoring/application/clicommands/ListCommand.php
|
||||
./modules/monitoring/application/controllers/ShowController.php
|
||||
./modules/monitoring/application/controllers/ConfigController.php
|
||||
./modules/monitoring/application/controllers/MultiController.php
|
||||
./modules/monitoring/application/controllers/ListController.php
|
||||
./modules/monitoring/application/controllers/CommandController.php
|
||||
./modules/monitoring/application/controllers/MonitoringCommands.php
|
||||
./modules/monitoring/application/controllers/ChartController.php
|
||||
./modules/monitoring/application/controllers/TimelineController.php
|
||||
./modules/monitoring/application/controllers/TacticalController.php
|
||||
./modules/monitoring/application/controllers/ProcessController.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Contactgroup.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Notification.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Comment.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Customvar.php
|
||||
./modules/monitoring/library/Monitoring/DataView/EventHistory.php
|
||||
./modules/monitoring/library/Monitoring/DataView/StatusSummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/DataView.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Runtimesummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Servicegroup.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Runtimevariables.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Contact.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Programstatus.php
|
||||
./modules/monitoring/library/Monitoring/DataView/StateHistorySummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Downtime.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Groupsummary.php
|
||||
./modules/monitoring/library/Monitoring/DataView/Hostgroup.php
|
||||
./modules/monitoring/library/Monitoring/DataView/HostStatus.php
|
||||
./modules/monitoring/library/Monitoring/DataView/ServiceStatus.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusdatQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ContactgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicegroupsummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/CommentQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/DowntimeQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusSummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/GroupsummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ContactQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicegroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/HostlistQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/StatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Statusdat/Query/ServicelistQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Livestatus/Query/StatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationhistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/CustomvarQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeendhistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/HostgroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/CommentQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimeQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StatehistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ProgramstatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/EventHistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusSummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/GroupsummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/HoststatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/RuntimevariablesQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/CommenthistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ContactQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StateHistorySummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/ServicegroupQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/AllcontactsQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/DowntimestarthistoryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/RuntimesummaryQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/StatusQuery.php
|
||||
./modules/monitoring/library/Monitoring/Backend/Ido/Query/NotificationQuery.php
|
||||
./modules/monitoring/library/Monitoring/Environment.php
|
||||
./modules/monitoring/library/Monitoring/Controller.php
|
||||
./modules/monitoring/library/Monitoring/Timeline/TimeEntry.php
|
||||
./modules/monitoring/library/Monitoring/Timeline/TimeRange.php
|
||||
./modules/monitoring/library/Monitoring/Timeline/TimeLine.php
|
||||
./modules/monitoring/library/Monitoring/Object/Service.php
|
||||
./modules/monitoring/library/Monitoring/Object/Host.php
|
||||
./modules/monitoring/library/Monitoring/Object/AbstractObject.php
|
||||
./modules/monitoring/library/Monitoring/Filter/Type/StatusFilter.php
|
||||
./modules/monitoring/library/Monitoring/Filter/Registry.php
|
||||
./modules/monitoring/library/Monitoring/Filter/UrlViewFilter.php
|
||||
./modules/monitoring/library/Monitoring/Exception/UnsupportedBackendException.php
|
||||
./modules/monitoring/library/Monitoring/Web/Widget/TimelineIntervalBox.php
|
||||
./modules/monitoring/library/Monitoring/Web/Hook/TimelineProvider.php
|
||||
./modules/monitoring/library/Monitoring/Web/Hook/TopBar.php
|
||||
./modules/monitoring/library/Monitoring/Command/SubmitPassiveCheckresultCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/AcknowledgeCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/ScheduleDowntimeCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/ScheduleCheckCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/DisableNotificationWithExpireCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/SingleArgumentCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/AddCommentCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/CustomNotificationCommand.php
|
||||
./modules/monitoring/library/Monitoring/Command/DelayNotificationCommand.php
|
||||
./modules/monitoring/library/Monitoring/Plugin.php
|
||||
./modules/monitoring/library/Monitoring/Cli/CliUtils.php
|
||||
./modules/monitoring/library/Monitoring/Backend.php
|
||||
./modules/monitoring/library/Monitoring/Plugin/Perfdata.php
|
||||
./modules/monitoring/library/Monitoring/Plugin/PerfdataSet.php
|
||||
./modules/monitoring/run.php
|
||||
./modules/monitoring/configuration.php
|
||||
./modules/monitoring/bin/action/list.inc.php
|
||||
./etc/module_skeleton/application/controllers/IndexController.php
|
||||
./application/forms/Authentication/LoginForm.php
|
||||
./application/forms/Config/GeneralForm.php
|
||||
./application/forms/Config/Authentication/LdapBackendForm.php
|
||||
./application/forms/Config/Authentication/ReorderForm.php
|
||||
./application/forms/Config/Authentication/BaseBackendForm.php
|
||||
./application/forms/Config/Authentication/DbBackendForm.php
|
||||
./application/forms/Config/LoggingForm.php
|
||||
./application/forms/Config/ConfirmRemovalForm.php
|
||||
./application/forms/Config/Resource/CreateResourceForm.php
|
||||
./application/forms/Config/Resource/EditResourceForm.php
|
||||
./application/forms/TestForm.php
|
||||
./application/forms/Dashboard/AddUrlForm.php
|
||||
./application/forms/Preference/GeneralForm.php
|
||||
./application/views/helpers/FormNumber.php
|
||||
./application/views/helpers/DateFormat.php
|
||||
./application/views/helpers/FormDateTime.php
|
||||
./application/views/helpers/FormTriStateCheckbox.php
|
||||
./application/views/helpers/Util.php
|
||||
./application/clicommands/HelpCommand.php
|
||||
./application/clicommands/ModuleCommand.php
|
||||
./application/clicommands/AutocompleteCommand.php
|
||||
./application/clicommands/WebCommand.php
|
||||
./application/controllers/ConfigController.php
|
||||
./application/controllers/ListController.php
|
||||
./application/controllers/IndexController.php
|
||||
./application/controllers/LayoutController.php
|
||||
./application/controllers/PreferenceController.php
|
||||
./application/controllers/DashboardController.php
|
||||
./application/controllers/FilterController.php
|
||||
./application/controllers/StaticController.php
|
||||
./application/controllers/SearchController.php
|
||||
./application/controllers/ErrorController.php
|
||||
./application/controllers/AuthenticationController.php
|
||||
./library/Icinga/Logger/Logger.php
|
||||
./library/Icinga/Logger/Writer/StreamWriter.php
|
||||
./library/Icinga/Logger/Writer/SyslogWriter.php
|
||||
./library/Icinga/Logger/LogWriter.php
|
||||
./library/Icinga/User/Preferences.php
|
||||
./library/Icinga/User/Message.php
|
||||
./library/Icinga/User/Preferences/Store/IniStore.php
|
||||
./library/Icinga/User/Preferences/Store/DbStore.php
|
||||
./library/Icinga/User/Preferences/PreferencesStore.php
|
||||
./library/Icinga/Authentication/UserBackend.php
|
||||
./library/Icinga/Authentication/Backend/DbUserBackend.php
|
||||
./library/Icinga/Authentication/Backend/LdapUserBackend.php
|
||||
./library/Icinga/Authentication/Membership.php
|
||||
./library/Icinga/Authentication/Manager.php
|
||||
./library/Icinga/Authentication/AdmissionLoader.php
|
||||
./library/Icinga/Authentication/AuthChain.php
|
||||
./library/Icinga/Data/Db/Query.php
|
||||
./library/Icinga/Data/Db/TreeToSqlParser.php
|
||||
./library/Icinga/Data/Db/Connection.php
|
||||
./library/Icinga/Data/PivotTable.php
|
||||
./library/Icinga/Data/DatasourceInterface.php
|
||||
./library/Icinga/Data/DataArray/Query.php
|
||||
./library/Icinga/Data/DataArray/Datasource.php
|
||||
./library/Icinga/Data/ResourceFactory.php
|
||||
./library/Icinga/Data/BaseQuery.php
|
||||
./library/Icinga/File/Pdf.php
|
||||
./library/Icinga/File/Csv.php
|
||||
./library/Icinga/File/Csv/Query.php
|
||||
./library/Icinga/Test/DbTest.php
|
||||
./library/Icinga/Test/BaseTestCase.php
|
||||
./library/Icinga/Test/FormTest.php
|
||||
./library/Icinga/Protocol/Ldap/Root.php
|
||||
./library/Icinga/Protocol/Ldap/Query.php
|
||||
./library/Icinga/Protocol/Ldap/Exception.php
|
||||
./library/Icinga/Protocol/Ldap/LdapUtils.php
|
||||
./library/Icinga/Protocol/Ldap/Node.php
|
||||
./library/Icinga/Protocol/Ldap/Connection.php
|
||||
./library/Icinga/Protocol/File/Query.php
|
||||
./library/Icinga/Protocol/File/Reader.php
|
||||
./library/Icinga/Protocol/Statusdat/Parser.php
|
||||
./library/Icinga/Protocol/Statusdat/Query.php
|
||||
./library/Icinga/Protocol/Statusdat/Query/IQueryPart.php
|
||||
./library/Icinga/Protocol/Statusdat/Query/Group.php
|
||||
./library/Icinga/Protocol/Statusdat/Query/Expression.php
|
||||
./library/Icinga/Protocol/Statusdat/View/AccessorStrategy.php
|
||||
./library/Icinga/Protocol/Statusdat/View/MonitoringObjectList.php
|
||||
./library/Icinga/Protocol/Statusdat/ObjectContainer.php
|
||||
./library/Icinga/Protocol/Statusdat/Exception/ParsingException.php
|
||||
./library/Icinga/Protocol/Statusdat/Reader.php
|
||||
./library/Icinga/Protocol/Statusdat/IReader.php
|
||||
./library/Icinga/Protocol/Statusdat/PrintableObject.php
|
||||
./library/Icinga/Protocol/Statusdat/TreeToStatusdatQueryParser.php
|
||||
./library/Icinga/Protocol/Statusdat/RuntimeStateContainer.php
|
||||
./library/Icinga/Protocol/Nrpe/Packet.php
|
||||
./library/Icinga/Protocol/Nrpe/Connection.php
|
||||
./library/Icinga/Protocol/Livestatus/Query.php
|
||||
./library/Icinga/Protocol/Livestatus/Connection.php
|
||||
./library/Icinga/Protocol/Commandpipe/Transport/Transport.php
|
||||
./library/Icinga/Protocol/Commandpipe/Transport/LocalPipe.php
|
||||
./library/Icinga/Protocol/Commandpipe/Transport/SecureShell.php
|
||||
./library/Icinga/Protocol/Commandpipe/Comment.php
|
||||
./library/Icinga/Protocol/Commandpipe/Exception/InvalidCommandException.php
|
||||
./library/Icinga/Protocol/Commandpipe/PropertyModifier.php
|
||||
./library/Icinga/Protocol/Commandpipe/Command.php
|
||||
./library/Icinga/Protocol/Commandpipe/CommandPipe.php
|
||||
./library/Icinga/Application/Platform.php
|
||||
./library/Icinga/Application/Benchmark.php
|
||||
./library/Icinga/Application/functions.php
|
||||
./library/Icinga/Application/LegacyWeb.php
|
||||
./library/Icinga/Application/Config.php
|
||||
./library/Icinga/Application/EmbeddedWeb.php
|
||||
./library/Icinga/Application/ApplicationBootstrap.php
|
||||
./library/Icinga/Application/Cli.php
|
||||
./library/Icinga/Application/webrouter.php
|
||||
./library/Icinga/Application/Modules/Module.php
|
||||
./library/Icinga/Application/Modules/Manager.php
|
||||
./library/Icinga/Application/Loader.php
|
||||
./library/Icinga/Application/Icinga.php
|
||||
./library/Icinga/Application/Web.php
|
||||
./library/Icinga/Chart/Primitive/Animation.php
|
||||
./library/Icinga/Chart/Primitive/Text.php
|
||||
./library/Icinga/Chart/Primitive/Animatable.php
|
||||
./library/Icinga/Chart/Primitive/Drawable.php
|
||||
./library/Icinga/Chart/Primitive/Circle.php
|
||||
./library/Icinga/Chart/Primitive/Styleable.php
|
||||
./library/Icinga/Chart/Primitive/RawElement.php
|
||||
./library/Icinga/Chart/Primitive/Rect.php
|
||||
./library/Icinga/Chart/Primitive/Line.php
|
||||
./library/Icinga/Chart/Primitive/Canvas.php
|
||||
./library/Icinga/Chart/Primitive/PieSlice.php
|
||||
./library/Icinga/Chart/Primitive/Path.php
|
||||
./library/Icinga/Chart/Graph/LineGraph.php
|
||||
./library/Icinga/Chart/Graph/StackedGraph.php
|
||||
./library/Icinga/Chart/Graph/BarGraph.php
|
||||
./library/Icinga/Chart/Axis.php
|
||||
./library/Icinga/Chart/Palette.php
|
||||
./library/Icinga/Chart/Unit/AxisUnit.php
|
||||
./library/Icinga/Chart/Unit/LinearUnit.php
|
||||
./library/Icinga/Chart/Unit/StaticAxis.php
|
||||
./library/Icinga/Chart/Unit/CalendarUnit.php
|
||||
./library/Icinga/Chart/PieChart.php
|
||||
./library/Icinga/Chart/GridChart.php
|
||||
./library/Icinga/Chart/SVGRenderer.php
|
||||
./library/Icinga/Chart/Legend.php
|
||||
./library/Icinga/Chart/Inline/PieChart.php
|
||||
./library/Icinga/Chart/Inline/Inline.php
|
||||
./library/Icinga/Chart/Chart.php
|
||||
./library/Icinga/Chart/Render/RenderContext.php
|
||||
./library/Icinga/Chart/Render/LayoutBox.php
|
||||
./library/Icinga/Config/IniEditor.php
|
||||
./library/Icinga/Config/PreservingIniWriter.php
|
||||
./library/Icinga/User.php
|
||||
./library/Icinga/Filter/Query/Tree.php
|
||||
./library/Icinga/Filter/Query/Node.php
|
||||
./library/Icinga/Filter/FilterAttribute.php
|
||||
./library/Icinga/Filter/Type/FilterType.php
|
||||
./library/Icinga/Filter/Type/BooleanFilter.php
|
||||
./library/Icinga/Filter/Type/TextFilter.php
|
||||
./library/Icinga/Filter/Type/TimeRangeSpecifier.php
|
||||
./library/Icinga/Filter/QueryProposer.php
|
||||
./library/Icinga/Filter/Registry.php
|
||||
./library/Icinga/Filter/Filter.php
|
||||
./library/Icinga/Filter/Filterable.php
|
||||
./library/Icinga/Filter/Domain.php
|
||||
./library/Icinga/Exception/NotWritableError.php
|
||||
./library/Icinga/Exception/MissingParameterException.php
|
||||
./library/Icinga/Exception/NotImplementedError.php
|
||||
./library/Icinga/Exception/ConfigurationError.php
|
||||
./library/Icinga/Exception/NotReadableError.php
|
||||
./library/Icinga/Exception/SystemPermissionException.php
|
||||
./library/Icinga/Exception/ProgrammingError.php
|
||||
./library/Icinga/Web/JavaScript.php
|
||||
./library/Icinga/Web/Notification.php
|
||||
./library/Icinga/Web/MenuItem.php
|
||||
./library/Icinga/Web/Widget/Dashboard.php
|
||||
./library/Icinga/Web/Widget/FilterBox.php
|
||||
./library/Icinga/Web/Widget/AlertMessageBox.php
|
||||
./library/Icinga/Web/Widget/Tabextension/DashboardAction.php
|
||||
./library/Icinga/Web/Widget/Tabextension/BasketAction.php
|
||||
./library/Icinga/Web/Widget/Tabextension/Tabextension.php
|
||||
./library/Icinga/Web/Widget/Tabextension/OutputFormat.php
|
||||
./library/Icinga/Web/Widget/Chart/InlinePie.php
|
||||
./library/Icinga/Web/Widget/Chart/HistoryColorGrid.php
|
||||
./library/Icinga/Web/Widget/AbstractWidget.php
|
||||
./library/Icinga/Web/Widget/FilterBadgeRenderer.php
|
||||
./library/Icinga/Web/Widget/Dashboard/Component.php
|
||||
./library/Icinga/Web/Widget/Dashboard/Pane.php
|
||||
./library/Icinga/Web/Widget/Tabs.php
|
||||
./library/Icinga/Web/Widget/Tab.php
|
||||
./library/Icinga/Web/Widget/Widget.php
|
||||
./library/Icinga/Web/Widget/SortBox.php
|
||||
./library/Icinga/Web/Hook.php
|
||||
./library/Icinga/Web/View/helpers/generic.php
|
||||
./library/Icinga/Web/View/helpers/url.php
|
||||
./library/Icinga/Web/View/helpers/format.php
|
||||
./library/Icinga/Web/Menu.php
|
||||
./library/Icinga/Web/Session.php
|
||||
./library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php
|
||||
./library/Icinga/Web/Paginator/Adapter/QueryAdapter.php
|
||||
./library/Icinga/Web/ViewStream.php
|
||||
./library/Icinga/Web/Url.php
|
||||
./library/Icinga/Web/Session/SessionNamespace.php
|
||||
./library/Icinga/Web/Session/Session.php
|
||||
./library/Icinga/Web/Session/PhpSession.php
|
||||
./library/Icinga/Web/StyleSheet.php
|
||||
./library/Icinga/Web/Hook/Ticket.php
|
||||
./library/Icinga/Web/Hook/Configuration/ConfigurationTabInterface.php
|
||||
./library/Icinga/Web/Hook/Configuration/ConfigurationTab.php
|
||||
./library/Icinga/Web/Hook/Configuration/ConfigurationTabBuilder.php
|
||||
./library/Icinga/Web/Hook/TopBar.php
|
||||
./library/Icinga/Web/Hook/Grapher.php
|
||||
./library/Icinga/Web/Request.php
|
||||
./library/Icinga/Web/View.php
|
||||
./library/Icinga/Web/Widget.php
|
||||
./library/Icinga/Web/Controller/ActionController.php
|
||||
./library/Icinga/Web/Controller/BaseConfigController.php
|
||||
./library/Icinga/Web/Controller/BasePreferenceController.php
|
||||
./library/Icinga/Web/Controller/ControllerTabCollector.php
|
||||
./library/Icinga/Web/LessCompiler.php
|
||||
./library/Icinga/Web/Form.php
|
||||
./library/Icinga/Web/Form/Element/Number.php
|
||||
./library/Icinga/Web/Form/Element/DateTimePicker.php
|
||||
./library/Icinga/Web/Form/Element/TriStateCheckbox.php
|
||||
./library/Icinga/Web/Form/Element/Note.php
|
||||
./library/Icinga/Web/Form/Decorator/ConditionalHidden.php
|
||||
./library/Icinga/Web/Form/Decorator/BootstrapForm.php
|
||||
./library/Icinga/Web/Form/Decorator/HelpText.php
|
||||
./library/Icinga/Web/Form/Validator/DateFormatValidator.php
|
||||
./library/Icinga/Web/Form/Validator/TriStateValidator.php
|
||||
./library/Icinga/Web/Form/Validator/DateTimeValidator.php
|
||||
./library/Icinga/Web/Form/Validator/TimeFormatValidator.php
|
||||
./library/Icinga/Web/Form/Validator/WritablePathValidator.php
|
||||
./library/Icinga/Web/Form/InvalidCSRFTokenException.php
|
||||
./library/Icinga/Cli/Documentation/CommentParser.php
|
||||
./library/Icinga/Cli/Params.php
|
||||
./library/Icinga/Cli/Documentation.php
|
||||
./library/Icinga/Cli/Screen/AnsiScreen.php
|
||||
./library/Icinga/Cli/Loader.php
|
||||
./library/Icinga/Cli/Command.php
|
||||
./library/Icinga/Cli/Screen.php
|
||||
./library/Icinga/Util/File.php
|
||||
./library/Icinga/Util/Dimension.php
|
||||
./library/Icinga/Util/DateTimeFactory.php
|
||||
./library/Icinga/Util/Color.php
|
||||
./library/Icinga/Util/String.php
|
||||
./library/Icinga/Util/Format.php
|
||||
./library/Icinga/Util/ConfigAwareFactory.php
|
||||
./library/Icinga/Util/Translator.php
|
||||
|
|
@ -142,9 +142,4 @@ class ResourceFactory implements ConfigAwareFactory
|
|||
}
|
||||
return $resource;
|
||||
}
|
||||
|
||||
public static function getBackendType($resource)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Form\Config\Authentication;
|
||||
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Form\Config\Authentication\BaseBackendForm;
|
||||
|
||||
class BackendForm extends BaseBackendForm
|
||||
{
|
||||
public $is_valid;
|
||||
|
||||
public function getConfig()
|
||||
{
|
||||
// Need to be declared as being abstract otherwise
|
||||
}
|
||||
|
||||
public function isValidAuthenticationBackend()
|
||||
{
|
||||
return $this->is_valid;
|
||||
}
|
||||
}
|
||||
|
||||
class BaseBackendFormTest extends BaseTestCase
|
||||
{
|
||||
public function testIsForceCreationCheckboxBeingAdded()
|
||||
{
|
||||
$form = new BackendForm();
|
||||
$form->is_valid = false;
|
||||
|
||||
$this->assertFalse($form->isValid(array()));
|
||||
$this->assertNotNull(
|
||||
$form->getElement('backend_force_creation'),
|
||||
'Checkbox to force a backend\'s creation is not being added though the backend is invalid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsForceCreationCheckboxNotBeingAdded()
|
||||
{
|
||||
$form = new BackendForm();
|
||||
$form->is_valid = true;
|
||||
|
||||
$this->assertTrue($form->isValid(array()));
|
||||
$this->assertNull(
|
||||
$form->getElement('backend_force_creation'),
|
||||
'Checkbox to force a backend\'s creation is being added though the backend is valid'
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsTheFormValidIfForceCreationTrue()
|
||||
{
|
||||
$form = new BackendForm();
|
||||
$form->is_valid = false;
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValid(array('backend_force_creation' => 1)),
|
||||
'BaseBackendForm with invalid backend is not valid though force creation is set'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Form\Config\Authentication\DbBackendForm;
|
||||
|
||||
class DbBackendFormTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testValidBackendIsValid()
|
||||
{
|
||||
Mockery::mock('alias:Icinga\Authentication\UserBackend')
|
||||
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing(
|
||||
function () { return Mockery::mock(array('count' => 1)); }
|
||||
);
|
||||
|
||||
$form = new DbBackendForm();
|
||||
$form->setBackendName('test');
|
||||
$form->setResources(array('test_db_backend' => null));
|
||||
$form->create();
|
||||
$form->populate(array('backend_test_resource' => 'test_db_backend'));
|
||||
|
||||
$this->assertTrue(
|
||||
$form->isValidAuthenticationBackend(),
|
||||
'DbBackendForm claims that a valid authentication backend with users is not valid'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testInvalidBackendIsNotValid()
|
||||
{
|
||||
Mockery::mock('alias:Icinga\Authentication\UserBackend')
|
||||
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing(
|
||||
function () { return Mockery::mock(array('count' => 0)); }
|
||||
);
|
||||
|
||||
$form = new DbBackendForm();
|
||||
$form->setBackendName('test');
|
||||
$form->setResources(array('test_db_backend' => null));
|
||||
$form->create();
|
||||
$form->populate(array('backend_test_resource' => 'test_db_backend'));
|
||||
|
||||
$this->assertFalse(
|
||||
$form->isValidAuthenticationBackend(),
|
||||
'DbBackendForm claims that an invalid authentication backend without users is valid'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Mockery;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Form\Config\Authentication\LdapBackendForm;
|
||||
|
||||
class LdapBackendFormTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testValidBackendIsValid()
|
||||
{
|
||||
Mockery::mock('alias:Icinga\Authentication\UserBackend')
|
||||
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing(
|
||||
function () { return Mockery::mock(array('count' => 1)); }
|
||||
);
|
||||
|
||||
$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
|
||||
*/
|
||||
public function testInvalidBackendIsNotValid()
|
||||
{
|
||||
Mockery::mock('alias:Icinga\Authentication\UserBackend')
|
||||
->shouldReceive('create')->with('test', Mockery::type('\Zend_Config'))->andReturnUsing(
|
||||
function () { return Mockery::mock(array('count' => 0)); }
|
||||
);
|
||||
|
||||
$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'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Form\Config\Authentication;
|
||||
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Form\Config\Authentication\ReorderForm;
|
||||
|
||||
class RequestLessReorderForm extends ReorderForm
|
||||
{
|
||||
public $order;
|
||||
|
||||
public function getValues($suppressArrayNotation = false)
|
||||
{
|
||||
return array('form_backend_order' => $this->order);
|
||||
}
|
||||
}
|
||||
|
||||
class ReorderFormTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewMock = Mockery::mock('\Zend_View');
|
||||
$this->viewMock->shouldReceive('icon')->andReturn('');
|
||||
}
|
||||
|
||||
public function testMoveBackendUp()
|
||||
{
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
'test1' => '',
|
||||
'test2' => '',
|
||||
'test3' => ''
|
||||
)
|
||||
);
|
||||
$oldOrder = array_keys($config->toArray());
|
||||
|
||||
$form = new RequestLessReorderForm();
|
||||
$form->setCurrentOrder($oldOrder);
|
||||
$form->setBackendName('test3');
|
||||
$form->setView($this->viewMock);
|
||||
$form->create();
|
||||
|
||||
$form->order = $form->getSubForm('btn_reorder_up')->getElement('form_backend_order')->getValue();
|
||||
$this->assertSame(
|
||||
$form->getReorderedConfig($config),
|
||||
array('test1' => '', 'test3' => '', 'test2' => ''),
|
||||
'Moving elements up with ReorderForm does not seem to properly work'
|
||||
);
|
||||
}
|
||||
|
||||
public function testMoveBackendDown()
|
||||
{
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
'test1' => '',
|
||||
'test2' => '',
|
||||
'test3' => ''
|
||||
)
|
||||
);
|
||||
$oldOrder = array_keys($config->toArray());
|
||||
|
||||
$form = new RequestLessReorderForm();
|
||||
$form->setCurrentOrder($oldOrder);
|
||||
$form->setBackendName('test1');
|
||||
$form->setView($this->viewMock);
|
||||
$form->create();
|
||||
|
||||
$form->order = $form->getSubForm('btn_reorder_down')->getElement('form_backend_order')->getValue();
|
||||
$this->assertSame(
|
||||
$form->getReorderedConfig($config),
|
||||
array('test2' => '', 'test1' => '', 'test3' => ''),
|
||||
'Moving elements down with ReorderForm does not seem to properly work'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,157 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Tests\Icinga\Form\Config;
|
||||
|
||||
use \Mockery;
|
||||
use \Zend_Config;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
|
||||
/**
|
||||
* Test for the authentication provider form
|
||||
*/
|
||||
class AuthenticationFormTest extends BaseTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->viewMock = Mockery::mock('\Zend_View');
|
||||
$this->viewMock->shouldReceive('icon')->andReturn('');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the ldap provider form population from config
|
||||
*/
|
||||
public function testLdapProvider()
|
||||
{
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\LdapBackendForm');
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
'backend' => 'ldap',
|
||||
'target' => 'user',
|
||||
'user_class' => 'testClass',
|
||||
'user_name_attribute' => 'testAttribute'
|
||||
)
|
||||
);
|
||||
$form->setBackendName('testldap');
|
||||
$form->setBackend($config);
|
||||
$form->create(array('resources' => array()));
|
||||
|
||||
// parameters to be hidden
|
||||
$notShown = array('backend', 'target');
|
||||
foreach ($config->toArray() as $name => $value) {
|
||||
if (in_array($name, $notShown)) {
|
||||
continue;
|
||||
}
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$form->getValue('backend_testldap_' . $name),
|
||||
'Asserting the ' . $name . ' parameter to be correctly populated for a ldap authentication form'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the database provider form population from config
|
||||
*/
|
||||
public function testDbProvider()
|
||||
{
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\DbBackendForm');
|
||||
$config = new Zend_Config(
|
||||
array(
|
||||
'backend' => 'db',
|
||||
'target' => 'user',
|
||||
'resource' => 'db_resource'
|
||||
)
|
||||
);
|
||||
$form->setResources(
|
||||
array(
|
||||
'db_resource' => array(
|
||||
'type' => 'db'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$form->setBackendName('test-db');
|
||||
$form->setBackend($config);
|
||||
$form->create();
|
||||
|
||||
// parameters to be hidden
|
||||
$notShown = array('backend', 'target');
|
||||
foreach ($config->toArray() as $name => $value) {
|
||||
if (in_array($name, $notShown)) {
|
||||
continue;
|
||||
}
|
||||
$this->assertEquals(
|
||||
$value,
|
||||
$form->getValue('backend_testdb_' . $name),
|
||||
'Asserting the ' . $name . ' parameter to be correctly populated for a db authentication form'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether order modifications via 'priority' are considered
|
||||
*/
|
||||
public function testModifyOrder()
|
||||
{
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||
$form->setAuthenticationBackend('backend2');
|
||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$this->assertSame(
|
||||
2,
|
||||
count($form->getSubForms()),
|
||||
'Assert that a form for moving backend up and down exists'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$form->upForm->getElement('form_backend_order') !== null,
|
||||
'Assert that a "move backend up" button exists'
|
||||
);
|
||||
$this->assertSame(
|
||||
array('backend2', 'backend1', 'backend3', 'backend4'),
|
||||
explode(',', $form->upForm->getElement('form_backend_order')->getValue()),
|
||||
'Assert the "move backend up" button containing the correct order'
|
||||
);
|
||||
|
||||
$this->assertTrue(
|
||||
$form->downForm->getElement('form_backend_order') !== null,
|
||||
'Assert that a "move backend down" button exists'
|
||||
);
|
||||
$this->assertSame(
|
||||
array('backend1', 'backend3', 'backend2', 'backend4'),
|
||||
explode(',', $form->downForm->getElement('form_backend_order')->getValue()),
|
||||
'Assert the "move backend up" button containing the correct order'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test whether the reorder form doesn't display senseless ordering (like moving the uppermost element up or
|
||||
* the lowermost down)
|
||||
*/
|
||||
public function testInvalidOrderingNotShown()
|
||||
{
|
||||
$form = $this->createForm('Icinga\Form\Config\Authentication\ReorderForm');
|
||||
$form->setAuthenticationBackend('backend1');
|
||||
$form->setCurrentOrder(array('backend1', 'backend2', 'backend3', 'backend4'));
|
||||
$form->setView($this->viewMock);
|
||||
|
||||
$form->create();
|
||||
$this->assertSame(
|
||||
2,
|
||||
count($form->getSubForms()),
|
||||
'Assert that a form for moving backend up and down exists, even when moving up is not possible'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$form->downForm->getElement('form_backend_order') !== null,
|
||||
'Assert that a "move backend down" button exists when moving up is not possible'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$form->upForm->getElement('form_backend_order') === null,
|
||||
'Assert that a "move backend up" button does not exist when moving up is not possible'
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue