aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Config
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Config')
-rw-r--r--tests/lib/Config/LexiconTest.php59
-rw-r--r--tests/lib/Config/TestConfigLexicon_I.php5
-rw-r--r--tests/lib/Config/UserConfigTest.php180
3 files changed, 127 insertions, 117 deletions
diff --git a/tests/lib/Config/LexiconTest.php b/tests/lib/Config/LexiconTest.php
index 5bcd3509b22..530767a7416 100644
--- a/tests/lib/Config/LexiconTest.php
+++ b/tests/lib/Config/LexiconTest.php
@@ -10,7 +10,9 @@ namespace Tests\lib\Config;
use NCU\Config\Exceptions\TypeConflictException;
use NCU\Config\Exceptions\UnknownKeyException;
use NCU\Config\IUserConfig;
+use OC\AppConfig;
use OC\AppFramework\Bootstrap\Coordinator;
+use OC\Config\ConfigManager;
use OCP\Exceptions\AppConfigTypeConflictException;
use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
@@ -25,13 +27,15 @@ use Test\TestCase;
* @package Test
*/
class LexiconTest extends TestCase {
+ /** @var AppConfig */
private IAppConfig $appConfig;
private IUserConfig $userConfig;
+ private ConfigManager $configManager;
protected function setUp(): void {
parent::setUp();
- $bootstrapCoordinator = \OCP\Server::get(Coordinator::class);
+ $bootstrapCoordinator = Server::get(Coordinator::class);
$bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon(TestConfigLexicon_I::APPID, TestConfigLexicon_I::class);
$bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon(TestConfigLexicon_N::APPID, TestConfigLexicon_N::class);
$bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon(TestConfigLexicon_W::APPID, TestConfigLexicon_W::class);
@@ -39,6 +43,7 @@ class LexiconTest extends TestCase {
$this->appConfig = Server::get(IAppConfig::class);
$this->userConfig = Server::get(IUserConfig::class);
+ $this->configManager = Server::get(ConfigManager::class);
}
protected function tearDown(): void {
@@ -141,11 +146,61 @@ class LexiconTest extends TestCase {
public function testUserLexiconSetException() {
$this->expectException(UnknownKeyException::class);
$this->userConfig->setValueString('user1', TestConfigLexicon_E::APPID, 'key_exception', 'new_value');
- $this->assertSame('', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key3', ''));
+ $this->assertSame('', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key5', ''));
}
public function testUserLexiconGetException() {
$this->expectException(UnknownKeyException::class);
$this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key_exception');
}
+
+ public function testAppConfigLexiconRenameSetNewValue() {
+ $this->assertSame(12345, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123));
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'old_key3', 994);
+ $this->assertSame(994, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123));
+ }
+
+ public function testAppConfigLexiconRenameSetOldValuePreMigration() {
+ $this->appConfig->ignoreLexiconAliases(true);
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'old_key3', 993);
+ $this->appConfig->ignoreLexiconAliases(false);
+ $this->assertSame(12345, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123));
+ }
+
+ public function testAppConfigLexiconRenameSetOldValuePostMigration() {
+ $this->appConfig->ignoreLexiconAliases(true);
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'old_key3', 994);
+ $this->appConfig->ignoreLexiconAliases(false);
+ $this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID);
+ $this->assertSame(994, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'key3', 123));
+ }
+
+ public function testAppConfigLexiconRenameGetNewValue() {
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key3', 981);
+ $this->assertSame(981, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'old_key3', 123));
+ }
+
+ public function testAppConfigLexiconRenameGetOldValuePreMigration() {
+ $this->appConfig->ignoreLexiconAliases(true);
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key3', 984);
+ $this->assertSame(123, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'old_key3', 123));
+ $this->appConfig->ignoreLexiconAliases(false);
+ }
+
+ public function testAppConfigLexiconRenameGetOldValuePostMigration() {
+ $this->appConfig->ignoreLexiconAliases(true);
+ $this->appConfig->setValueInt(TestConfigLexicon_I::APPID, 'key3', 987);
+ $this->appConfig->ignoreLexiconAliases(false);
+ $this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID);
+ $this->assertSame(987, $this->appConfig->getValueInt(TestConfigLexicon_I::APPID, 'old_key3', 123));
+ }
+
+ public function testAppConfigLexiconRenameInvertBoolean() {
+ $this->appConfig->ignoreLexiconAliases(true);
+ $this->appConfig->setValueBool(TestConfigLexicon_I::APPID, 'old_key4', true);
+ $this->appConfig->ignoreLexiconAliases(false);
+ $this->assertSame(true, $this->appConfig->getValueBool(TestConfigLexicon_I::APPID, 'key4'));
+ $this->configManager->migrateConfigLexiconKeys(TestConfigLexicon_I::APPID);
+ $this->assertSame(false, $this->appConfig->getValueBool(TestConfigLexicon_I::APPID, 'key4'));
+ }
}
diff --git a/tests/lib/Config/TestConfigLexicon_I.php b/tests/lib/Config/TestConfigLexicon_I.php
index 497c62acecb..6fb7921b6e6 100644
--- a/tests/lib/Config/TestConfigLexicon_I.php
+++ b/tests/lib/Config/TestConfigLexicon_I.php
@@ -25,8 +25,9 @@ class TestConfigLexicon_I implements IConfigLexicon {
public function getAppConfigs(): array {
return [
new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IAppConfig::FLAG_SENSITIVE),
- new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
-
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false),
+ new ConfigLexiconEntry('key3', ValueType::INT, 12345, 'test key', true, rename: 'old_key3'),
+ new ConfigLexiconEntry('key4', ValueType::BOOL, 12345, 'test key', true, rename: 'old_key4', options: ConfigLexiconEntry::RENAME_INVERT_BOOLEAN),
];
}
diff --git a/tests/lib/Config/UserConfigTest.php b/tests/lib/Config/UserConfigTest.php
index 7bd1e06e297..2c8222576c4 100644
--- a/tests/lib/Config/UserConfigTest.php
+++ b/tests/lib/Config/UserConfigTest.php
@@ -15,6 +15,7 @@ use OC\Config\UserConfig;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
+use OCP\Server;
use Psr\Log\LoggerInterface;
use Test\TestCase;
@@ -35,10 +36,10 @@ class UserConfigTest extends TestCase {
/**
* @var array<string, array<string, array<array<string, string, int, bool, bool>>> [userId => [appId => prefKey, prefValue, valueType, lazy, sensitive]]]
*/
- private array $basePreferences =
- [
- 'user1' =>
- [
+ private array $basePreferences
+ = [
+ 'user1'
+ => [
'app1' => [
'key1' => ['key1', 'value1'],
'key22' => ['key22', '31'],
@@ -97,8 +98,8 @@ class UserConfigTest extends TestCase {
'key5' => ['key5', true, ValueType::BOOL, true],
]
],
- 'user2' =>
- [
+ 'user2'
+ => [
'app1' => [
'1' => ['1', 'value1'],
'2' => ['2', 'value2', ValueType::STRING, true, UserConfig::FLAG_SENSITIVE],
@@ -120,8 +121,8 @@ class UserConfigTest extends TestCase {
'key1' => ['key1', 'value1', ValueType::STRING, true, 0, true]
]
],
- 'user3' =>
- [
+ 'user3'
+ => [
'app2' => [
'key2' => ['key2', 'value2c', ValueType::MIXED, false, 0, true],
'key3' => ['key3', 'value3', ValueType::STRING, true, ],
@@ -137,8 +138,8 @@ class UserConfigTest extends TestCase {
'key3' => ['key3', 'value3', ValueType::STRING, true]
]
],
- 'user4' =>
- [
+ 'user4'
+ => [
'app2' => [
'key1' => ['key1', 'value1'],
'key2' => ['key2', 'value2A', ValueType::MIXED, false, 0, true],
@@ -152,8 +153,8 @@ class UserConfigTest extends TestCase {
'key1' => ['key1', 123, ValueType::INT, true, 0, true]
]
],
- 'user5' =>
- [
+ 'user5'
+ => [
'app1' => [
'key1' => ['key1', 'value1']
],
@@ -170,10 +171,10 @@ class UserConfigTest extends TestCase {
protected function setUp(): void {
parent::setUp();
- $this->connection = \OCP\Server::get(IDBConnection::class);
- $this->config = \OCP\Server::get(IConfig::class);
- $this->logger = \OCP\Server::get(LoggerInterface::class);
- $this->crypto = \OCP\Server::get(ICrypto::class);
+ $this->connection = Server::get(IDBConnection::class);
+ $this->config = Server::get(IConfig::class);
+ $this->logger = Server::get(LoggerInterface::class);
+ $this->crypto = Server::get(ICrypto::class);
// storing current preferences and emptying the data table
$sql = $this->connection->getQueryBuilder();
@@ -278,7 +279,7 @@ class UserConfigTest extends TestCase {
* @return IUserConfig
*/
private function generateUserConfig(array $preLoading = []): IUserConfig {
- $userConfig = new \OC\Config\UserConfig(
+ $userConfig = new UserConfig(
$this->connection,
$this->config,
$this->logger,
@@ -347,9 +348,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerHasKey
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerHasKey')]
public function testHasKey(string $userId, string $appId, string $key, ?bool $lazy, bool $result): void {
$userConfig = $this->generateUserConfig();
$this->assertEquals($result, $userConfig->hasKey($userId, $appId, $key, $lazy));
@@ -374,9 +373,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerIsSensitive
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerIsSensitive')]
public function testIsSensitive(
string $userId,
string $appId,
@@ -405,9 +402,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerIsLazy
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerIsLazy')]
public function testIsLazy(
string $userId,
string $appId,
@@ -540,9 +535,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetValues
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValues')]
public function testGetValues(
string $userId,
string $appId,
@@ -641,9 +634,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetAllValues
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetAllValues')]
public function testGetAllValues(
string $userId,
bool $filtered,
@@ -685,9 +676,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSearchValuesByApps
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSearchValuesByApps')]
public function testSearchValuesByApps(
string $userId,
string $key,
@@ -735,9 +724,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSearchValuesByUsers
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSearchValuesByUsers')]
public function testSearchValuesByUsers(
string $app,
string $key,
@@ -759,9 +746,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSearchValuesByValueString
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSearchValuesByValueString')]
public function testSearchUsersByValueString(
string $app,
string $key,
@@ -781,9 +766,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSearchValuesByValueInt
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSearchValuesByValueInt')]
public function testSearchUsersByValueInt(
string $app,
string $key,
@@ -801,9 +784,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSearchValuesByValues
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSearchValuesByValues')]
public function testSearchUsersByValues(
string $app,
string $key,
@@ -821,9 +802,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSearchValuesByValueBool
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSearchValuesByValueBool')]
public function testSearchUsersByValueBool(
string $app,
string $key,
@@ -902,9 +881,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetValueMixed
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValueMixed')]
public function testGetValueMixed(
?array $preload,
string $userId,
@@ -918,9 +895,7 @@ class UserConfigTest extends TestCase {
$this->assertEquals($result, $userConfig->getValueMixed($userId, $app, $key, $default, $lazy));
}
- /**
- * @dataProvider providerGetValueMixed
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValueMixed')]
public function testGetValueString(
?array $preload,
string $userId,
@@ -960,9 +935,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetValueInt
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValueInt')]
public function testGetValueInt(
?array $preload,
string $userId,
@@ -1001,9 +974,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetValueFloat
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValueFloat')]
public function testGetValueFloat(
?array $preload,
string $userId,
@@ -1062,9 +1033,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetValueBool
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValueBool')]
public function testGetValueBool(
?array $preload,
string $userId,
@@ -1099,9 +1068,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetValueArray
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValueArray')]
public function testGetValueArray(
?array $preload,
string $userId,
@@ -1155,9 +1122,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetValueType
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetValueType')]
public function testGetValueType(
?array $preload,
string $userId,
@@ -1214,9 +1179,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSetValueMixed
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSetValueMixed')]
public function testSetValueMixed(
?array $preload,
string $userId,
@@ -1240,6 +1203,19 @@ class UserConfigTest extends TestCase {
}
}
+ /**
+ * This test needs to stay! Emails are expected to be lowercase due to performance reasons.
+ * This way we can skip the expensive casing change on the database.
+ */
+ public function testSetValueMixedWithSettingsEmail(): void {
+ $userConfig = $this->generateUserConfig();
+
+ $edited = $userConfig->setValueMixed('user1', 'settings', 'email', 'mixed.CASE@Nextcloud.com');
+ $this->assertTrue($edited);
+
+ $actual = $userConfig->getValueMixed('user1', 'settings', 'email');
+ $this->assertEquals('mixed.case@nextcloud.com', $actual);
+ }
public static function providerSetValueString(): array {
return [
@@ -1284,9 +1260,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSetValueString
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSetValueString')]
public function testSetValueString(
?array $preload,
string $userId,
@@ -1347,9 +1321,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSetValueInt
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSetValueInt')]
public function testSetValueInt(
?array $preload,
string $userId,
@@ -1410,9 +1382,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSetValueFloat
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSetValueFloat')]
public function testSetValueFloat(
?array $preload,
string $userId,
@@ -1474,9 +1444,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerSetValueArray
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerSetValueArray')]
public function testSetValueArray(
?array $preload,
string $userId,
@@ -1520,9 +1488,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerUpdateSensitive
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerUpdateSensitive')]
public function testUpdateSensitive(
?array $preload,
string $userId,
@@ -1549,8 +1515,8 @@ class UserConfigTest extends TestCase {
$this->assertEquals($sensitive, $userConfig->isSensitive($userId, $app, $key));
if ($sensitive) {
$this->assertEquals(true, str_starts_with(
- $userConfig->statusCache()['fastCache'][$userId][$app][$key] ??
- $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
+ $userConfig->statusCache()['fastCache'][$userId][$app][$key]
+ ?? $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
'$UserConfigEncryption$')
);
}
@@ -1561,9 +1527,7 @@ class UserConfigTest extends TestCase {
return [[true], [false]];
}
- /**
- * @dataProvider providerUpdateGlobalSensitive
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerUpdateGlobalSensitive')]
public function testUpdateGlobalSensitive(bool $sensitive): void {
$userConfig = $this->generateUserConfig($preload ?? []);
$app = 'app2';
@@ -1580,8 +1544,8 @@ class UserConfigTest extends TestCase {
$userConfig->getValueString($userId, $app, $key); // cache loading for userId
$this->assertEquals(
!$sensitive, str_starts_with(
- $userConfig->statusCache()['fastCache'][$userId][$app][$key] ??
- $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
+ $userConfig->statusCache()['fastCache'][$userId][$app][$key]
+ ?? $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
'$UserConfigEncryption$'
)
);
@@ -1594,8 +1558,8 @@ class UserConfigTest extends TestCase {
$this->assertEquals($sensitive, $userConfig->isSensitive($userId, $app, $key));
// should only work if updateGlobalSensitive drop cache
$this->assertEquals($sensitive, str_starts_with(
- $userConfig->statusCache()['fastCache'][$userId][$app][$key] ??
- $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
+ $userConfig->statusCache()['fastCache'][$userId][$app][$key]
+ ?? $userConfig->statusCache()['lazyCache'][$userId][$app][$key],
'$UserConfigEncryption$')
);
}
@@ -1610,9 +1574,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerUpdateLazy
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerUpdateLazy')]
public function testUpdateLazy(
?array $preload,
string $userId,
@@ -1644,9 +1606,7 @@ class UserConfigTest extends TestCase {
return [[true], [false]];
}
- /**
- * @dataProvider providerUpdateGlobalLazy
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerUpdateGlobalLazy')]
public function testUpdateGlobalLazy(bool $lazy): void {
$userConfig = $this->generateUserConfig($preload ?? []);
$app = 'app2';
@@ -1714,9 +1674,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerGetDetails
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerGetDetails')]
public function testGetDetails(string $userId, string $app, string $key, array $result): void {
$userConfig = $this->generateUserConfig($preload ?? []);
$this->assertEqualsCanonicalizing($result, $userConfig->getDetails($userId, $app, $key));
@@ -1734,9 +1692,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerDeletePreference
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerDeletePreference')]
public function testDeletePreference(
?array $preload,
string $userId,
@@ -1765,9 +1721,7 @@ class UserConfigTest extends TestCase {
];
}
- /**
- * @dataProvider providerDeleteKey
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('providerDeleteKey')]
public function testDeleteKey(
?array $preload,
string $app,