Skip to content

Commit

Permalink
add configuration integrity check
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Jan 17, 2025
1 parent a8f321f commit 23f5b77
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Http/Middleware/ConfigIntegrity.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class ConfigIntegrity
{
private const SE_FIELDS = [
public const SE_FIELDS = [
'default_user_quota',
'timeline_photos_granularity',
'timeline_albums_granularity',
Expand Down
46 changes: 46 additions & 0 deletions tests/Unit/Middleware/ConfigIntegrityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/

/**
* We don't care for unhandled exceptions in tests.
* It is the nature of a test to throw an exception.
* Without this suppression we had 100+ Linter warning in this file which
* don't help anything.
*
* @noinspection PhpDocMissingThrowsInspection
* @noinspection PhpUnhandledExceptionInspection
*/

namespace Tests\Unit\Middleware;

use App\Http\Middleware\ConfigIntegrity;
use Illuminate\Support\Facades\DB;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\ConsoleSectionOutput;
use Tests\AbstractTestCase;

class ConfigIntegrityTest extends AbstractTestCase
{
private ConsoleSectionOutput $msgSection;
private bool $failed = false;

public function testConfiguration(): void
{
$this->msgSection = (new ConsoleOutput())->section();

$keys = DB::table('configs')->select('key')->where('level', '=', '1')->pluck('key');
foreach ($keys as $key) {
if (!in_array($key, ConfigIntegrity::SE_FIELDS, true)) {
$this->msgSection->writeln(sprintf('<comment>Error:</comment> Key %s is not in the list of keys.', $key));
$this->failed = true;
}
}

static::assertFalse($this->failed);
}
}

0 comments on commit 23f5b77

Please sign in to comment.