Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Apr 17, 2020
1 parent ab550d6 commit a530f6d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
25 changes: 16 additions & 9 deletions apps/user_ldap/lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public function __construct(IConfig $config) {

/**
* returns prefixes for each saved LDAP/AD server configuration.
*
* @param bool $activeConfigurations optional, whether only active configuration shall be
* retrieved, defaults to false
* @return array with a list of the available prefixes
Expand Down Expand Up @@ -97,6 +98,7 @@ public function getServerConfigurationPrefixes($activeConfigurations = false) {
/**
*
* determines the host for every configured connection
*
* @return array an array with configprefix as keys
*
*/
Expand Down Expand Up @@ -149,6 +151,7 @@ private function getServersConfig($value) {

/**
* deletes a given saved LDAP/AD server configuration.
*
* @param string $prefix the configuration prefix of the config to delete
* @return bool true on success, false otherwise
*/
Expand All @@ -166,11 +169,11 @@ public function deleteServerConfiguration($prefix) {
DELETE
FROM `*PREFIX*appconfig`
WHERE `configkey` LIKE ?
'.$saveOtherConfigurations.'
' . $saveOtherConfigurations . '
AND `appid` = \'user_ldap\'
AND `configkey` NOT IN (\'enabled\', \'installed_version\', \'types\', \'bgjUpdateGroupsLastRun\')
');
$delRows = $query->execute([$prefix.'%']);
$delRows = $query->execute([$prefix . '%']);

if ($delRows === null) {
return false;
Expand All @@ -185,8 +188,9 @@ public function deleteServerConfiguration($prefix) {

/**
* checks whether there is one or more disabled LDAP configurations
* @throws \Exception
*
* @return bool
* @throws \Exception
*/
public function haveDisabledConfigurations() {
$all = $this->getServerConfigurationPrefixes(false);
Expand All @@ -201,6 +205,7 @@ public function haveDisabledConfigurations() {

/**
* extracts the domain from a given URL
*
* @param string $url the URL
* @return string|false domain as string on success, false otherwise
*/
Expand Down Expand Up @@ -234,6 +239,7 @@ public function setLDAPProvider() {

/**
* sanitizes a DN received from the LDAP server
*
* @param array $dn the DN in question
* @return array|string the sanitized DN
*/
Expand All @@ -247,12 +253,12 @@ public function sanitizeDN($dn) {
return $result;
}

if(!is_string($dn)) {
if (!is_string($dn)) {
throw new \LogicException('String expected ' . \gettype($dn) . ' given');
}

if (($sanitizedDn = $this->sanitizeDnCache->get($dn)) !== null) {
return $sanitizedDn;
return $sanitizedDn;
}

//OID sometimes gives back DNs with whitespace after the comma
Expand All @@ -274,9 +280,9 @@ public function sanitizeDN($dn) {
'\;' => '\5c3B',
'\"' => '\5c22',
'\#' => '\5c23',
'(' => '\28',
')' => '\29',
'*' => '\2A',
'(' => '\28',
')' => '\29',
'*' => '\2A',
];
$sanitizedDn = str_replace(array_keys($replacements), array_values($replacements), $sanitizedDn);
$this->sanitizeDnCache->set($dn, $sanitizedDn);
Expand All @@ -286,6 +292,7 @@ public function sanitizeDN($dn) {

/**
* converts a stored DN so it can be used as base parameter for LDAP queries, internally we store them for usage in LDAP filters
*
* @param string $dn the DN
* @return string
*/
Expand Down Expand Up @@ -316,7 +323,7 @@ public static function loginName2UserName($param) {
$userSession = \OC::$server->getUserSession();
$userPluginManager = \OC::$server->query('LDAPUserPluginManager');

$userBackend = new User_Proxy(
$userBackend = new User_Proxy(
$configPrefixes, $ldapWrapper, $ocConfig, $notificationManager, $userSession, $userPluginManager
);
$uid = $userBackend->loginName2UserName($param['uid']);
Expand Down
36 changes: 18 additions & 18 deletions apps/user_ldap/tests/Group_LDAPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function getAccessMock() {
$conMethods = get_class_methods('\OCA\User_LDAP\Connection');
$accMethods = get_class_methods('\OCA\User_LDAP\Access');
}
$lw = $this->createMock(ILDAPWrapper::class);
$lw = $this->createMock(ILDAPWrapper::class);
$connector = $this->getMockBuilder('\OCA\User_LDAP\Connection')
->setMethods($conMethods)
->setConstructorArgs([$lw, null, null])
Expand Down Expand Up @@ -169,7 +169,7 @@ public function testCountWithSearchString() {
->method('isDNPartOfBase')
->willReturn(true);

$groupBackend = new GroupLDAP($access,$pluginManager);
$groupBackend = new GroupLDAP($access, $pluginManager);
$users = $groupBackend->countUsersInGroup('group', '3');

$this->assertSame(2, $users);
Expand All @@ -178,7 +178,7 @@ public function testCountWithSearchString() {
public function testCountUsersWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','countUsersInGroup'])
->setMethods(['implementsActions', 'countUsersInGroup'])
->getMock();

$pluginManager->expects($this->once())
Expand All @@ -196,7 +196,7 @@ public function testCountUsersWithPlugin() {

$ldap = new GroupLDAP($access, $pluginManager);

$this->assertEquals($ldap->countUsersInGroup('gid', 'search'),42);
$this->assertEquals($ldap->countUsersInGroup('gid', 'search'), 42);
}

public function testGidNumber2NameSuccess() {
Expand Down Expand Up @@ -478,7 +478,7 @@ public function testInGroupHitsUidGidCache() {

$uid = 'someUser';
$gid = 'someGroup';
$cacheKey = 'inGroup'.$uid.':'.$gid;
$cacheKey = 'inGroup' . $uid . ':' . $gid;

$access->connection->expects($this->once())
->method('getFromCache')
Expand Down Expand Up @@ -746,16 +746,16 @@ public function testGetGroupsByMember() {
->willReturn([$group1, $group2]);
$access->expects($this->any())
->method('dn2groupname')
->willReturnCallback(function(string $dn) {
->willReturnCallback(function (string $dn) {
return ldap_explode_dn($dn, 1)[0];
});
$access->expects($this->any())
->method('groupname2dn')
->willReturnCallback(function (string $gid) use ($group1, $group2) {
if($gid === $group1['cn']) {
if ($gid === $group1['cn']) {
return $group1['dn'][0];
}
if($gid === $group2['cn']) {
if ($gid === $group2['cn']) {
return $group2['dn'][0];
}
});
Expand All @@ -774,7 +774,7 @@ public function testGetGroupsByMember() {
public function testCreateGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','createGroup'])
->setMethods(['implementsActions', 'createGroup'])
->getMock();

$pluginManager->expects($this->once())
Expand All @@ -792,7 +792,7 @@ public function testCreateGroupWithPlugin() {

$ldap = new GroupLDAP($access, $pluginManager);

$this->assertEquals($ldap->createGroup('gid'),true);
$this->assertEquals($ldap->createGroup('gid'), true);
}


Expand Down Expand Up @@ -820,7 +820,7 @@ public function testCreateGroupFailing() {
public function testDeleteGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','deleteGroup'])
->setMethods(['implementsActions', 'deleteGroup'])
->getMock();

$pluginManager->expects($this->once())
Expand All @@ -847,7 +847,7 @@ public function testDeleteGroupWithPlugin() {

$ldap = new GroupLDAP($access, $pluginManager);

$this->assertEquals($ldap->deleteGroup('gid'),'result');
$this->assertEquals($ldap->deleteGroup('gid'), 'result');
}


Expand Down Expand Up @@ -875,7 +875,7 @@ public function testDeleteGroupFailing() {
public function testAddToGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','addToGroup'])
->setMethods(['implementsActions', 'addToGroup'])
->getMock();

$pluginManager->expects($this->once())
Expand All @@ -893,7 +893,7 @@ public function testAddToGroupWithPlugin() {

$ldap = new GroupLDAP($access, $pluginManager);

$this->assertEquals($ldap->addToGroup('uid', 'gid'),'result');
$this->assertEquals($ldap->addToGroup('uid', 'gid'), 'result');
}


Expand Down Expand Up @@ -921,7 +921,7 @@ public function testAddToGroupFailing() {
public function testRemoveFromGroupWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','removeFromGroup'])
->setMethods(['implementsActions', 'removeFromGroup'])
->getMock();

$pluginManager->expects($this->once())
Expand All @@ -939,7 +939,7 @@ public function testRemoveFromGroupWithPlugin() {

$ldap = new GroupLDAP($access, $pluginManager);

$this->assertEquals($ldap->removeFromGroup('uid', 'gid'),'result');
$this->assertEquals($ldap->removeFromGroup('uid', 'gid'), 'result');
}


Expand Down Expand Up @@ -967,7 +967,7 @@ public function testRemoveFromGroupFailing() {
public function testGetGroupDetailsWithPlugin() {
/** @var GroupPluginManager|\PHPUnit_Framework_MockObject_MockObject $pluginManager */
$pluginManager = $this->getMockBuilder('\OCA\User_LDAP\GroupPluginManager')
->setMethods(['implementsActions','getGroupDetails'])
->setMethods(['implementsActions', 'getGroupDetails'])
->getMock();

$pluginManager->expects($this->once())
Expand All @@ -985,7 +985,7 @@ public function testGetGroupDetailsWithPlugin() {

$ldap = new GroupLDAP($access, $pluginManager);

$this->assertEquals($ldap->getGroupDetails('gid'),'result');
$this->assertEquals($ldap->getGroupDetails('gid'), 'result');
}


Expand Down

0 comments on commit a530f6d

Please sign in to comment.