Pflege Adresse und Zugangsschlüssel der Shinkan-Anbindung in der Verwaltung
Werte aus der Umgebung des Servers haben Vorrang, sonst gilt der in der Verwaltung gepflegte. Der Schlüssel liegt verschlüsselt in site_settings und wird nie angezeigt. Änderung nur für Katalog- und Systemverwalter. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bcda189267
commit
26ca79cd22
8 files changed
+320
-17
No files matched your search
@@ -9,7 +9,9 @@
|
||||
use App\Domain\Catalog\ExerciseImportRun;
|
||||
use App\Domain\Catalog\ExerciseSource;
|
||||
use App\Domain\Catalog\ExerciseSourceSnapshot;
|
||||
use App\Domain\Catalog\ShinkanConnection;
|
||||
use App\Domain\Catalog\ShinkanImport;
|
||||
use App\Domain\Design\SiteSetting;
|
||||
use App\Filament\Pages\Uebernahme;
|
||||
use App\Filament\Resources\Practices\Pages\ListPractices;
|
||||
use App\Models\User;
|
||||
@@ -280,11 +282,103 @@ public function test_the_page_shows_the_connection_state_without_values_and_chec
|
||||
Livewire::actingAs($user, 'staff')
|
||||
->test(Uebernahme::class)
|
||||
->assertSee('nicht hinterlegt')
|
||||
->assertSee('SHINKAN_DISTRIBUTION_KEY')
|
||||
->call('check')
|
||||
->assertSee('nicht eingerichtet');
|
||||
}
|
||||
|
||||
public function test_address_and_key_can_be_kept_in_the_administration_and_the_key_is_stored_encrypted(): void
|
||||
{
|
||||
config(['services.shinkan.url' => null, 'services.shinkan.key' => null]);
|
||||
$keeper = $this->staff('katalogverwalter');
|
||||
|
||||
Livewire::actingAs($keeper, 'staff')
|
||||
->test(Uebernahme::class)
|
||||
->assertSee('Anbindung speichern')
|
||||
->set('url', 'https://shinkan.example/')
|
||||
->set('apiKey', 'schluessel-aus-shinkan')
|
||||
->call('saveConnection')
|
||||
->assertSee('Die Anbindung ist gespeichert')
|
||||
->assertSet('apiKey', '')
|
||||
->assertSee('shinkan.example')
|
||||
->assertSee('in der Verwaltung gepflegt')
|
||||
->assertDontSee('schluessel-aus-shinkan');
|
||||
|
||||
$stored = SiteSetting::query()->findOrFail('shinkan.anbindung')->value;
|
||||
$this->assertSame('https://shinkan.example', $stored['url']);
|
||||
$this->assertStringNotContainsString('schluessel-aus-shinkan', json_encode($stored));
|
||||
$this->assertSame('schluessel-aus-shinkan', app(ShinkanConnection::class)->apiKey());
|
||||
|
||||
$this->freshHttp();
|
||||
Http::fake(['shinkan.example/*' => Http::response(['exercises' => [], 'changes' => [], 'next_cursor' => 'c1'])]);
|
||||
|
||||
$this->assertSame('ok', app(ShinkanImport::class)->fetch()->status);
|
||||
Http::assertSent(fn ($request): bool => $request->hasHeader('Authorization', 'Bearer schluessel-aus-shinkan') && str_starts_with($request->url(), 'https://shinkan.example/api/distribution/v1/catalog'));
|
||||
}
|
||||
|
||||
public function test_a_value_from_the_server_environment_wins_over_the_one_kept_in_the_administration(): void
|
||||
{
|
||||
$connection = app(ShinkanConnection::class);
|
||||
config(['services.shinkan.url' => null, 'services.shinkan.key' => null]);
|
||||
$connection->save('https://verwaltung.example', 'schluessel-verwaltung');
|
||||
|
||||
$this->assertSame('verwaltung', $connection->source('key'));
|
||||
|
||||
config(['services.shinkan.url' => 'https://server.example', 'services.shinkan.key' => 'schluessel-server']);
|
||||
|
||||
$this->assertSame('https://server.example', $connection->url());
|
||||
$this->assertSame('schluessel-server', $connection->apiKey());
|
||||
$this->assertSame('server', $connection->source('key'));
|
||||
|
||||
config(['services.shinkan.key' => null]);
|
||||
|
||||
$this->assertSame('schluessel-verwaltung', $connection->apiKey(), 'Ohne Wert in der Umgebung gilt der gepflegte.');
|
||||
}
|
||||
|
||||
public function test_only_catalog_and_system_administrators_change_the_connection_and_the_address_is_checked(): void
|
||||
{
|
||||
config(['services.shinkan.url' => null, 'services.shinkan.key' => null]);
|
||||
|
||||
Livewire::actingAs($this->staff('redakteur'), 'staff')
|
||||
->test(Uebernahme::class)
|
||||
->assertDontSee('Anbindung speichern')
|
||||
->set('url', 'https://x.example')
|
||||
->call('saveConnection')
|
||||
->assertForbidden();
|
||||
|
||||
$this->assertSame(0, SiteSetting::query()->where('key', 'shinkan.anbindung')->count());
|
||||
|
||||
Livewire::actingAs($this->staff('systemverwalter'), 'staff')
|
||||
->test(Uebernahme::class)
|
||||
->set('url', 'ftp://kein-web')
|
||||
->set('apiKey', 'x')
|
||||
->call('saveConnection')
|
||||
->assertSee('keine gültige Internetadresse');
|
||||
}
|
||||
|
||||
public function test_the_kept_key_can_be_removed_and_a_new_one_replaces_it(): void
|
||||
{
|
||||
config(['services.shinkan.url' => null, 'services.shinkan.key' => null]);
|
||||
$connection = app(ShinkanConnection::class);
|
||||
$connection->save('https://shinkan.example', 'alt');
|
||||
$connection->save('https://shinkan.example', '');
|
||||
$this->assertSame('alt', $connection->apiKey(), 'Ein leeres Feld lässt den Schlüssel unverändert.');
|
||||
$connection->save('https://shinkan.example', 'neu');
|
||||
$this->assertSame('neu', $connection->apiKey());
|
||||
|
||||
Livewire::actingAs($this->staff('katalogverwalter'), 'staff')->test(Uebernahme::class)->call('removeKey');
|
||||
|
||||
$this->assertNull($connection->apiKey());
|
||||
$this->assertFalse(app(ShinkanImport::class)->configured());
|
||||
}
|
||||
|
||||
private function staff(string $role): User
|
||||
{
|
||||
$user = User::factory()->{$role}()->create();
|
||||
$user->saveAppAuthenticationSecret('JBSWY3DPEHPK3PXP');
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
private function freshHttp(): void
|
||||
{
|
||||
Http::swap(new Factory);
|
||||
|
||||
Reference in new issue
Block a user