/** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testInvalidBackendIsNotValid() { $ldapUserBackendMock = Mockery::mock('overload:Icinga\\Authentication\\User\\LdapUserBackend')->shouldReceive('inspect')->andReturn(self::createInspector(true))->getMock(); $ldapUserBackendMock->shouldReceive('assertAuthenticationPossible')->andThrow(new AuthenticationException()); $this->setUpUserBackendMock($ldapUserBackendMock); // Passing array(null) is required to make Mockery call the constructor... $form = Mockery::mock('Icinga\\Forms\\Config\\UserBackend\\LdapBackendForm[getView]', array(null)); $form->shouldReceive('getView->escape')->with(Mockery::type('string'))->andReturnUsing(function ($s) { return $s; }); $form->setTokenDisabled(); $form->setResources(array('test_ldap_backend')); $form->populate(array('resource' => 'test_ldap_backend')); $this->assertFalse(LdapBackendForm::isValidUserBackend($form), 'LdapBackendForm claims that an invalid user backend without users is valid'); }
/** * Validate the given form data and check whether it's possible to authenticate using the configured backend * * @param array $data The data to validate * * @return bool */ public function isValid($data) { if (false === parent::isValid($data)) { return false; } if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) { $self = clone $this; $self->addElement('text', 'resource', array('value' => $this->getResourceConfig())); if ($this->config['type'] === 'ldap' && false === LdapBackendForm::isValidUserBackend($self)) { $this->addSkipValidationCheckbox(); return false; } } return true; }