Skip to content

Commit 6dc5a65

Browse files
authored
Merge pull request #110 from LibreSign/fix/disable-guest-id-hashing
fix: disable guest id hashing in setup
2 parents 3c19fdb + 57bddb6 commit 6dc5a65

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

src/NextcloudApiContext.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class NextcloudApiContext implements Context {
3939
* @var string[]
4040
*/
4141
protected static array $createdUsers = [];
42+
protected static bool $shouldRestoreGuestIdHashing = false;
43+
protected static ?bool $guestIdHashingOriginalValue = null;
4244
protected ResponseInterface $response;
4345
/** @var CookieJar[] */
4446
protected $cookieJars;
@@ -74,6 +76,8 @@ public static function beforeSuite(BeforeSuiteScope $scope):void {
7476
public static function beforeScenario(): void {
7577
self::$createdUsers = [];
7678
self::$environments = [];
79+
self::$shouldRestoreGuestIdHashing = false;
80+
self::$guestIdHashingOriginalValue = null;
7781
}
7882

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

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

123+
private static function disableGuestIdHashing(): void {
124+
if (self::$shouldRestoreGuestIdHashing) {
125+
return;
126+
}
127+
128+
// nextcloud/guests 555cf1bc hashes guest IDs by default, but guest
129+
// scenarios still use the raw identifier as the login/user reference.
130+
$currentValue = self::runCommand('config:app:get guests hash_user_ids');
131+
self::$shouldRestoreGuestIdHashing = true;
132+
self::$guestIdHashingOriginalValue = $currentValue['resultCode'] === 0
133+
? trim(implode("\n", $currentValue['output'])) === '1'
134+
: null;
135+
self::runCommandWithResultCode('config:app:set guests hash_user_ids --value false --type boolean', 0);
136+
}
137+
138+
private static function restoreGuestIdHashing(): void {
139+
if (!self::$shouldRestoreGuestIdHashing) {
140+
return;
141+
}
142+
143+
$originalValue = self::$guestIdHashingOriginalValue;
144+
self::$shouldRestoreGuestIdHashing = false;
145+
self::$guestIdHashingOriginalValue = null;
146+
147+
if ($originalValue === null) {
148+
self::runCommandWithResultCode('config:app:delete guests hash_user_ids', 0);
149+
return;
150+
}
151+
152+
self::runCommandWithResultCode(
153+
'config:app:set guests hash_user_ids --value ' . ($originalValue ? 'true' : 'false') . ' --type boolean',
154+
0
155+
);
156+
}
157+
118158
protected function createUser(string $user): void {
119159
$currentUser = $this->currentUser;
120160
$this->setCurrentUser('admin');
@@ -642,6 +682,7 @@ public function tearDown(): void {
642682
foreach (self::$createdUsers as $user) {
643683
$this->deleteUser($user);
644684
}
685+
self::restoreGuestIdHashing();
645686
}
646687

647688
protected function deleteUser(string $user): ResponseInterface {

0 commit comments

Comments
 (0)