123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464 |
- <?php
- declare(strict_types=1);
- /**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-only
- */
- namespace Test;
- use InvalidArgumentException;
- use OC\AppConfig;
- use OCP\Exceptions\AppConfigTypeConflictException;
- use OCP\Exceptions\AppConfigUnknownKeyException;
- use OCP\IAppConfig;
- use OCP\IDBConnection;
- use OCP\Security\ICrypto;
- use Psr\Log\LoggerInterface;
- /**
- * Class AppConfigTest
- *
- * @group DB
- *
- * @package Test
- */
- class AppConfigTest extends TestCase {
- protected IAppConfig $appConfig;
- protected IDBConnection $connection;
- private LoggerInterface $logger;
- private ICrypto $crypto;
- private array $originalConfig;
- /**
- * @var array<string, array<array<string, string, int, bool, bool>>>
- * [appId => [configKey, configValue, valueType, lazy, sensitive]]
- */
- private array $baseStruct =
- [
- 'testapp' => [
- 'enabled' => ['enabled', 'true'],
- 'installed_version' => ['installed_version', '1.2.3'],
- 'depends_on' => ['depends_on', 'someapp'],
- 'deletethis' => ['deletethis', 'deletethis'],
- 'key' => ['key', 'value']
- ],
- 'someapp' => [
- 'key' => ['key', 'value'],
- 'otherkey' => ['otherkey', 'othervalue']
- ],
- '123456' => [
- 'enabled' => ['enabled', 'true'],
- 'key' => ['key', 'value']
- ],
- 'anotherapp' => [
- 'enabled' => ['enabled', 'false'],
- 'key' => ['key', 'value']
- ],
- 'non-sensitive-app' => [
- 'lazy-key' => ['lazy-key', 'value', IAppConfig::VALUE_STRING, true, false],
- 'non-lazy-key' => ['non-lazy-key', 'value', IAppConfig::VALUE_STRING, false, false],
- ],
- 'sensitive-app' => [
- 'lazy-key' => ['lazy-key', 'value', IAppConfig::VALUE_STRING, true, true],
- 'non-lazy-key' => ['non-lazy-key', 'value', IAppConfig::VALUE_STRING, false, true],
- ],
- 'only-lazy' => [
- 'lazy-key' => ['lazy-key', 'value', IAppConfig::VALUE_STRING, true]
- ],
- 'typed' => [
- 'mixed' => ['mixed', 'mix', IAppConfig::VALUE_MIXED],
- 'string' => ['string', 'value', IAppConfig::VALUE_STRING],
- 'int' => ['int', '42', IAppConfig::VALUE_INT],
- 'float' => ['float', '3.14', IAppConfig::VALUE_FLOAT],
- 'bool' => ['bool', '1', IAppConfig::VALUE_BOOL],
- 'array' => ['array', '{"test": 1}', IAppConfig::VALUE_ARRAY],
- ],
- 'prefix-app' => [
- 'key1' => ['key1', 'value'],
- 'prefix1' => ['prefix1', 'value'],
- 'prefix-2' => ['prefix-2', 'value'],
- 'key-2' => ['key-2', 'value'],
- ]
- ];
- protected function setUp(): void {
- parent::setUp();
- $this->connection = \OCP\Server::get(IDBConnection::class);
- $this->logger = \OCP\Server::get(LoggerInterface::class);
- $this->crypto = \OCP\Server::get(ICrypto::class);
- // storing current config and emptying the data table
- $sql = $this->connection->getQueryBuilder();
- $sql->select('*')
- ->from('appconfig');
- $result = $sql->executeQuery();
- $this->originalConfig = $result->fetchAll();
- $result->closeCursor();
- $sql = $this->connection->getQueryBuilder();
- $sql->delete('appconfig');
- $sql->executeStatement();
- $sql = $this->connection->getQueryBuilder();
- $sql->insert('appconfig')
- ->values(
- [
- 'appid' => $sql->createParameter('appid'),
- 'configkey' => $sql->createParameter('configkey'),
- 'configvalue' => $sql->createParameter('configvalue'),
- 'type' => $sql->createParameter('type'),
- 'lazy' => $sql->createParameter('lazy')
- ]
- );
- foreach ($this->baseStruct as $appId => $appData) {
- foreach ($appData as $key => $row) {
- $value = $row[1];
- $type = $row[2] ?? IAppConfig::VALUE_MIXED;
- if (($row[4] ?? false) === true) {
- $type |= IAppConfig::VALUE_SENSITIVE;
- $value = self::invokePrivate(AppConfig::class, 'ENCRYPTION_PREFIX') . $this->crypto->encrypt($value);
- $this->baseStruct[$appId][$key]['encrypted'] = $value;
- }
- $sql->setParameters(
- [
- 'appid' => $appId,
- 'configkey' => $row[0],
- 'configvalue' => $value,
- 'type' => $type,
- 'lazy' => (($row[3] ?? false) === true) ? 1 : 0
- ]
- )->executeStatement();
- }
- }
- }
- protected function tearDown(): void {
- $sql = $this->connection->getQueryBuilder();
- $sql->delete('appconfig');
- $sql->executeStatement();
- $sql = $this->connection->getQueryBuilder();
- $sql->insert('appconfig')
- ->values(
- [
- 'appid' => $sql->createParameter('appid'),
- 'configkey' => $sql->createParameter('configkey'),
- 'configvalue' => $sql->createParameter('configvalue'),
- 'lazy' => $sql->createParameter('lazy'),
- 'type' => $sql->createParameter('type'),
- ]
- );
- foreach ($this->originalConfig as $key => $configs) {
- $sql->setParameter('appid', $configs['appid'])
- ->setParameter('configkey', $configs['configkey'])
- ->setParameter('configvalue', $configs['configvalue'])
- ->setParameter('lazy', ($configs['lazy'] === '1') ? '1' : '0')
- ->setParameter('type', $configs['type']);
- $sql->executeStatement();
- }
- // $this->restoreService(AppConfig::class);
- parent::tearDown();
- }
- /**
- * @param bool $preLoading TRUE will preload the 'fast' cache, which is the normal behavior of usual
- * IAppConfig
- *
- * @return IAppConfig
- */
- private function generateAppConfig(bool $preLoading = true): IAppConfig {
- /** @var AppConfig $config */
- $config = new \OC\AppConfig(
- $this->connection,
- $this->logger,
- $this->crypto,
- );
- $msg = ' generateAppConfig() failed to confirm cache status';
- // confirm cache status
- $status = $config->statusCache();
- $this->assertSame(false, $status['fastLoaded'], $msg);
- $this->assertSame(false, $status['lazyLoaded'], $msg);
- $this->assertSame([], $status['fastCache'], $msg);
- $this->assertSame([], $status['lazyCache'], $msg);
- if ($preLoading) {
- // simple way to initiate the load of non-lazy config values in cache
- $config->getValueString('core', 'preload', '');
- // confirm cache status
- $status = $config->statusCache();
- $this->assertSame(true, $status['fastLoaded'], $msg);
- $this->assertSame(false, $status['lazyLoaded'], $msg);
- $apps = array_values(array_diff(array_keys($this->baseStruct), ['only-lazy']));
- $this->assertEqualsCanonicalizing($apps, array_keys($status['fastCache']), $msg);
- $this->assertSame([], array_keys($status['lazyCache']), $msg);
- }
- return $config;
- }
- public function testGetApps(): void {
- $config = $this->generateAppConfig(false);
- $this->assertEqualsCanonicalizing(array_keys($this->baseStruct), $config->getApps());
- }
- /**
- * returns list of app and their keys
- *
- * @return array<string, string[]> ['appId' => ['key1', 'key2', ]]
- * @see testGetKeys
- */
- public function providerGetAppKeys(): array {
- $appKeys = [];
- foreach ($this->baseStruct as $appId => $appData) {
- $keys = [];
- foreach ($appData as $row) {
- $keys[] = $row[0];
- }
- $appKeys[] = [(string)$appId, $keys];
- }
- return $appKeys;
- }
- /**
- * returns list of config keys
- *
- * @return array<string, string, string, int, bool, bool> [appId, key, value, type, lazy, sensitive]
- * @see testIsSensitive
- * @see testIsLazy
- * @see testGetKeys
- */
- public function providerGetKeys(): array {
- $appKeys = [];
- foreach ($this->baseStruct as $appId => $appData) {
- foreach ($appData as $row) {
- $appKeys[] = [
- (string)$appId, $row[0], $row[1], $row[2] ?? IAppConfig::VALUE_MIXED, $row[3] ?? false,
- $row[4] ?? false
- ];
- }
- }
- return $appKeys;
- }
- /**
- * @dataProvider providerGetAppKeys
- *
- * @param string $appId
- * @param array $expectedKeys
- */
- public function testGetKeys(string $appId, array $expectedKeys): void {
- $config = $this->generateAppConfig();
- $this->assertEqualsCanonicalizing($expectedKeys, $config->getKeys($appId));
- }
- public function testGetKeysOnUnknownAppShouldReturnsEmptyArray(): void {
- $config = $this->generateAppConfig();
- $this->assertEqualsCanonicalizing([], $config->getKeys('unknown-app'));
- }
- /**
- * @dataProvider providerGetKeys
- *
- * @param string $appId
- * @param string $configKey
- * @param string $value
- * @param bool $lazy
- */
- public function testHasKey(string $appId, string $configKey, string $value, int $type, bool $lazy): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(true, $config->hasKey($appId, $configKey, $lazy));
- }
- public function testHasKeyOnNonExistentKeyReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(false, $config->hasKey(array_keys($this->baseStruct)[0], 'inexistant-key'));
- }
- public function testHasKeyOnUnknownAppReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(false, $config->hasKey('inexistant-app', 'inexistant-key'));
- }
- public function testHasKeyOnMistypedAsLazyReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->hasKey('non-sensitive-app', 'non-lazy-key', true));
- }
- public function testHasKeyOnMistypeAsNonLazyReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->hasKey('non-sensitive-app', 'lazy-key', false));
- }
- public function testHasKeyOnMistypeAsNonLazyReturnsTrueWithLazyArgumentIsNull(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(true, $config->hasKey('non-sensitive-app', 'lazy-key', null));
- }
- /**
- * @dataProvider providerGetKeys
- */
- public function testIsSensitive(
- string $appId, string $configKey, string $configValue, int $type, bool $lazy, bool $sensitive,
- ): void {
- $config = $this->generateAppConfig();
- $this->assertEquals($sensitive, $config->isSensitive($appId, $configKey, $lazy));
- }
- public function testIsSensitiveOnNonExistentKeyThrowsException(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->isSensitive(array_keys($this->baseStruct)[0], 'inexistant-key');
- }
- public function testIsSensitiveOnUnknownAppThrowsException(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->isSensitive('unknown-app', 'inexistant-key');
- }
- public function testIsSensitiveOnSensitiveMistypedAsLazy(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(true, $config->isSensitive('sensitive-app', 'non-lazy-key', true));
- }
- public function testIsSensitiveOnNonSensitiveMistypedAsLazy(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->isSensitive('non-sensitive-app', 'non-lazy-key', true));
- }
- public function testIsSensitiveOnSensitiveMistypedAsNonLazyThrowsException(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->isSensitive('sensitive-app', 'lazy-key', false);
- }
- public function testIsSensitiveOnNonSensitiveMistypedAsNonLazyThrowsException(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->isSensitive('non-sensitive-app', 'lazy-key', false);
- }
- /**
- * @dataProvider providerGetKeys
- */
- public function testIsLazy(string $appId, string $configKey, string $configValue, int $type, bool $lazy,
- ): void {
- $config = $this->generateAppConfig();
- $this->assertEquals($lazy, $config->isLazy($appId, $configKey));
- }
- public function testIsLazyOnNonExistentKeyThrowsException(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->isLazy(array_keys($this->baseStruct)[0], 'inexistant-key');
- }
- public function testIsLazyOnUnknownAppThrowsException(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->isLazy('unknown-app', 'inexistant-key');
- }
- public function testGetAllValues(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(
- [
- 'array' => ['test' => 1],
- 'bool' => true,
- 'float' => 3.14,
- 'int' => 42,
- 'mixed' => 'mix',
- 'string' => 'value',
- ],
- $config->getAllValues('typed')
- );
- }
- public function testGetAllValuesWithEmptyApp(): void {
- $config = $this->generateAppConfig();
- $this->expectException(InvalidArgumentException::class);
- $config->getAllValues('');
- }
- /**
- * @dataProvider providerGetAppKeys
- *
- * @param string $appId
- * @param array $keys
- */
- public function testGetAllValuesWithEmptyKey(string $appId, array $keys): void {
- $config = $this->generateAppConfig();
- $this->assertEqualsCanonicalizing($keys, array_keys($config->getAllValues($appId, '')));
- }
- public function testGetAllValuesWithPrefix(): void {
- $config = $this->generateAppConfig();
- $this->assertEqualsCanonicalizing(['prefix1', 'prefix-2'], array_keys($config->getAllValues('prefix-app', 'prefix')));
- }
- public function testSearchValues(): void {
- $config = $this->generateAppConfig();
- $this->assertEqualsCanonicalizing(['testapp' => 'true', '123456' => 'true', 'anotherapp' => 'false'], $config->searchValues('enabled'));
- }
- public function testGetValueString(): void {
- $config = $this->generateAppConfig();
- $this->assertSame('value', $config->getValueString('typed', 'string', ''));
- }
- public function testGetValueStringOnUnknownAppReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame('default-1', $config->getValueString('typed-1', 'string', 'default-1'));
- }
- public function testGetValueStringOnNonExistentKeyReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame('default-2', $config->getValueString('typed', 'string-2', 'default-2'));
- }
- public function testGetValueStringOnWrongType(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigTypeConflictException::class);
- $config->getValueString('typed', 'int');
- }
- public function testGetNonLazyValueStringAsLazy(): void {
- $config = $this->generateAppConfig();
- $this->assertSame('value', $config->getValueString('non-sensitive-app', 'non-lazy-key', 'default', lazy: true));
- }
- public function testGetValueInt(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(42, $config->getValueInt('typed', 'int', 0));
- }
- public function testGetValueIntOnUnknownAppReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(1, $config->getValueInt('typed-1', 'int', 1));
- }
- public function testGetValueIntOnNonExistentKeyReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(2, $config->getValueInt('typed', 'int-2', 2));
- }
- public function testGetValueIntOnWrongType(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigTypeConflictException::class);
- $config->getValueInt('typed', 'float');
- }
- public function testGetValueFloat(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(3.14, $config->getValueFloat('typed', 'float', 0));
- }
- public function testGetValueFloatOnNonUnknownAppReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(1.11, $config->getValueFloat('typed-1', 'float', 1.11));
- }
- public function testGetValueFloatOnNonExistentKeyReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(2.22, $config->getValueFloat('typed', 'float-2', 2.22));
- }
- public function testGetValueFloatOnWrongType(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigTypeConflictException::class);
- $config->getValueFloat('typed', 'bool');
- }
- public function testGetValueBool(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(true, $config->getValueBool('typed', 'bool'));
- }
- public function testGetValueBoolOnUnknownAppReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->getValueBool('typed-1', 'bool', false));
- }
- public function testGetValueBoolOnNonExistentKeyReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->getValueBool('typed', 'bool-2'));
- }
- public function testGetValueBoolOnWrongType(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigTypeConflictException::class);
- $config->getValueBool('typed', 'array');
- }
- public function testGetValueArray(): void {
- $config = $this->generateAppConfig();
- $this->assertEqualsCanonicalizing(['test' => 1], $config->getValueArray('typed', 'array', []));
- }
- public function testGetValueArrayOnUnknownAppReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame([1], $config->getValueArray('typed-1', 'array', [1]));
- }
- public function testGetValueArrayOnNonExistentKeyReturnsDefault(): void {
- $config = $this->generateAppConfig();
- $this->assertSame([1, 2], $config->getValueArray('typed', 'array-2', [1, 2]));
- }
- public function testGetValueArrayOnWrongType(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigTypeConflictException::class);
- $config->getValueArray('typed', 'string');
- }
- /**
- * @return array
- * @see testGetValueType
- *
- * @see testGetValueMixed
- */
- public function providerGetValueMixed(): array {
- return [
- // key, value, type
- ['mixed', 'mix', IAppConfig::VALUE_MIXED],
- ['string', 'value', IAppConfig::VALUE_STRING],
- ['int', '42', IAppConfig::VALUE_INT],
- ['float', '3.14', IAppConfig::VALUE_FLOAT],
- ['bool', '1', IAppConfig::VALUE_BOOL],
- ['array', '{"test": 1}', IAppConfig::VALUE_ARRAY],
- ];
- }
- /**
- * @dataProvider providerGetValueMixed
- *
- * @param string $key
- * @param string $value
- */
- public function testGetValueMixed(string $key, string $value): void {
- $config = $this->generateAppConfig();
- $this->assertSame($value, $config->getValueMixed('typed', $key));
- }
- /**
- * @dataProvider providerGetValueMixed
- *
- * @param string $key
- * @param string $value
- * @param int $type
- */
- public function testGetValueType(string $key, string $value, int $type): void {
- $config = $this->generateAppConfig();
- $this->assertSame($type, $config->getValueType('typed', $key));
- }
- public function testGetValueTypeOnUnknownApp(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->getValueType('typed-1', 'string');
- }
- public function testGetValueTypeOnNonExistentKey(): void {
- $config = $this->generateAppConfig();
- $this->expectException(AppConfigUnknownKeyException::class);
- $config->getValueType('typed', 'string-2');
- }
- public function testSetValueString(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1');
- $this->assertSame('value-1', $config->getValueString('feed', 'string', ''));
- }
- public function testSetValueStringCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1');
- $status = $config->statusCache();
- $this->assertSame('value-1', $status['fastCache']['feed']['string']);
- }
- public function testSetValueStringDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1');
- $config->clearCache();
- $this->assertSame('value-1', $config->getValueString('feed', 'string', ''));
- }
- public function testSetValueStringIsUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1');
- $this->assertSame(true, $config->setValueString('feed', 'string', 'value-2'));
- }
- public function testSetValueStringIsNotUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1');
- $this->assertSame(false, $config->setValueString('feed', 'string', 'value-1'));
- }
- public function testSetValueStringIsUpdatedCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1');
- $config->setValueString('feed', 'string', 'value-2');
- $status = $config->statusCache();
- $this->assertSame('value-2', $status['fastCache']['feed']['string']);
- }
- public function testSetValueStringIsUpdatedDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1');
- $config->setValueString('feed', 'string', 'value-2');
- $config->clearCache();
- $this->assertSame('value-2', $config->getValueString('feed', 'string', ''));
- }
- public function testSetValueInt(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0));
- }
- public function testSetValueIntCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $status = $config->statusCache();
- $this->assertSame('42', $status['fastCache']['feed']['int']);
- }
- public function testSetValueIntDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $config->clearCache();
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0));
- }
- public function testSetValueIntIsUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $this->assertSame(true, $config->setValueInt('feed', 'int', 17));
- }
- public function testSetValueIntIsNotUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $this->assertSame(false, $config->setValueInt('feed', 'int', 42));
- }
- public function testSetValueIntIsUpdatedCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $config->setValueInt('feed', 'int', 17);
- $status = $config->statusCache();
- $this->assertSame('17', $status['fastCache']['feed']['int']);
- }
- public function testSetValueIntIsUpdatedDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $config->setValueInt('feed', 'int', 17);
- $config->clearCache();
- $this->assertSame(17, $config->getValueInt('feed', 'int', 0));
- }
- public function testSetValueFloat(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0));
- }
- public function testSetValueFloatCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $status = $config->statusCache();
- $this->assertSame('3.14', $status['fastCache']['feed']['float']);
- }
- public function testSetValueFloatDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $config->clearCache();
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0));
- }
- public function testSetValueFloatIsUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $this->assertSame(true, $config->setValueFloat('feed', 'float', 1.23));
- }
- public function testSetValueFloatIsNotUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $this->assertSame(false, $config->setValueFloat('feed', 'float', 3.14));
- }
- public function testSetValueFloatIsUpdatedCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $config->setValueFloat('feed', 'float', 1.23);
- $status = $config->statusCache();
- $this->assertSame('1.23', $status['fastCache']['feed']['float']);
- }
- public function testSetValueFloatIsUpdatedDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $config->setValueFloat('feed', 'float', 1.23);
- $config->clearCache();
- $this->assertSame(1.23, $config->getValueFloat('feed', 'float', 0));
- }
- public function testSetValueBool(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true);
- $this->assertSame(true, $config->getValueBool('feed', 'bool', false));
- }
- public function testSetValueBoolCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true);
- $status = $config->statusCache();
- $this->assertSame('1', $status['fastCache']['feed']['bool']);
- }
- public function testSetValueBoolDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true);
- $config->clearCache();
- $this->assertSame(true, $config->getValueBool('feed', 'bool', false));
- }
- public function testSetValueBoolIsUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true);
- $this->assertSame(true, $config->setValueBool('feed', 'bool', false));
- }
- public function testSetValueBoolIsNotUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true);
- $this->assertSame(false, $config->setValueBool('feed', 'bool', true));
- }
- public function testSetValueBoolIsUpdatedCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true);
- $config->setValueBool('feed', 'bool', false);
- $status = $config->statusCache();
- $this->assertSame('0', $status['fastCache']['feed']['bool']);
- }
- public function testSetValueBoolIsUpdatedDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true);
- $config->setValueBool('feed', 'bool', false);
- $config->clearCache();
- $this->assertSame(false, $config->getValueBool('feed', 'bool', true));
- }
- public function testSetValueArray(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $this->assertSame(['test' => 1], $config->getValueArray('feed', 'array', []));
- }
- public function testSetValueArrayCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $status = $config->statusCache();
- $this->assertSame('{"test":1}', $status['fastCache']['feed']['array']);
- }
- public function testSetValueArrayDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $config->clearCache();
- $this->assertSame(['test' => 1], $config->getValueArray('feed', 'array', []));
- }
- public function testSetValueArrayIsUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $this->assertSame(true, $config->setValueArray('feed', 'array', ['test' => 2]));
- }
- public function testSetValueArrayIsNotUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $this->assertSame(false, $config->setValueArray('feed', 'array', ['test' => 1]));
- }
- public function testSetValueArrayIsUpdatedCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $config->setValueArray('feed', 'array', ['test' => 2]);
- $status = $config->statusCache();
- $this->assertSame('{"test":2}', $status['fastCache']['feed']['array']);
- }
- public function testSetValueArrayIsUpdatedDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $config->setValueArray('feed', 'array', ['test' => 2]);
- $config->clearCache();
- $this->assertSame(['test' => 2], $config->getValueArray('feed', 'array', []));
- }
- public function testSetLazyValueString(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', true);
- $this->assertSame('value-1', $config->getValueString('feed', 'string', '', true));
- }
- public function testSetLazyValueStringCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', true);
- $status = $config->statusCache();
- $this->assertSame('value-1', $status['lazyCache']['feed']['string']);
- }
- public function testSetLazyValueStringDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', true);
- $config->clearCache();
- $this->assertSame('value-1', $config->getValueString('feed', 'string', '', true));
- }
- public function testSetLazyValueStringAsNonLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', true);
- $config->setValueString('feed', 'string', 'value-1', false);
- $this->assertSame('value-1', $config->getValueString('feed', 'string', ''));
- }
- public function testSetNonLazyValueStringAsLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', false);
- $config->setValueString('feed', 'string', 'value-1', true);
- $this->assertSame('value-1', $config->getValueString('feed', 'string', '', true));
- }
- public function testSetSensitiveValueString(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', sensitive: true);
- $this->assertSame('value-1', $config->getValueString('feed', 'string', ''));
- }
- public function testSetSensitiveValueStringCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', sensitive: true);
- $status = $config->statusCache();
- $this->assertStringStartsWith(self::invokePrivate(AppConfig::class, 'ENCRYPTION_PREFIX'), $status['fastCache']['feed']['string']);
- }
- public function testSetSensitiveValueStringDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', sensitive: true);
- $config->clearCache();
- $this->assertSame('value-1', $config->getValueString('feed', 'string', ''));
- }
- public function testSetNonSensitiveValueStringAsSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', sensitive: false);
- $config->setValueString('feed', 'string', 'value-1', sensitive: true);
- $this->assertSame(true, $config->isSensitive('feed', 'string'));
- $this->assertConfigValueNotEquals('feed', 'string', 'value-1');
- $this->assertConfigValueNotEquals('feed', 'string', 'value-2');
- }
- public function testSetSensitiveValueStringAsNonSensitiveStaysSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', sensitive: true);
- $config->setValueString('feed', 'string', 'value-2', sensitive: false);
- $this->assertSame(true, $config->isSensitive('feed', 'string'));
- $this->assertConfigValueNotEquals('feed', 'string', 'value-1');
- $this->assertConfigValueNotEquals('feed', 'string', 'value-2');
- }
- public function testSetSensitiveValueStringAsNonSensitiveAreStillUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', 'value-1', sensitive: true);
- $config->setValueString('feed', 'string', 'value-2', sensitive: false);
- $this->assertSame('value-2', $config->getValueString('feed', 'string', ''));
- $this->assertConfigValueNotEquals('feed', 'string', 'value-1');
- $this->assertConfigValueNotEquals('feed', 'string', 'value-2');
- }
- public function testSetLazyValueInt(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, true);
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0, true));
- }
- public function testSetLazyValueIntCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, true);
- $status = $config->statusCache();
- $this->assertSame('42', $status['lazyCache']['feed']['int']);
- }
- public function testSetLazyValueIntDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, true);
- $config->clearCache();
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0, true));
- }
- public function testSetLazyValueIntAsNonLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, true);
- $config->setValueInt('feed', 'int', 42, false);
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0));
- }
- public function testSetNonLazyValueIntAsLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, false);
- $config->setValueInt('feed', 'int', 42, true);
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0, true));
- }
- public function testSetSensitiveValueInt(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, sensitive: true);
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0));
- }
- public function testSetSensitiveValueIntCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, sensitive: true);
- $status = $config->statusCache();
- $this->assertStringStartsWith(self::invokePrivate(AppConfig::class, 'ENCRYPTION_PREFIX'), $status['fastCache']['feed']['int']);
- }
- public function testSetSensitiveValueIntDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, sensitive: true);
- $config->clearCache();
- $this->assertSame(42, $config->getValueInt('feed', 'int', 0));
- }
- public function testSetNonSensitiveValueIntAsSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42);
- $config->setValueInt('feed', 'int', 42, sensitive: true);
- $this->assertSame(true, $config->isSensitive('feed', 'int'));
- }
- public function testSetSensitiveValueIntAsNonSensitiveStaysSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, sensitive: true);
- $config->setValueInt('feed', 'int', 17);
- $this->assertSame(true, $config->isSensitive('feed', 'int'));
- }
- public function testSetSensitiveValueIntAsNonSensitiveAreStillUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueInt('feed', 'int', 42, sensitive: true);
- $config->setValueInt('feed', 'int', 17);
- $this->assertSame(17, $config->getValueInt('feed', 'int', 0));
- }
- public function testSetLazyValueFloat(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, true);
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0, true));
- }
- public function testSetLazyValueFloatCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, true);
- $status = $config->statusCache();
- $this->assertSame('3.14', $status['lazyCache']['feed']['float']);
- }
- public function testSetLazyValueFloatDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, true);
- $config->clearCache();
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0, true));
- }
- public function testSetLazyValueFloatAsNonLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, true);
- $config->setValueFloat('feed', 'float', 3.14, false);
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0));
- }
- public function testSetNonLazyValueFloatAsLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, false);
- $config->setValueFloat('feed', 'float', 3.14, true);
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0, true));
- }
- public function testSetSensitiveValueFloat(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, sensitive: true);
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0));
- }
- public function testSetSensitiveValueFloatCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, sensitive: true);
- $status = $config->statusCache();
- $this->assertStringStartsWith(self::invokePrivate(AppConfig::class, 'ENCRYPTION_PREFIX'), $status['fastCache']['feed']['float']);
- }
- public function testSetSensitiveValueFloatDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, sensitive: true);
- $config->clearCache();
- $this->assertSame(3.14, $config->getValueFloat('feed', 'float', 0));
- }
- public function testSetNonSensitiveValueFloatAsSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14);
- $config->setValueFloat('feed', 'float', 3.14, sensitive: true);
- $this->assertSame(true, $config->isSensitive('feed', 'float'));
- }
- public function testSetSensitiveValueFloatAsNonSensitiveStaysSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, sensitive: true);
- $config->setValueFloat('feed', 'float', 1.23);
- $this->assertSame(true, $config->isSensitive('feed', 'float'));
- }
- public function testSetSensitiveValueFloatAsNonSensitiveAreStillUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueFloat('feed', 'float', 3.14, sensitive: true);
- $config->setValueFloat('feed', 'float', 1.23);
- $this->assertSame(1.23, $config->getValueFloat('feed', 'float', 0));
- }
- public function testSetLazyValueBool(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true, true);
- $this->assertSame(true, $config->getValueBool('feed', 'bool', false, true));
- }
- public function testSetLazyValueBoolCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true, true);
- $status = $config->statusCache();
- $this->assertSame('1', $status['lazyCache']['feed']['bool']);
- }
- public function testSetLazyValueBoolDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true, true);
- $config->clearCache();
- $this->assertSame(true, $config->getValueBool('feed', 'bool', false, true));
- }
- public function testSetLazyValueBoolAsNonLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true, true);
- $config->setValueBool('feed', 'bool', true, false);
- $this->assertSame(true, $config->getValueBool('feed', 'bool', false));
- }
- public function testSetNonLazyValueBoolAsLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueBool('feed', 'bool', true, false);
- $config->setValueBool('feed', 'bool', true, true);
- $this->assertSame(true, $config->getValueBool('feed', 'bool', false, true));
- }
- public function testSetLazyValueArray(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], true);
- $this->assertSame(['test' => 1], $config->getValueArray('feed', 'array', [], true));
- }
- public function testSetLazyValueArrayCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], true);
- $status = $config->statusCache();
- $this->assertSame('{"test":1}', $status['lazyCache']['feed']['array']);
- }
- public function testSetLazyValueArrayDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], true);
- $config->clearCache();
- $this->assertSame(['test' => 1], $config->getValueArray('feed', 'array', [], true));
- }
- public function testSetLazyValueArrayAsNonLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], true);
- $config->setValueArray('feed', 'array', ['test' => 1], false);
- $this->assertSame(['test' => 1], $config->getValueArray('feed', 'array', []));
- }
- public function testSetNonLazyValueArrayAsLazy(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], false);
- $config->setValueArray('feed', 'array', ['test' => 1], true);
- $this->assertSame(['test' => 1], $config->getValueArray('feed', 'array', [], true));
- }
- public function testSetSensitiveValueArray(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], sensitive: true);
- $this->assertEqualsCanonicalizing(['test' => 1], $config->getValueArray('feed', 'array', []));
- }
- public function testSetSensitiveValueArrayCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], sensitive: true);
- $status = $config->statusCache();
- $this->assertStringStartsWith(self::invokePrivate(AppConfig::class, 'ENCRYPTION_PREFIX'), $status['fastCache']['feed']['array']);
- }
- public function testSetSensitiveValueArrayDatabase(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], sensitive: true);
- $config->clearCache();
- $this->assertEqualsCanonicalizing(['test' => 1], $config->getValueArray('feed', 'array', []));
- }
- public function testSetNonSensitiveValueArrayAsSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1]);
- $config->setValueArray('feed', 'array', ['test' => 1], sensitive: true);
- $this->assertSame(true, $config->isSensitive('feed', 'array'));
- }
- public function testSetSensitiveValueArrayAsNonSensitiveStaysSensitive(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], sensitive: true);
- $config->setValueArray('feed', 'array', ['test' => 2]);
- $this->assertSame(true, $config->isSensitive('feed', 'array'));
- }
- public function testSetSensitiveValueArrayAsNonSensitiveAreStillUpdated(): void {
- $config = $this->generateAppConfig();
- $config->setValueArray('feed', 'array', ['test' => 1], sensitive: true);
- $config->setValueArray('feed', 'array', ['test' => 2]);
- $this->assertEqualsCanonicalizing(['test' => 2], $config->getValueArray('feed', 'array', []));
- }
- public function testUpdateNotSensitiveToSensitive(): void {
- $config = $this->generateAppConfig();
- $config->updateSensitive('non-sensitive-app', 'lazy-key', true);
- $this->assertSame(true, $config->isSensitive('non-sensitive-app', 'lazy-key', true));
- }
- public function testUpdateSensitiveToNotSensitive(): void {
- $config = $this->generateAppConfig();
- $config->updateSensitive('sensitive-app', 'lazy-key', false);
- $this->assertSame(false, $config->isSensitive('sensitive-app', 'lazy-key', true));
- }
- public function testUpdateSensitiveToSensitiveReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->updateSensitive('sensitive-app', 'lazy-key', true));
- }
- public function testUpdateNotSensitiveToNotSensitiveReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->updateSensitive('non-sensitive-app', 'lazy-key', false));
- }
- public function testUpdateSensitiveOnUnknownKeyReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->updateSensitive('non-sensitive-app', 'unknown-key', true));
- }
- public function testUpdateNotLazyToLazy(): void {
- $config = $this->generateAppConfig();
- $config->updateLazy('non-sensitive-app', 'non-lazy-key', true);
- $this->assertSame(true, $config->isLazy('non-sensitive-app', 'non-lazy-key'));
- }
- public function testUpdateLazyToNotLazy(): void {
- $config = $this->generateAppConfig();
- $config->updateLazy('non-sensitive-app', 'lazy-key', false);
- $this->assertSame(false, $config->isLazy('non-sensitive-app', 'lazy-key'));
- }
- public function testUpdateLazyToLazyReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->updateLazy('non-sensitive-app', 'lazy-key', true));
- }
- public function testUpdateNotLazyToNotLazyReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->updateLazy('non-sensitive-app', 'non-lazy-key', false));
- }
- public function testUpdateLazyOnUnknownKeyReturnsFalse(): void {
- $config = $this->generateAppConfig();
- $this->assertSame(false, $config->updateLazy('non-sensitive-app', 'unknown-key', true));
- }
- public function testGetDetails(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(
- [
- 'app' => 'non-sensitive-app',
- 'key' => 'lazy-key',
- 'value' => 'value',
- 'type' => 4,
- 'lazy' => true,
- 'typeString' => 'string',
- 'sensitive' => false,
- ],
- $config->getDetails('non-sensitive-app', 'lazy-key')
- );
- }
- public function testGetDetailsSensitive(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(
- [
- 'app' => 'sensitive-app',
- 'key' => 'lazy-key',
- 'value' => 'value',
- 'type' => 4,
- 'lazy' => true,
- 'typeString' => 'string',
- 'sensitive' => true,
- ],
- $config->getDetails('sensitive-app', 'lazy-key')
- );
- }
- public function testGetDetailsInt(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(
- [
- 'app' => 'typed',
- 'key' => 'int',
- 'value' => '42',
- 'type' => 8,
- 'lazy' => false,
- 'typeString' => 'integer',
- 'sensitive' => false
- ],
- $config->getDetails('typed', 'int')
- );
- }
- public function testGetDetailsFloat(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(
- [
- 'app' => 'typed',
- 'key' => 'float',
- 'value' => '3.14',
- 'type' => 16,
- 'lazy' => false,
- 'typeString' => 'float',
- 'sensitive' => false
- ],
- $config->getDetails('typed', 'float')
- );
- }
- public function testGetDetailsBool(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(
- [
- 'app' => 'typed',
- 'key' => 'bool',
- 'value' => '1',
- 'type' => 32,
- 'lazy' => false,
- 'typeString' => 'boolean',
- 'sensitive' => false
- ],
- $config->getDetails('typed', 'bool')
- );
- }
- public function testGetDetailsArray(): void {
- $config = $this->generateAppConfig();
- $this->assertEquals(
- [
- 'app' => 'typed',
- 'key' => 'array',
- 'value' => '{"test": 1}',
- 'type' => 64,
- 'lazy' => false,
- 'typeString' => 'array',
- 'sensitive' => false
- ],
- $config->getDetails('typed', 'array')
- );
- }
- public function testDeleteKey(): void {
- $config = $this->generateAppConfig();
- $config->deleteKey('anotherapp', 'key');
- $this->assertSame('default', $config->getValueString('anotherapp', 'key', 'default'));
- }
- public function testDeleteKeyCache(): void {
- $config = $this->generateAppConfig();
- $config->deleteKey('anotherapp', 'key');
- $status = $config->statusCache();
- $this->assertEqualsCanonicalizing(['enabled' => 'false'], $status['fastCache']['anotherapp']);
- }
- public function testDeleteKeyDatabase(): void {
- $config = $this->generateAppConfig();
- $config->deleteKey('anotherapp', 'key');
- $config->clearCache();
- $this->assertSame('default', $config->getValueString('anotherapp', 'key', 'default'));
- }
- public function testDeleteApp(): void {
- $config = $this->generateAppConfig();
- $config->deleteApp('anotherapp');
- $this->assertSame('default', $config->getValueString('anotherapp', 'key', 'default'));
- $this->assertSame('default', $config->getValueString('anotherapp', 'enabled', 'default'));
- }
- public function testDeleteAppCache(): void {
- $config = $this->generateAppConfig();
- $status = $config->statusCache();
- $this->assertSame(true, isset($status['fastCache']['anotherapp']));
- $config->deleteApp('anotherapp');
- $status = $config->statusCache();
- $this->assertSame(false, isset($status['fastCache']['anotherapp']));
- }
- public function testDeleteAppDatabase(): void {
- $config = $this->generateAppConfig();
- $config->deleteApp('anotherapp');
- $config->clearCache();
- $this->assertSame('default', $config->getValueString('anotherapp', 'key', 'default'));
- $this->assertSame('default', $config->getValueString('anotherapp', 'enabled', 'default'));
- }
- public function testClearCache(): void {
- $config = $this->generateAppConfig();
- $config->setValueString('feed', 'string', '123454');
- $config->clearCache();
- $status = $config->statusCache();
- $this->assertSame([], $status['fastCache']);
- }
- public function testSensitiveValuesAreEncrypted(): void {
- $key = self::getUniqueID('secret');
- $appConfig = $this->generateAppConfig();
- $secret = md5((string)time());
- $appConfig->setValueString('testapp', $key, $secret, sensitive: true);
- $this->assertConfigValueNotEquals('testapp', $key, $secret);
- // Can get in same run
- $actualSecret = $appConfig->getValueString('testapp', $key);
- $this->assertEquals($secret, $actualSecret);
- // Can get freshly decrypted from DB
- $newAppConfig = $this->generateAppConfig();
- $actualSecret = $newAppConfig->getValueString('testapp', $key);
- $this->assertEquals($secret, $actualSecret);
- }
- public function testMigratingNonSensitiveValueToSensitiveWithSetValue(): void {
- $key = self::getUniqueID('secret');
- $appConfig = $this->generateAppConfig();
- $secret = sha1((string)time());
- // Unencrypted
- $appConfig->setValueString('testapp', $key, $secret);
- $this->assertConfigKey('testapp', $key, $secret);
- // Can get freshly decrypted from DB
- $newAppConfig = $this->generateAppConfig();
- $actualSecret = $newAppConfig->getValueString('testapp', $key);
- $this->assertEquals($secret, $actualSecret);
- // Encrypting on change
- $appConfig->setValueString('testapp', $key, $secret, sensitive: true);
- $this->assertConfigValueNotEquals('testapp', $key, $secret);
- // Can get in same run
- $actualSecret = $appConfig->getValueString('testapp', $key);
- $this->assertEquals($secret, $actualSecret);
- // Can get freshly decrypted from DB
- $newAppConfig = $this->generateAppConfig();
- $actualSecret = $newAppConfig->getValueString('testapp', $key);
- $this->assertEquals($secret, $actualSecret);
- }
- public function testUpdateSensitiveValueToNonSensitiveWithUpdateSensitive(): void {
- $key = self::getUniqueID('secret');
- $appConfig = $this->generateAppConfig();
- $secret = sha1((string)time());
- // Encrypted
- $appConfig->setValueString('testapp', $key, $secret, sensitive: true);
- $this->assertConfigValueNotEquals('testapp', $key, $secret);
- // Migrate to non-sensitive / non-encrypted
- $appConfig->updateSensitive('testapp', $key, false);
- $this->assertConfigKey('testapp', $key, $secret);
- }
- public function testUpdateNonSensitiveValueToSensitiveWithUpdateSensitive(): void {
- $key = self::getUniqueID('secret');
- $appConfig = $this->generateAppConfig();
- $secret = sha1((string)time());
- // Unencrypted
- $appConfig->setValueString('testapp', $key, $secret);
- $this->assertConfigKey('testapp', $key, $secret);
- // Migrate to sensitive / encrypted
- $appConfig->updateSensitive('testapp', $key, true);
- $this->assertConfigValueNotEquals('testapp', $key, $secret);
- }
- protected function loadConfigValueFromDatabase(string $app, string $key): string|false {
- $sql = $this->connection->getQueryBuilder();
- $sql->select('configvalue')
- ->from('appconfig')
- ->where($sql->expr()->eq('appid', $sql->createParameter('appid')))
- ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey')))
- ->setParameter('appid', $app)
- ->setParameter('configkey', $key);
- $query = $sql->executeQuery();
- $actual = $query->fetchOne();
- $query->closeCursor();
- return $actual;
- }
- protected function assertConfigKey(string $app, string $key, string|false $expected): void {
- $this->assertEquals($expected, $this->loadConfigValueFromDatabase($app, $key));
- }
- protected function assertConfigValueNotEquals(string $app, string $key, string|false $expected): void {
- $this->assertNotEquals($expected, $this->loadConfigValueFromDatabase($app, $key));
- }
- }
|