Merge pull request #44337 from nextcloud/backport/44276/stable27

[stable27] fix(config): Make sure user keys are strings
This commit is contained in:
Joas Schilling 2024-03-19 20:26:55 +01:00 committed by GitHub
commit 4d0476fd8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View file

@ -334,7 +334,7 @@ class AllConfig implements IConfig {
public function getUserKeys($userId, $appName) {
$data = $this->getAllUserValues($userId);
if (isset($data[$appName])) {
return array_keys($data[$appName]);
return array_map('strval', array_keys($data[$appName]));
} else {
return [];
}

View file

@ -277,6 +277,31 @@ class AllConfigTest extends \Test\TestCase {
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
public function testGetUserKeysAllInts() {
$config = $this->getConfig();
// preparation - add something to the database
$data = [
['userFetch', 'appFetch1', '123', 'value'],
['userFetch', 'appFetch1', '456', 'value'],
];
foreach ($data as $entry) {
$this->connection->executeUpdate(
'INSERT INTO `*PREFIX*preferences` (`userid`, `appid`, ' .
'`configkey`, `configvalue`) VALUES (?, ?, ?, ?)',
$entry
);
}
$value = $config->getUserKeys('userFetch', 'appFetch1');
$this->assertEquals(['123', '456'], $value);
$this->assertIsString($value[0]);
$this->assertIsString($value[1]);
// cleanup
$this->connection->executeUpdate('DELETE FROM `*PREFIX*preferences`');
}
public function testGetUserValueDefault() {
$config = $this->getConfig();