aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2024-12-06 09:35:00 -0100
committerMaxence Lange <maxence@artificial-owl.com>2024-12-13 11:08:20 -0100
commit96586ba7095b3d955b093bc34d696654faa80252 (patch)
tree4fb7d1dec44c96507aa42a07e0d9182dce7d2596 /tests
parent10852d38e345eab68035a2442f3a76b5c5e7bf1a (diff)
downloadnextcloud-server-96586ba7095b3d955b093bc34d696654faa80252.tar.gz
nextcloud-server-96586ba7095b3d955b093bc34d696654faa80252.zip
feat(config): implementation of lexicon
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/AppConfigTest.php5
-rw-r--r--tests/lib/Config/LexiconTest.php151
-rw-r--r--tests/lib/Config/TestConfigLexicon_E.php38
-rw-r--r--tests/lib/Config/TestConfigLexicon_I.php40
-rw-r--r--tests/lib/Config/TestConfigLexicon_N.php39
-rw-r--r--tests/lib/Config/TestConfigLexicon_W.php39
-rw-r--r--tests/lib/Config/UserConfigTest.php4
7 files changed, 314 insertions, 2 deletions
diff --git a/tests/lib/AppConfigTest.php b/tests/lib/AppConfigTest.php
index e8c10fe654b..775c9027dd6 100644
--- a/tests/lib/AppConfigTest.php
+++ b/tests/lib/AppConfigTest.php
@@ -9,6 +9,7 @@ namespace Test;
use InvalidArgumentException;
use OC\AppConfig;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\Exceptions\AppConfigTypeConflictException;
use OCP\Exceptions\AppConfigUnknownKeyException;
use OCP\IAppConfig;
@@ -28,6 +29,8 @@ class AppConfigTest extends TestCase {
protected IDBConnection $connection;
private LoggerInterface $logger;
private ICrypto $crypto;
+ private Coordinator $coordinator;
+
private array $originalConfig;
/**
@@ -88,6 +91,7 @@ class AppConfigTest extends TestCase {
$this->connection = \OCP\Server::get(IDBConnection::class);
$this->logger = \OCP\Server::get(LoggerInterface::class);
$this->crypto = \OCP\Server::get(ICrypto::class);
+ $this->coordinator = \OCP\Server::get(Coordinator::class);
// storing current config and emptying the data table
$sql = $this->connection->getQueryBuilder();
@@ -178,6 +182,7 @@ class AppConfigTest extends TestCase {
$this->connection,
$this->logger,
$this->crypto,
+ $this->coordinator
);
$msg = ' generateAppConfig() failed to confirm cache status';
diff --git a/tests/lib/Config/LexiconTest.php b/tests/lib/Config/LexiconTest.php
new file mode 100644
index 00000000000..5bcd3509b22
--- /dev/null
+++ b/tests/lib/Config/LexiconTest.php
@@ -0,0 +1,151 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+namespace Tests\lib\Config;
+
+use NCU\Config\Exceptions\TypeConflictException;
+use NCU\Config\Exceptions\UnknownKeyException;
+use NCU\Config\IUserConfig;
+use OC\AppFramework\Bootstrap\Coordinator;
+use OCP\Exceptions\AppConfigTypeConflictException;
+use OCP\Exceptions\AppConfigUnknownKeyException;
+use OCP\IAppConfig;
+use OCP\Server;
+use Test\TestCase;
+
+/**
+ * Class UserPreferencesTest
+ *
+ * @group DB
+ *
+ * @package Test
+ */
+class LexiconTest extends TestCase {
+ private IAppConfig $appConfig;
+ private IUserConfig $userConfig;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $bootstrapCoordinator = \OCP\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);
+ $bootstrapCoordinator->getRegistrationContext()?->registerConfigLexicon(TestConfigLexicon_E::APPID, TestConfigLexicon_E::class);
+
+ $this->appConfig = Server::get(IAppConfig::class);
+ $this->userConfig = Server::get(IUserConfig::class);
+ }
+
+ protected function tearDown(): void {
+ parent::tearDown();
+
+ $this->appConfig->deleteApp(TestConfigLexicon_I::APPID);
+ $this->appConfig->deleteApp(TestConfigLexicon_N::APPID);
+ $this->appConfig->deleteApp(TestConfigLexicon_W::APPID);
+ $this->appConfig->deleteApp(TestConfigLexicon_E::APPID);
+
+ $this->userConfig->deleteApp(TestConfigLexicon_I::APPID);
+ $this->userConfig->deleteApp(TestConfigLexicon_N::APPID);
+ $this->userConfig->deleteApp(TestConfigLexicon_W::APPID);
+ $this->userConfig->deleteApp(TestConfigLexicon_E::APPID);
+ }
+
+ public function testAppLexiconSetCorrect() {
+ $this->assertSame(true, $this->appConfig->setValueString(TestConfigLexicon_E::APPID, 'key1', 'new_value'));
+ $this->assertSame(true, $this->appConfig->isLazy(TestConfigLexicon_E::APPID, 'key1'));
+ $this->assertSame(true, $this->appConfig->isSensitive(TestConfigLexicon_E::APPID, 'key1'));
+ $this->appConfig->deleteKey(TestConfigLexicon_E::APPID, 'key1');
+ }
+
+ public function testAppLexiconGetCorrect() {
+ $this->assertSame('abcde', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key1', 'default'));
+ }
+
+ public function testAppLexiconSetIncorrectValueType() {
+ $this->expectException(AppConfigTypeConflictException::class);
+ $this->appConfig->setValueInt(TestConfigLexicon_E::APPID, 'key1', -1);
+ }
+
+ public function testAppLexiconGetIncorrectValueType() {
+ $this->expectException(AppConfigTypeConflictException::class);
+ $this->appConfig->getValueInt(TestConfigLexicon_E::APPID, 'key1');
+ }
+
+ public function testAppLexiconIgnore() {
+ $this->appConfig->setValueString(TestConfigLexicon_I::APPID, 'key_ignore', 'new_value');
+ $this->assertSame('new_value', $this->appConfig->getValueString(TestConfigLexicon_I::APPID, 'key_ignore', ''));
+ }
+
+ public function testAppLexiconNotice() {
+ $this->appConfig->setValueString(TestConfigLexicon_N::APPID, 'key_notice', 'new_value');
+ $this->assertSame('new_value', $this->appConfig->getValueString(TestConfigLexicon_N::APPID, 'key_notice', ''));
+ }
+
+ public function testAppLexiconWarning() {
+ $this->appConfig->setValueString(TestConfigLexicon_W::APPID, 'key_warning', 'new_value');
+ $this->assertSame('', $this->appConfig->getValueString(TestConfigLexicon_W::APPID, 'key_warning', ''));
+ }
+
+ public function testAppLexiconSetException() {
+ $this->expectException(AppConfigUnknownKeyException::class);
+ $this->appConfig->setValueString(TestConfigLexicon_E::APPID, 'key_exception', 'new_value');
+ $this->assertSame('', $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key3', ''));
+ }
+
+ public function testAppLexiconGetException() {
+ $this->expectException(AppConfigUnknownKeyException::class);
+ $this->appConfig->getValueString(TestConfigLexicon_E::APPID, 'key_exception');
+ }
+
+ public function testUserLexiconSetCorrect() {
+ $this->assertSame(true, $this->userConfig->setValueString('user1', TestConfigLexicon_E::APPID, 'key1', 'new_value'));
+ $this->assertSame(true, $this->userConfig->isLazy('user1', TestConfigLexicon_E::APPID, 'key1'));
+ $this->assertSame(true, $this->userConfig->isSensitive('user1', TestConfigLexicon_E::APPID, 'key1'));
+ $this->userConfig->deleteKey(TestConfigLexicon_E::APPID, 'key1');
+ }
+
+ public function testUserLexiconGetCorrect() {
+ $this->assertSame('abcde', $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key1', 'default'));
+ }
+
+ public function testUserLexiconSetIncorrectValueType() {
+ $this->expectException(TypeConflictException::class);
+ $this->userConfig->setValueInt('user1', TestConfigLexicon_E::APPID, 'key1', -1);
+ }
+
+ public function testUserLexiconGetIncorrectValueType() {
+ $this->expectException(TypeConflictException::class);
+ $this->userConfig->getValueInt('user1', TestConfigLexicon_E::APPID, 'key1');
+ }
+
+ public function testUserLexiconIgnore() {
+ $this->userConfig->setValueString('user1', TestConfigLexicon_I::APPID, 'key_ignore', 'new_value');
+ $this->assertSame('new_value', $this->userConfig->getValueString('user1', TestConfigLexicon_I::APPID, 'key_ignore', ''));
+ }
+
+ public function testUserLexiconNotice() {
+ $this->userConfig->setValueString('user1', TestConfigLexicon_N::APPID, 'key_notice', 'new_value');
+ $this->assertSame('new_value', $this->userConfig->getValueString('user1', TestConfigLexicon_N::APPID, 'key_notice', ''));
+ }
+
+ public function testUserLexiconWarning() {
+ $this->userConfig->setValueString('user1', TestConfigLexicon_W::APPID, 'key_warning', 'new_value');
+ $this->assertSame('', $this->userConfig->getValueString('user1', TestConfigLexicon_W::APPID, 'key_warning', ''));
+ }
+
+ 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', ''));
+ }
+
+ public function testUserLexiconGetException() {
+ $this->expectException(UnknownKeyException::class);
+ $this->userConfig->getValueString('user1', TestConfigLexicon_E::APPID, 'key_exception');
+ }
+}
diff --git a/tests/lib/Config/TestConfigLexicon_E.php b/tests/lib/Config/TestConfigLexicon_E.php
new file mode 100644
index 00000000000..e0890cbd76e
--- /dev/null
+++ b/tests/lib/Config/TestConfigLexicon_E.php
@@ -0,0 +1,38 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+namespace Tests\lib\Config;
+
+use NCU\Config\IUserConfig;
+use NCU\Config\Lexicon\ConfigLexiconEntry;
+use NCU\Config\Lexicon\ConfigLexiconStrictness;
+use NCU\Config\Lexicon\IConfigLexicon;
+use NCU\Config\ValueType;
+use OCP\IAppConfig;
+
+class TestConfigLexicon_E implements IConfigLexicon {
+ public const APPID = 'lexicon_test_e';
+
+ public function getStrictness(): ConfigLexiconStrictness {
+ return ConfigLexiconStrictness::EXCEPTION;
+ }
+
+ 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)
+ ];
+ }
+
+ public function getUserConfigs(): array {
+ return [
+ new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
+ ];
+ }
+}
diff --git a/tests/lib/Config/TestConfigLexicon_I.php b/tests/lib/Config/TestConfigLexicon_I.php
new file mode 100644
index 00000000000..497c62acecb
--- /dev/null
+++ b/tests/lib/Config/TestConfigLexicon_I.php
@@ -0,0 +1,40 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+namespace Tests\lib\Config;
+
+use NCU\Config\IUserConfig;
+use NCU\Config\Lexicon\ConfigLexiconEntry;
+use NCU\Config\Lexicon\ConfigLexiconStrictness;
+use NCU\Config\Lexicon\IConfigLexicon;
+use NCU\Config\ValueType;
+use OCP\IAppConfig;
+
+class TestConfigLexicon_I implements IConfigLexicon {
+ public const APPID = 'lexicon_test_i';
+
+ public function getStrictness(): ConfigLexiconStrictness {
+ return ConfigLexiconStrictness::IGNORE;
+ }
+
+ 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)
+
+ ];
+ }
+
+ public function getUserConfigs(): array {
+ return [
+ new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
+ ];
+ }
+
+}
diff --git a/tests/lib/Config/TestConfigLexicon_N.php b/tests/lib/Config/TestConfigLexicon_N.php
new file mode 100644
index 00000000000..4d96fe9b10d
--- /dev/null
+++ b/tests/lib/Config/TestConfigLexicon_N.php
@@ -0,0 +1,39 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+namespace Tests\lib\Config;
+
+use NCU\Config\IUserConfig;
+use NCU\Config\Lexicon\ConfigLexiconEntry;
+use NCU\Config\Lexicon\ConfigLexiconStrictness;
+use NCU\Config\Lexicon\IConfigLexicon;
+use NCU\Config\ValueType;
+use OCP\IAppConfig;
+
+class TestConfigLexicon_N implements IConfigLexicon {
+ public const APPID = 'lexicon_test_n';
+
+ public function getStrictness(): ConfigLexiconStrictness {
+ return ConfigLexiconStrictness::NOTICE;
+ }
+
+ 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)
+ ];
+ }
+
+ public function getUserConfigs(): array {
+ return [
+ new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false)
+ ];
+ }
+
+}
diff --git a/tests/lib/Config/TestConfigLexicon_W.php b/tests/lib/Config/TestConfigLexicon_W.php
new file mode 100644
index 00000000000..d4242db0682
--- /dev/null
+++ b/tests/lib/Config/TestConfigLexicon_W.php
@@ -0,0 +1,39 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-only
+ */
+
+namespace Tests\lib\Config;
+
+use NCU\Config\IUserConfig;
+use NCU\Config\Lexicon\ConfigLexiconEntry;
+use NCU\Config\Lexicon\ConfigLexiconStrictness;
+use NCU\Config\Lexicon\IConfigLexicon;
+use NCU\Config\ValueType;
+use OCP\IAppConfig;
+
+class TestConfigLexicon_W implements IConfigLexicon {
+ public const APPID = 'lexicon_test_w';
+
+ public function getStrictness(): ConfigLexiconStrictness {
+ return ConfigLexiconStrictness::WARNING;
+ }
+
+ 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)
+
+ ];
+ }
+
+ public function getUserConfigs(): array {
+ return [
+ new ConfigLexiconEntry('key1', ValueType::STRING, 'abcde', 'test key', true, IUserConfig::FLAG_SENSITIVE),
+ new ConfigLexiconEntry('key2', ValueType::INT, 12345, 'test key', false) ];
+ }
+
+}
diff --git a/tests/lib/Config/UserConfigTest.php b/tests/lib/Config/UserConfigTest.php
index a79e1e59a79..e727116d9a8 100644
--- a/tests/lib/Config/UserConfigTest.php
+++ b/tests/lib/Config/UserConfigTest.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
-namespace lib\Config;
+namespace Test\lib\Config;
use NCU\Config\Exceptions\TypeConflictException;
use NCU\Config\Exceptions\UnknownKeyException;
@@ -748,7 +748,7 @@ class UserConfigTest extends TestCase {
string $key,
?ValueType $typedAs = null,
?array $userIds = null,
- array $result,
+ array $result = [],
): void {
$userConfig = $this->generateUserConfig();
$this->assertEqualsCanonicalizing(