integration test to ensure entries without displayname don't cause trouble

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-04-12 10:57:42 +02:00
parent d1a8a909de
commit eaf352b8d1
No known key found for this signature in database
GPG key ID: 7424F1874854DF23
3 changed files with 22 additions and 93 deletions

View file

@ -1,81 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Joas Schilling <coding@schilljs.com>
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OCA\User_LDAP\Tests\Integration\Lib;
use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\Tests\Integration\AbstractIntegrationTest;
require_once __DIR__ . '/../Bootstrap.php';
class IntegrationTestBatchApplyUserAttributes extends AbstractIntegrationTest {
/** @var UserMapping */
protected $mapping;
/**
* prepares the LDAP environment and sets up a test configuration for
* the LDAP backend.
*/
public function init() {
require(__DIR__ . '/../setup-scripts/createExplicitUsers.php');
require(__DIR__ . '/../setup-scripts/createUsersWithoutDisplayName.php');
parent::init();
$this->mapping = new UserMapping(\OC::$server->getDatabaseConnection());
$this->mapping->clear();
$this->access->setUserMapper($this->mapping);
}
/**
* sets up the LDAP configuration to be used for the test
*/
protected function initConnection() {
parent::initConnection();
$this->connection->setConfiguration([
'ldapUserDisplayName' => 'displayname',
]);
}
/**
* indirectly tests whether batchApplyUserAttributes does it job properly,
* when a user without display name is included in the result set from LDAP.
*
* @return bool
*/
protected function case1() {
$result = $this->access->fetchListOfUsers('objectclass=person', 'dn');
// on the original issue, PHP would emit a fatal error
// cannot catch it here, but will render the test as unsuccessful
return is_array($result) && !empty($result);
}
}
/** @var string $host */
/** @var int $port */
/** @var string $adn */
/** @var string $apwd */
/** @var string $bdn */
$test = new IntegrationTestBatchApplyUserAttributes($host, $port, $adn, $apwd, $bdn);
$test->init();
$test->run();

View file

@ -141,17 +141,16 @@ class LDAPContext implements Context {
}
/**
* @Given /^the group result should$/
* @Given /^the "([^"]*)" result should match$/
*/
public function theGroupResultShould(TableNode $expectations) {
$listReturnedGroups = simplexml_load_string($this->response->getBody())->data[0]->groups[0]->element;
$extractedGroupsArray = json_decode(json_encode($listReturnedGroups), 1);
foreach($expectations->getRows() as $groupExpectation) {
if((int)$groupExpectation[1] === 1) {
PHPUnit_Framework_Assert::assertContains($groupExpectation[0], $extractedGroupsArray);
public function theGroupResultShouldMatch(string $type, TableNode $expectations) {
$listReturnedElements = simplexml_load_string($this->response->getBody())->data[0]->$type[0]->element;
$extractedIDsArray = json_decode(json_encode($listReturnedElements), 1);
foreach($expectations->getRows() as $expectation) {
if((int)$expectation[1] === 1) {
PHPUnit_Framework_Assert::assertContains($expectation[0], $extractedIDsArray);
} else {
PHPUnit_Framework_Assert::assertNotContains($groupExpectation[0], $extractedGroupsArray);
PHPUnit_Framework_Assert::assertNotContains($expectation[0], $extractedIDsArray);
}
}
}

View file

@ -17,6 +17,17 @@ Feature: LDAP
| email | alice@nextcloud.ci |
| displayname | Alice |
Scenario: Look for a expected LDAP users
Given having a valid LDAP configuration
And modify LDAP configuration
| ldapExpertUsernameAttr | uid |
And As an "admin"
And sending "GET" to "/cloud/users"
Then the OCS status code should be "200"
And the "users" result should match
| alice | 1 |
| ghost | 0 |
Scenario: Test group filter with one specific group
Given having a valid LDAP configuration
And modify LDAP configuration
@ -25,7 +36,7 @@ Feature: LDAP
And As an "admin"
And sending "GET" to "/cloud/groups"
Then the OCS status code should be "200"
And the group result should
And the "groups" result should match
| RedGroup | 1 |
| GreenGroup | 0 |
| BlueGroup | 0 |
@ -39,7 +50,7 @@ Feature: LDAP
And As an "admin"
And sending "GET" to "/cloud/groups"
Then the OCS status code should be "200"
And the group result should
And the "groups" result should match
| RedGroup | 1 |
| GreenGroup | 1 |
| BlueGroup | 0 |
@ -53,7 +64,7 @@ Feature: LDAP
And As an "admin"
And sending "GET" to "/cloud/groups"
Then the OCS status code should be "200"
And the group result should
And the "groups" result should match
| RedGroup | 1 |
| GreenGroup | 1 |
| BlueGroup | 1 |