Rückmeldungen, Hintergrundaufgaben, Systemzustand und Web-Installer
- Rückmeldungen an den Hersteller (docs/specs/feedback.md): Fehlerbericht und
Funktionswunsch, nur freigeschaltete Wege, Idempotency-Key je Meldung,
Warteschlange mit höchstens fünf Versuchen, 422 am Feld, 429 mit Wartezeit,
404 blendet den Weg aus, Referenznummer und „Meine Rückmeldungen“,
sichtbare technische Angaben und Datenschutzhinweis über dem Absendeknopf
- Hintergrundaufgaben ohne Dauerprozess: Cron, Web-Cron (/cron/{token}) oder
Pseudo-Cron nach dem Seitenaufruf; Queue in kurzen Häppchen
- Seite „Systemzustand“ mit Voraussetzungen, Grenzen, Betrieb, Sicherheit und
Anleitung für den Cronjob
- Web-Installer (Systemprüfung → Datenbank → Administrator), legt .env und
Anwendungsschlüssel selbst an, arbeitet vor der Einrichtung ohne Datenbank
- Datenbank-Benachrichtigungen im Admin-Bereich
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
43244d751a
commit
029dbd243d
38 changed files with 2274 additions and 12 deletions
53
tests/Feature/BackgroundTasksTest.php
Normal file
53
tests/Feature/BackgroundTasksTest.php
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Support\BackgroundTasks;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class BackgroundTasksTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
@unlink(storage_path('.background-heartbeat'));
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
@unlink(storage_path('.background-heartbeat'));
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_web_cron_requires_the_secret_token(): void
|
||||
{
|
||||
$token = app(BackgroundTasks::class)->webCronToken();
|
||||
|
||||
$this->assertSame(40, strlen($token));
|
||||
$this->get('/cron/falsch')->assertNotFound();
|
||||
$this->get("/cron/{$token}")->assertNoContent();
|
||||
|
||||
$this->assertArrayHasKey('webcron', app(BackgroundTasks::class)->heartbeats());
|
||||
}
|
||||
|
||||
public function test_pseudo_cron_only_steps_in_without_external_cron(): void
|
||||
{
|
||||
$tasks = app(BackgroundTasks::class);
|
||||
|
||||
$this->assertTrue($tasks->pseudoCronDue());
|
||||
|
||||
$tasks->heartbeat('cron');
|
||||
$this->assertFalse($tasks->pseudoCronDue());
|
||||
|
||||
$this->travel(BackgroundTasks::PSEUDO_CRON_AFTER_SECONDS + 5)->seconds();
|
||||
$this->assertTrue($tasks->pseudoCronDue());
|
||||
|
||||
$tasks->heartbeat('pseudo');
|
||||
$this->assertFalse($tasks->pseudoCronDue(), 'Höchstens einmal pro Minute.');
|
||||
}
|
||||
}
|
||||
274
tests/Feature/Feedback/FeedbackTest.php
Normal file
274
tests/Feature/Feedback/FeedbackTest.php
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Feedback;
|
||||
|
||||
use App\Filament\Pages\Feedback;
|
||||
use App\Models\User;
|
||||
use App\Models\VendorFeedback;
|
||||
use App\Support\Feedback\FeedbackChannels;
|
||||
use App\Support\Feedback\FeedbackOutbox;
|
||||
use App\Support\Feedback\FeedbackResult;
|
||||
use App\Support\License\LicenseStore;
|
||||
use App\Support\Update\Filesystem;
|
||||
use App\Support\Update\InstalledVersion;
|
||||
use App\Version;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Client\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class FeedbackTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private const URL = 'https://api.loheide.cloud/v1/software/mitarbeiterportal/bugreport';
|
||||
|
||||
private string $dir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->dir = sys_get_temp_dir().'/inhaus-fb-'.bin2hex(random_bytes(4));
|
||||
mkdir($this->dir);
|
||||
$this->app->instance(LicenseStore::class, new LicenseStore($this->dir.'/license.json'));
|
||||
$this->app->instance(InstalledVersion::class, new InstalledVersion($this->dir.'/.version'));
|
||||
app(InstalledVersion::class)->save(str_repeat('9', 40));
|
||||
Cache::put('feedback.endpoints', ['bugreport', 'featurerequest', 'telemetry'], 60);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Filesystem::deleteDirectory($this->dir);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function payload(): array
|
||||
{
|
||||
return ['title' => 'Export bricht ab', 'body' => 'Ab etwa 5000 Zeilen passiert nichts mehr.', 'severity' => 'high'];
|
||||
}
|
||||
|
||||
public function test_request_body_and_headers_with_license(): void
|
||||
{
|
||||
app(LicenseStore::class)->setLicense('lizenz@firma.de', 'KEY-1');
|
||||
Http::fake([self::URL => Http::response(['ok' => true, 'reference' => 'BUG-8F3K2Q', 'id' => 'x'], 201)]);
|
||||
$user = User::factory()->admin()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(Feedback::class)
|
||||
->set('type', 'bugreport')
|
||||
->set('subject', 'Export bricht ab')
|
||||
->set('body', 'Ab etwa 5000 Zeilen passiert nichts mehr.')
|
||||
->set('severity', 'high')
|
||||
->set('email', 'rueckfrage@firma.de')
|
||||
->call('submit')
|
||||
->assertHasNoErrors()
|
||||
->assertSet('lastReference', 'BUG-8F3K2Q')
|
||||
->assertSet('subject', '')
|
||||
->assertSee('BUG-8F3K2Q');
|
||||
|
||||
Http::assertSent(function (Request $request) {
|
||||
$data = $request->data();
|
||||
|
||||
return $request->url() === self::URL
|
||||
&& $request->method() === 'POST'
|
||||
&& $request->hasHeader('X-License-Email', 'lizenz@firma.de')
|
||||
&& $request->hasHeader('Authorization', 'Bearer KEY-1')
|
||||
&& strlen($request->header('Idempotency-Key')[0]) === 32
|
||||
&& $data['title'] === 'Export bricht ab'
|
||||
&& $data['email'] === 'rueckfrage@firma.de'
|
||||
&& $data['severity'] === 'high'
|
||||
&& $data['app_version'] === Version::VERSION
|
||||
&& $data['current_sha'] === str_repeat('9', 40)
|
||||
&& $data['os'] !== ''
|
||||
&& isset($data['metadata']['php'])
|
||||
&& ! isset($data['name']);
|
||||
});
|
||||
|
||||
$feedback = VendorFeedback::query()->sole();
|
||||
$this->assertSame('sent', $feedback->status);
|
||||
$this->assertSame('BUG-8F3K2Q', $feedback->reference);
|
||||
}
|
||||
|
||||
public function test_no_license_headers_without_license(): void
|
||||
{
|
||||
Http::fake([self::URL => Http::response(['ok' => true, 'reference' => 'BUG-1'], 201)]);
|
||||
|
||||
app(FeedbackOutbox::class)->submit(null, 'bugreport', $this->payload());
|
||||
|
||||
Http::assertSent(fn (Request $request) => ! $request->hasHeader('X-License-Email')
|
||||
&& ! $request->hasHeader('Authorization')
|
||||
&& ! $request->hasHeader('X-Device-Id'));
|
||||
}
|
||||
|
||||
public function test_expired_license_does_not_prevent_sending(): void
|
||||
{
|
||||
app(LicenseStore::class)->setLicense('lizenz@firma.de', 'ABGELAUFEN');
|
||||
app(LicenseStore::class)->rememberStatus(null, 'license_expired');
|
||||
Http::fake([self::URL => Http::response(['ok' => true, 'reference' => 'BUG-2'], 201)]);
|
||||
|
||||
$result = app(FeedbackOutbox::class)->submit(null, 'bugreport', $this->payload());
|
||||
|
||||
$this->assertSame(FeedbackResult::SENT, $result->status);
|
||||
Http::assertSentCount(1);
|
||||
}
|
||||
|
||||
public function test_422_shows_error_on_field_and_keeps_input(): void
|
||||
{
|
||||
Http::fake([self::URL => Http::response(['code' => 'validation_failed', 'errors' => ['title' => ['Der Betreff ist zu lang.']]], 422)]);
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
Livewire::test(Feedback::class)
|
||||
->set('type', 'bugreport')
|
||||
->set('subject', 'Betreff')
|
||||
->set('body', 'Eine ausreichend lange Beschreibung.')
|
||||
->call('submit')
|
||||
->assertHasErrors(['subject'])
|
||||
->assertSet('subject', 'Betreff')
|
||||
->assertSet('body', 'Eine ausreichend lange Beschreibung.');
|
||||
|
||||
$this->assertSame(0, VendorFeedback::query()->count());
|
||||
}
|
||||
|
||||
public function test_429_names_the_waiting_time_and_keeps_input(): void
|
||||
{
|
||||
Http::fake([self::URL => Http::response(['code' => 'rate_limited'], 429, ['Retry-After' => '600'])]);
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
Livewire::test(Feedback::class)
|
||||
->set('type', 'bugreport')
|
||||
->set('subject', 'Betreff')
|
||||
->set('body', 'Eine ausreichend lange Beschreibung.')
|
||||
->call('submit')
|
||||
->assertSet('notice', fn (string $notice) => str_contains($notice, 'in etwa 10 Minute(n)'))
|
||||
->assertSet('body', 'Eine ausreichend lange Beschreibung.');
|
||||
|
||||
Http::assertSentCount(1);
|
||||
$this->assertSame(0, VendorFeedback::query()->count());
|
||||
}
|
||||
|
||||
public function test_404_hides_the_channel_permanently(): void
|
||||
{
|
||||
Http::fake([self::URL => Http::response(['code' => 'not_found'], 404)]);
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
|
||||
Livewire::test(Feedback::class)
|
||||
->set('type', 'bugreport')
|
||||
->set('subject', 'Betreff')
|
||||
->set('body', 'Eine ausreichend lange Beschreibung.')
|
||||
->call('submit')
|
||||
->assertSet('type', 'featurerequest')
|
||||
->assertSet('body', 'Eine ausreichend lange Beschreibung.');
|
||||
|
||||
$this->assertSame(['featurerequest' => 'Funktionswunsch'], app(FeedbackChannels::class)->available());
|
||||
}
|
||||
|
||||
public function test_only_enabled_channels_are_offered(): void
|
||||
{
|
||||
Cache::put('feedback.endpoints', ['featurerequest', 'telemetry'], 60);
|
||||
|
||||
$this->assertSame(['featurerequest' => 'Funktionswunsch'], app(FeedbackChannels::class)->available());
|
||||
}
|
||||
|
||||
public function test_channels_are_read_from_software_list(): void
|
||||
{
|
||||
Cache::forget('feedback.endpoints');
|
||||
Http::fake(['api.loheide.cloud/v1/software' => Http::response(['software' => [
|
||||
['slug' => 'andere', 'endpoints' => ['bugreport']],
|
||||
['slug' => 'mitarbeiterportal', 'endpoints' => ['bugreport', 'telemetry']],
|
||||
]])]);
|
||||
|
||||
$this->assertSame(['bugreport' => 'Fehlerbericht'], app(FeedbackChannels::class)->available());
|
||||
}
|
||||
|
||||
public function test_503_queues_and_retries_with_same_idempotency_key(): void
|
||||
{
|
||||
Http::fakeSequence(self::URL)
|
||||
->push(['code' => 'maintenance'], 503)
|
||||
->push(['code' => 'maintenance'], 503)
|
||||
->push(['ok' => true, 'reference' => 'BUG-SPAET'], 201);
|
||||
|
||||
$result = app(FeedbackOutbox::class)->submit(null, 'bugreport', $this->payload());
|
||||
$this->assertSame(FeedbackResult::RETRY, $result->status);
|
||||
|
||||
$feedback = VendorFeedback::query()->sole();
|
||||
$this->assertSame('pending', $feedback->status);
|
||||
$this->assertSame(1, $feedback->attempts);
|
||||
|
||||
// Noch nicht fällig.
|
||||
$this->assertSame(0, app(FeedbackOutbox::class)->processDue());
|
||||
|
||||
$this->travel(2)->minutes();
|
||||
app(FeedbackOutbox::class)->processDue();
|
||||
$this->travel(10)->minutes();
|
||||
app(FeedbackOutbox::class)->processDue();
|
||||
|
||||
$feedback->refresh();
|
||||
$this->assertSame('sent', $feedback->status);
|
||||
$this->assertSame('BUG-SPAET', $feedback->reference);
|
||||
|
||||
$keys = collect(Http::recorded())->map(fn ($pair) => $pair[0]->header('Idempotency-Key')[0])->unique();
|
||||
$this->assertCount(1, $keys, 'Wiederholungen müssen denselben Idempotency-Key senden.');
|
||||
}
|
||||
|
||||
public function test_gives_up_after_five_attempts_and_informs_the_user(): void
|
||||
{
|
||||
Http::fake([self::URL => Http::response('', 503)]);
|
||||
$user = User::factory()->admin()->create();
|
||||
|
||||
app(FeedbackOutbox::class)->submit($user, 'bugreport', $this->payload());
|
||||
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
$this->travel(2)->hours();
|
||||
app(FeedbackOutbox::class)->processDue();
|
||||
}
|
||||
|
||||
$feedback = VendorFeedback::query()->sole();
|
||||
$this->assertSame('discarded', $feedback->status);
|
||||
$this->assertSame(5, $feedback->attempts);
|
||||
Http::assertSentCount(5);
|
||||
$this->assertSame(1, $user->notifications()->count());
|
||||
}
|
||||
|
||||
public function test_network_failure_is_queued(): void
|
||||
{
|
||||
Http::fake([self::URL => fn () => throw new ConnectionException('offline')]);
|
||||
|
||||
$result = app(FeedbackOutbox::class)->submit(null, 'bugreport', $this->payload());
|
||||
|
||||
$this->assertSame(FeedbackResult::RETRY, $result->status);
|
||||
$this->assertSame('pending', VendorFeedback::query()->sole()->status);
|
||||
}
|
||||
|
||||
public function test_409_is_not_shown_as_error_but_retried(): void
|
||||
{
|
||||
Http::fake([self::URL => Http::response(['code' => 'in_progress'], 409)]);
|
||||
|
||||
$result = app(FeedbackOutbox::class)->submit(null, 'bugreport', $this->payload());
|
||||
|
||||
$this->assertSame(FeedbackResult::RETRY, $result->status);
|
||||
$this->assertTrue(VendorFeedback::query()->sole()->next_attempt_at->isFuture());
|
||||
}
|
||||
|
||||
public function test_page_shows_technical_info_and_privacy_notice_and_is_admin_only(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create())->get('/admin/rueckmeldung')->assertForbidden();
|
||||
|
||||
$this->actingAs(User::factory()->admin()->create())
|
||||
->get('/admin/rueckmeldung')
|
||||
->assertOk()
|
||||
->assertSee('Diese technischen Angaben werden mitgesendet')
|
||||
->assertSee(Version::VERSION)
|
||||
->assertSee(str_repeat('9', 40))
|
||||
->assertSee('Mit dem Absenden werden Daten an api.loheide.cloud übertragen.')
|
||||
->assertDontSee('die von Ihnen angehängten Dateien')
|
||||
->assertDontSee('Ihre Lizenzdaten, damit die Meldung');
|
||||
}
|
||||
}
|
||||
115
tests/Feature/InstallerTest.php
Normal file
115
tests/Feature/InstallerTest.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\Installation;
|
||||
use App\Support\License\LicenseStore;
|
||||
use App\Support\Settings;
|
||||
use App\Support\Update\Filesystem;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class InstallerTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private string $dir;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->dir = sys_get_temp_dir().'/inhaus-inst-'.bin2hex(random_bytes(4));
|
||||
mkdir($this->dir);
|
||||
copy(base_path('.env.example'), $this->dir.'/.env');
|
||||
$this->app->useEnvironmentPath($this->dir);
|
||||
$this->app->instance(LicenseStore::class, new LicenseStore($this->dir.'/license.json'));
|
||||
config(['inhaus.installed' => false]);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
@unlink(storage_path('.installed'));
|
||||
Filesystem::deleteDirectory($this->dir);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_every_page_leads_to_the_installer(): void
|
||||
{
|
||||
$this->get('/')->assertRedirect('/install');
|
||||
$this->get('/login')->assertRedirect('/install');
|
||||
$this->get('/install')->assertOk()->assertSee('Systemprüfung')->assertSee('PHP-Version');
|
||||
}
|
||||
|
||||
public function test_wrong_database_credentials_are_explained(): void
|
||||
{
|
||||
$this->post('/install/datenbank', [
|
||||
'host' => config('database.connections.mysql.host'),
|
||||
'port' => config('database.connections.mysql.port'),
|
||||
'database' => config('database.connections.mysql.database'),
|
||||
'username' => 'gibtesnicht',
|
||||
'password' => 'falsch',
|
||||
])->assertSessionHasErrors(['host' => 'Verbindung fehlgeschlagen: Benutzername oder Passwort sind falsch, oder der Benutzer hat keinen Zugriff auf diese Datenbank.']);
|
||||
}
|
||||
|
||||
public function test_database_settings_are_written_to_env(): void
|
||||
{
|
||||
$this->post('/install/datenbank', [
|
||||
'host' => config('database.connections.mysql.host'),
|
||||
'port' => config('database.connections.mysql.port'),
|
||||
'database' => config('database.connections.mysql.database'),
|
||||
'username' => config('database.connections.mysql.username'),
|
||||
'password' => config('database.connections.mysql.password'),
|
||||
])->assertRedirect('/install/konto');
|
||||
|
||||
$env = file_get_contents($this->dir.'/.env');
|
||||
$this->assertStringContainsString('DB_DATABASE='.config('database.connections.mysql.database'), $env);
|
||||
$this->assertStringContainsString('DB_USERNAME='.config('database.connections.mysql.username'), $env);
|
||||
$this->assertStringContainsString('APP_URL='.url('/'), $env);
|
||||
}
|
||||
|
||||
public function test_account_step_completes_the_installation(): void
|
||||
{
|
||||
$this->post('/install/konto', [
|
||||
'portal_name' => 'Caritas-Netz',
|
||||
'first_name' => 'Ada',
|
||||
'last_name' => 'Admin',
|
||||
'email' => 'Ada@Example.com',
|
||||
'password' => 'SicheresPasswort1',
|
||||
'password_confirmation' => 'SicheresPasswort1',
|
||||
'license_email' => 'lizenz@example.com',
|
||||
'license_key' => 'KEY-123',
|
||||
])->assertRedirect('/login');
|
||||
|
||||
$admin = User::query()->where('email', 'ada@example.com')->sole();
|
||||
$this->assertTrue($admin->is_admin);
|
||||
$this->assertSame('Ada Admin', $admin->name);
|
||||
$this->assertSame('Caritas-Netz', app(Settings::class)->get('branding.portal_name'));
|
||||
$this->assertSame('KEY-123', app(LicenseStore::class)->key());
|
||||
$this->assertFileExists(storage_path('.installed'));
|
||||
|
||||
config(['inhaus.installed' => null]);
|
||||
$this->assertTrue(Installation::isInstalled());
|
||||
$this->get('/install')->assertNotFound();
|
||||
}
|
||||
|
||||
public function test_weak_admin_password_is_rejected(): void
|
||||
{
|
||||
$this->post('/install/konto', [
|
||||
'portal_name' => 'Portal', 'first_name' => 'A', 'last_name' => 'B', 'email' => 'a@example.com',
|
||||
'password' => 'kurz', 'password_confirmation' => 'kurz',
|
||||
])->assertSessionHasErrors('password');
|
||||
|
||||
$this->assertFileDoesNotExist(storage_path('.installed'));
|
||||
}
|
||||
|
||||
public function test_installer_is_gone_once_installed(): void
|
||||
{
|
||||
config(['inhaus.installed' => true]);
|
||||
|
||||
$this->get('/install')->assertNotFound();
|
||||
$this->post('/install/konto', [])->assertNotFound();
|
||||
}
|
||||
}
|
||||
42
tests/Feature/SiteHealthTest.php
Normal file
42
tests/Feature/SiteHealthTest.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Support\SiteHealth;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SiteHealthTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_requirements_are_met_in_this_environment(): void
|
||||
{
|
||||
$requirements = app(SiteHealth::class)->requirements();
|
||||
|
||||
foreach ($requirements as $check) {
|
||||
$this->assertNotSame(SiteHealth::ERROR, $check['status'], $check['label'].': '.$check['message']);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_page_shows_checks_and_cron_setup(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->create())->get('/admin/systemzustand')->assertForbidden();
|
||||
|
||||
$this->actingAs(User::factory()->admin()->create())
|
||||
->get('/admin/systemzustand')
|
||||
->assertOk()
|
||||
->assertSee('PHP-Version')
|
||||
->assertSee('Hintergrundaufgaben')
|
||||
->assertSee('php artisan schedule:run')
|
||||
->assertSee('/cron/');
|
||||
}
|
||||
|
||||
public function test_byte_values_are_parsed(): void
|
||||
{
|
||||
$this->assertSame(128 * 1024 ** 2, SiteHealth::bytes('128M'));
|
||||
$this->assertSame(2 * 1024 ** 3, SiteHealth::bytes('2G'));
|
||||
$this->assertSame(-1, SiteHealth::bytes('-1'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue