From 4fbb5d4bda406b3725b6efb0a848c985e281422c Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 3 Apr 2026 14:05:38 -0300 Subject: [PATCH 1/2] fix: disable guest id hashing in setup Signed-off-by: Vitor Mattos --- src/NextcloudApiContext.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index 4e0a339..655f8cd 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -96,6 +96,9 @@ public function assureUserExists(string $user): void { #[Given('guest :guest exists')] public function assureGuestExists(string $guest): void { + // Recent guests versions hash user IDs by default, but downstream tests + // still authenticate using the guest identifier passed in the scenario. + self::runCommand('config:app:set guests hash_user_ids --value false --type boolean'); $response = $this->userExists($guest); if ($response->getStatusCode() !== 200) { static::createAnEnvironmentWithValueToBeUsedByOccCommand('OC_PASS', '123456'); From 57bddb68571ce82709b67bda796b37e9cf44363f Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Fri, 3 Apr 2026 14:14:10 -0300 Subject: [PATCH 2/2] fix: restore guest id hashing after scenarios Signed-off-by: Vitor Mattos --- src/NextcloudApiContext.php | 44 ++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/NextcloudApiContext.php b/src/NextcloudApiContext.php index 655f8cd..5fb310a 100644 --- a/src/NextcloudApiContext.php +++ b/src/NextcloudApiContext.php @@ -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; @@ -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')] @@ -96,9 +100,7 @@ public function assureUserExists(string $user): void { #[Given('guest :guest exists')] public function assureGuestExists(string $guest): void { - // Recent guests versions hash user IDs by default, but downstream tests - // still authenticate using the guest identifier passed in the scenario. - self::runCommand('config:app:set guests hash_user_ids --value false --type boolean'); + self::disableGuestIdHashing(); $response = $this->userExists($guest); if ($response->getStatusCode() !== 200) { static::createAnEnvironmentWithValueToBeUsedByOccCommand('OC_PASS', '123456'); @@ -118,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'); @@ -645,6 +682,7 @@ public function tearDown(): void { foreach (self::$createdUsers as $user) { $this->deleteUser($user); } + self::restoreGuestIdHashing(); } protected function deleteUser(string $user): ResponseInterface {