]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix(config): Make sure user keys are strings 44480/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Mon, 18 Mar 2024 13:51:35 +0000 (14:51 +0100)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Tue, 26 Mar 2024 10:16:09 +0000 (10:16 +0000)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
lib/private/AllConfig.php
tests/lib/AllConfigTest.php

index 36f5f2cd40a0ac3fbe7b3733c76b6df780c18c1e..1a3d032a61edbb9791370fad6408e2474d50a335 100644 (file)
@@ -334,7 +334,7 @@ class AllConfig implements \OCP\IConfig {
        public function getUserKeys($userId, $appName) {
                $data = $this->getUserValues($userId);
                if (isset($data[$appName])) {
-                       return array_keys($data[$appName]);
+                       return array_map('strval', array_keys($data[$appName]));
                } else {
                        return [];
                }
index 9daa7c9be9c8a1aaf7cb8d5a901e795ab344afc4..71def607ac7ab403c8dc2668a948f30b8101aaf9 100644 (file)
@@ -276,6 +276,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();