2012-04-13 16:52:06 -04:00
|
|
|
<?php
|
2025-06-30 09:04:05 -04:00
|
|
|
|
2012-04-13 16:52:06 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-05-28 17:46:57 -04:00
|
|
|
*/
|
2015-02-26 05:37:37 -05:00
|
|
|
|
2015-09-21 18:56:36 -04:00
|
|
|
namespace Test\Util\User;
|
|
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OC\User\Backend;
|
2025-06-12 12:31:58 -04:00
|
|
|
use OCP\IUserBackend;
|
2015-09-21 18:56:36 -04:00
|
|
|
|
2015-02-26 05:37:37 -05:00
|
|
|
/**
|
|
|
|
|
* dummy user backend, does not keep state, only for testing use
|
|
|
|
|
*/
|
2025-06-12 12:31:58 -04:00
|
|
|
class Dummy extends Backend implements IUserBackend {
|
2025-12-02 05:39:50 -05:00
|
|
|
private array $users = [];
|
|
|
|
|
private array $displayNames = [];
|
|
|
|
|
|
|
|
|
|
public function createUser($uid, $password): bool {
|
2013-05-28 17:46:57 -04:00
|
|
|
if (isset($this->users[$uid])) {
|
2012-04-13 16:52:06 -04:00
|
|
|
return false;
|
2013-05-28 17:46:57 -04:00
|
|
|
} else {
|
|
|
|
|
$this->users[$uid] = $password;
|
2012-04-13 16:52:06 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function deleteUser($uid): bool {
|
2013-05-28 17:46:57 -04:00
|
|
|
if (isset($this->users[$uid])) {
|
2012-04-13 16:52:06 -04:00
|
|
|
unset($this->users[$uid]);
|
|
|
|
|
return true;
|
2013-05-28 17:46:57 -04:00
|
|
|
} else {
|
2012-04-13 16:52:06 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function setPassword($uid, $password): bool {
|
2013-05-28 17:46:57 -04:00
|
|
|
if (isset($this->users[$uid])) {
|
|
|
|
|
$this->users[$uid] = $password;
|
2012-04-13 16:52:06 -04:00
|
|
|
return true;
|
2013-05-28 17:46:57 -04:00
|
|
|
} else {
|
2012-04-13 16:52:06 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function checkPassword($uid, $password): string|false {
|
2013-10-08 14:03:16 -04:00
|
|
|
if (isset($this->users[$uid]) && $this->users[$uid] === $password) {
|
2013-10-08 13:48:49 -04:00
|
|
|
return $uid;
|
2012-04-13 16:52:06 -04:00
|
|
|
}
|
2017-07-19 09:37:03 -04:00
|
|
|
|
|
|
|
|
return false;
|
2012-04-13 16:52:06 -04:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function loginName2UserName($loginName): string|false {
|
2017-12-22 07:38:10 -05:00
|
|
|
if (isset($this->users[strtolower($loginName)])) {
|
|
|
|
|
return strtolower($loginName);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function getUsers($search = '', $limit = null, $offset = null): array {
|
2014-11-06 11:22:59 -05:00
|
|
|
if (empty($search)) {
|
2014-06-25 07:13:53 -04:00
|
|
|
return array_keys($this->users);
|
|
|
|
|
}
|
2020-03-26 04:30:18 -04:00
|
|
|
$result = [];
|
2014-11-06 11:22:59 -05:00
|
|
|
foreach (array_keys($this->users) as $user) {
|
|
|
|
|
if (stripos($user, $search) !== false) {
|
2014-06-25 07:13:53 -04:00
|
|
|
$result[] = $user;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $result;
|
2012-04-13 16:52:06 -04:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function userExists($uid): bool {
|
2012-04-13 16:52:06 -04:00
|
|
|
return isset($this->users[$uid]);
|
|
|
|
|
}
|
2013-02-11 16:01:52 -05:00
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function hasUserListings(): bool {
|
2013-02-11 16:01:52 -05:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-01-08 07:26:48 -05:00
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function countUsers(): int {
|
2014-01-08 07:26:48 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|
2014-11-06 11:22:59 -05:00
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function setDisplayName($uid, $displayName): bool {
|
2014-11-06 11:22:59 -05:00
|
|
|
$this->displayNames[$uid] = $displayName;
|
2019-04-11 05:43:33 -04:00
|
|
|
return true;
|
2014-11-06 11:22:59 -05:00
|
|
|
}
|
|
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function getDisplayName($uid): string {
|
2023-07-07 06:45:12 -04:00
|
|
|
return $this->displayNames[$uid] ?? $uid;
|
2014-11-06 11:22:59 -05:00
|
|
|
}
|
2014-12-12 11:25:03 -05:00
|
|
|
|
2025-12-02 05:39:50 -05:00
|
|
|
public function getBackendName(): string {
|
2014-12-12 11:25:03 -05:00
|
|
|
return 'Dummy';
|
|
|
|
|
}
|
2012-04-13 16:52:06 -04:00
|
|
|
}
|