Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/NextcloudApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class NextcloudApiContext implements Context {
* @var string[]
*/
protected static array $createdUsers = [];
protected static bool $shouldRestoreGuestIdHashing = false;
protected static ?bool $guestIdHashingOriginalValue = null;
protected ResponseInterface $response;
/** @var CookieJar[] */
protected $cookieJars;
Expand Down Expand Up @@ -74,6 +76,8 @@ public static function beforeSuite(BeforeSuiteScope $scope):void {
public static function beforeScenario(): void {
self::$createdUsers = [];
self::$environments = [];
self::$shouldRestoreGuestIdHashing = false;
self::$guestIdHashingOriginalValue = null;
}

#[Given('as user :user')]
Expand All @@ -96,6 +100,7 @@ public function assureUserExists(string $user): void {

#[Given('guest :guest exists')]
public function assureGuestExists(string $guest): void {
self::disableGuestIdHashing();
$response = $this->userExists($guest);
if ($response->getStatusCode() !== 200) {
static::createAnEnvironmentWithValueToBeUsedByOccCommand('OC_PASS', '123456');
Expand All @@ -115,6 +120,41 @@ protected function userExists(string $user): ResponseInterface {
return $this->response;
}

private static function disableGuestIdHashing(): void {
if (self::$shouldRestoreGuestIdHashing) {
return;
}

// nextcloud/guests 555cf1bc hashes guest IDs by default, but guest
// scenarios still use the raw identifier as the login/user reference.
$currentValue = self::runCommand('config:app:get guests hash_user_ids');
self::$shouldRestoreGuestIdHashing = true;
self::$guestIdHashingOriginalValue = $currentValue['resultCode'] === 0
? trim(implode("\n", $currentValue['output'])) === '1'
: null;
self::runCommandWithResultCode('config:app:set guests hash_user_ids --value false --type boolean', 0);
}

private static function restoreGuestIdHashing(): void {
if (!self::$shouldRestoreGuestIdHashing) {
return;
}

$originalValue = self::$guestIdHashingOriginalValue;
self::$shouldRestoreGuestIdHashing = false;
self::$guestIdHashingOriginalValue = null;

if ($originalValue === null) {
self::runCommandWithResultCode('config:app:delete guests hash_user_ids', 0);
return;
}

self::runCommandWithResultCode(
'config:app:set guests hash_user_ids --value ' . ($originalValue ? 'true' : 'false') . ' --type boolean',
0
);
}

protected function createUser(string $user): void {
$currentUser = $this->currentUser;
$this->setCurrentUser('admin');
Expand Down Expand Up @@ -642,6 +682,7 @@ public function tearDown(): void {
foreach (self::$createdUsers as $user) {
$this->deleteUser($user);
}
self::restoreGuestIdHashing();
}

protected function deleteUser(string $user): ResponseInterface {
Expand Down
Loading