Skip to content

Commit 7d8aa35

Browse files
committed
fix: Fix unmodified placeholder replacing the actual value when updating
When updating global storages and user storages a property is not updated by "StoragesService::updateStorage()" if the value matches the unmodified placeholder. However, userglobal storages are not updated through the "StoragesService"; as only the authentication mechanism is updated it is directly done with "saveBackendOptions()" in "IUserProvided" or "UserGlobalAuth". Due to this the unmodified placeholder value needs to be explicitly checked in those cases and replaced by the actual value (note that in this case it is not possible to just skip updating a specific property). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
1 parent 1d1275d commit 7d8aa35

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

apps/files_external/lib/Lib/Auth/Password/UserGlobalAuth.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace OCA\Files_External\Lib\Auth\Password;
1010

1111
use OCA\Files_External\Lib\Auth\AuthMechanism;
12+
use OCA\Files_External\Lib\DefinitionParameter;
1213
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
1314
use OCA\Files_External\Lib\StorageConfig;
1415
use OCA\Files_External\Service\BackendService;
@@ -41,6 +42,12 @@ public function saveBackendOptions(IUser $user, $id, $backendOptions) {
4142
if (!isset($backendOptions['user']) && !isset($backendOptions['password'])) {
4243
return;
4344
}
45+
46+
if ($backendOptions['password'] === DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
47+
$oldCredentials = $this->credentialsManager->retrieve($user->getUID(), self::CREDENTIALS_IDENTIFIER);
48+
$backendOptions['password'] = $oldCredentials['password'];
49+
}
50+
4451
// make sure we're not setting any unexpected keys
4552
$credentials = [
4653
'user' => $backendOptions['user'],

apps/files_external/lib/Lib/Auth/Password/UserProvided.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ private function getCredentialsIdentifier($storageId) {
4747
}
4848

4949
public function saveBackendOptions(IUser $user, $mountId, array $options) {
50+
if ($options['password'] === DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
51+
$oldCredentials = $this->credentialsManager->retrieve($user->getUID(), $this->getCredentialsIdentifier($mountId));
52+
$options['password'] = $oldCredentials['password'];
53+
}
54+
5055
$this->credentialsManager->store($user->getUID(), $this->getCredentialsIdentifier($mountId), [
5156
'user' => $options['user'], // explicitly copy the fields we want instead of just passing the entire $options array
5257
'password' => $options['password'] // this way we prevent users from being able to modify any other field

build/integration/files_features/external-storage.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ Feature: external-storage
8080
Then fields of last external storage match with
8181
| status | 0 |
8282

83+
Scenario: Save an external storage again with an unmodified password provided by user
84+
Given Logging in using web as "admin"
85+
And logged in user creates external global storage
86+
| mountPoint | "ExternalStorageTest" |
87+
| backend | "owncloud" |
88+
| authMechanism | "password::userprovided" |
89+
| backendOptions | {"host":"http://localhost:8080","secure":false} |
90+
And fields of last external storage match with
91+
| status | 2 |
92+
And logged in user updates last external userglobal storage
93+
| backendOptions | {"user":"admin","password":"admin"} |
94+
When logged in user updates last external userglobal storage
95+
| backendOptions | {"user":"admin","password":"__unmodified__"} |
96+
Then fields of last external storage match with
97+
| status | 0 |
98+
8399
Scenario: Save an external storage with global credentials provided by user
84100
Given Logging in using web as "admin"
85101
And logged in user creates external global storage
@@ -93,3 +109,19 @@ Feature: external-storage
93109
| backendOptions | {"user":"admin","password":"admin"} |
94110
Then fields of last external storage match with
95111
| status | 0 |
112+
113+
Scenario: Save an external storage again with unmodified global credentials provided by user
114+
Given Logging in using web as "admin"
115+
And logged in user creates external global storage
116+
| mountPoint | "ExternalStorageTest" |
117+
| backend | "owncloud" |
118+
| authMechanism | "password::global::user" |
119+
| backendOptions | {"host":"http://localhost:8080","secure":false} |
120+
And fields of last external storage match with
121+
| status | 2 |
122+
And logged in user updates last external userglobal storage
123+
| backendOptions | {"user":"admin","password":"admin"} |
124+
When logged in user updates last external userglobal storage
125+
| backendOptions | {"user":"admin","password":"__unmodified__"} |
126+
Then fields of last external storage match with
127+
| status | 0 |

0 commit comments

Comments
 (0)