Nenne bei einem Netzwerkfehler der Shinkan-Anbindung die Ursache
Namensauflösung, abgelehnte Verbindung, Zeitüberschreitung und Zertifikat werden unterschieden. Genannt wird nur der Servername, nie Pfad, Adresse oder Schlüssel. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e5b3eea7de
commit
bb08b9b3fa
2 files changed
+55
-1
No files matched your search
@@ -629,6 +629,34 @@ private function plain(Throwable $exception): string
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return $exception instanceof DomainRuleException ? $exception->getMessage() : 'Die Quelle ist nicht erreichbar.';
|
if ($exception instanceof DomainRuleException) {
|
||||||
|
return $exception->getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->networkCause($exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Benennt die Ursache eines Netzwerkfehlers, ohne Adresse, Pfad oder Schlüssel auszugeben. Genannt wird nur der
|
||||||
|
* Servername, damit die Redaktion erkennt, ob die richtige Quelle gemeint ist.
|
||||||
|
*/
|
||||||
|
private function networkCause(Throwable $exception): string
|
||||||
|
{
|
||||||
|
$host = app(ShinkanConnection::class)->url();
|
||||||
|
$host = $host === null ? 'der Quelle' : (string) (parse_url($host, PHP_URL_HOST) ?: 'der Quelle');
|
||||||
|
preg_match('/cURL error (\d+)/', $exception->getMessage(), $match);
|
||||||
|
$code = isset($match[1]) ? (int) $match[1] : null;
|
||||||
|
|
||||||
|
$cause = match (true) {
|
||||||
|
$code === 6 => 'Der Servername konnte von diesem Server aus nicht aufgelöst werden (Namensauflösung, DNS).',
|
||||||
|
$code === 7 => 'Der Server nimmt die Verbindung nicht an (abgelehnt, falscher Port oder Firewall).',
|
||||||
|
$code === 28 => 'Die Verbindung hat die Zeit überschritten (ausgehende Verbindungen sind möglicherweise blockiert).',
|
||||||
|
in_array($code, [35, 51, 58, 60, 77, 83], true) => 'Das Zertifikat oder die verschlüsselte Verbindung wird nicht akzeptiert.',
|
||||||
|
$code === 56 || $code === 52 => 'Die Verbindung wurde unterbrochen.',
|
||||||
|
$code !== null => 'Netzwerkfehler (cURL '.$code.').',
|
||||||
|
default => 'Netzwerkfehler.',
|
||||||
|
};
|
||||||
|
|
||||||
|
return 'Die Quelle '.$host.' ist von diesem Server aus nicht erreichbar. '.$cause;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
use Illuminate\Http\Client\Factory;
|
use Illuminate\Http\Client\Factory;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Livewire\Livewire;
|
use Livewire\Livewire;
|
||||||
@@ -465,6 +466,31 @@ public function test_the_address_may_name_the_installation_or_its_api_path_witho
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_a_network_failure_names_the_cause_and_the_host_but_no_address_path_or_key(): void
|
||||||
|
{
|
||||||
|
config(['services.shinkan.url' => 'https://dev.shinkan.jinkendo.de']);
|
||||||
|
$cases = [
|
||||||
|
'cURL error 6: Could not resolve host: dev.shinkan.jinkendo.de (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://dev.shinkan.jinkendo.de/api/distribution/v1/catalog' => 'Namensauflösung',
|
||||||
|
'cURL error 7: Failed to connect to dev.shinkan.jinkendo.de port 443' => 'Firewall',
|
||||||
|
'cURL error 28: Connection timed out after 20001 milliseconds' => 'Zeit überschritten',
|
||||||
|
'cURL error 60: SSL certificate problem' => 'Zertifikat',
|
||||||
|
'irgendetwas anderes' => 'Netzwerkfehler.',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($cases as $message => $expected) {
|
||||||
|
$this->freshHttp();
|
||||||
|
Http::fake(fn () => throw new ConnectionException($message));
|
||||||
|
|
||||||
|
$result = app(ShinkanImport::class)->check();
|
||||||
|
|
||||||
|
$this->assertFalse($result['ok']);
|
||||||
|
$this->assertStringContainsString('dev.shinkan.jinkendo.de', $result['message']);
|
||||||
|
$this->assertStringContainsString($expected, $result['message']);
|
||||||
|
$this->assertStringNotContainsString('/api/', $result['message']);
|
||||||
|
$this->assertStringNotContainsString('geheim-fuer-den-test', $result['message']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function test_the_exercise_list_leads_to_the_takeover_page(): void
|
public function test_the_exercise_list_leads_to_the_takeover_page(): void
|
||||||
{
|
{
|
||||||
Livewire::actingAs($this->staff('redakteur'), 'staff')
|
Livewire::actingAs($this->staff('redakteur'), 'staff')
|
||||||
|
|||||||
Reference in new issue
Block a user