U-D/U-E/O5: Prozess-Tester im eigenen Prozess (standardmäßig gesperrt, 15 Negativtests, statischer Wächter), Szenarien und Bericht, Kanalereignisse (API-Eingang ohne Umbau von iCal/Mail), Abschluss nach finanzieller Klärung, Löschfrist 30 Tage
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c255783cec
commit
0689c0a591
68 files changed
+3350
-35
No files matched your search
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
use App\Channels\Contracts\ChannelConnector;
|
||||
use App\Channels\Contracts\DeliversEvents;
|
||||
use App\Channels\Events\IncomingBooking;
|
||||
use App\Channels\Events\PaymentReported;
|
||||
use App\Channels\Events\Provenance;
|
||||
use App\Models\Channel;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
/**
|
||||
* N7: a portal interface as it could come later – only an adapter and its registry entry. It reads the portal's
|
||||
* bookings over HTTP (faked in the test) and delivers normalised channel events; it decides nothing.
|
||||
*/
|
||||
final class FakeApiConnector implements ChannelConnector, DeliversEvents
|
||||
{
|
||||
public static function key(): string
|
||||
{
|
||||
return 'fake_api';
|
||||
}
|
||||
|
||||
public static function label(): string
|
||||
{
|
||||
return 'Beispiel-Schnittstelle (Test)';
|
||||
}
|
||||
|
||||
public static function settingsSchema(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function canImport(Channel $channel): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function fetchOccupations(Channel $channel): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function fetchEvents(Channel $channel, ?CarbonImmutable $since): array
|
||||
{
|
||||
$events = [];
|
||||
foreach ((array) Http::get('https://api.portal.example/bookings')->json('bookings', []) as $row) {
|
||||
$provenance = new Provenance($channel, 'api', Provenance::AUTHENTICATED, (string) $row['reference'], 'fake-api:'.$row['reference'], CarbonImmutable::now());
|
||||
$events[] = new IncomingBooking($provenance, CarbonImmutable::parse($row['arrival']), CarbonImmutable::parse($row['departure']), $row['guests'] ?? null);
|
||||
if (isset($row['paid'])) {
|
||||
$events[] = new PaymentReported($provenance, (int) $row['paid'], CarbonImmutable::parse($row['paid_on']));
|
||||
}
|
||||
}
|
||||
|
||||
return $events;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Support\Process;
|
||||
|
||||
use App\Channels\Mail\MailboxReader;
|
||||
use App\Process\Tester\EffectLedger;
|
||||
use App\Process\Tester\SandboxContext;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Negative tests of the process tester (docs/Prozessarchitektur/Architektur/04 §7.2): runs inside the tester process
|
||||
* and deliberately tries one forbidden access (environment FEWO_SANDBOX_PROBE_CASE). Only registered in the test suite
|
||||
* (SandboxBootstrapper accepts a probe only with APP_ENV=testing). Records what it observed in the ledger.
|
||||
*/
|
||||
final class HostileProbe
|
||||
{
|
||||
public function handle(SandboxContext $context): void
|
||||
{
|
||||
$case = (string) getenv('FEWO_SANDBOX_PROBE_CASE');
|
||||
$operational = (string) getenv('FEWO_SANDBOX_PROBE_FILE');
|
||||
|
||||
try {
|
||||
match ($case) {
|
||||
'db_other_connection' => DB::connection('mysql')->select('select 1'),
|
||||
'db_new_connection' => (function () use ($operational): void {
|
||||
config(['database.connections.evil' => ['driver' => 'sqlite', 'database' => $operational, 'prefix' => '']]);
|
||||
DB::connection('evil')->insert('insert into probe (value) values (?)', ['evil']);
|
||||
})(),
|
||||
'db_redirected_sandbox' => (function () use ($operational): void {
|
||||
config(['database.connections.sandbox.database' => $operational]);
|
||||
DB::purge('sandbox');
|
||||
DB::connection('sandbox')->insert('insert into probe (value) values (?)', ['evil']);
|
||||
})(),
|
||||
'db_operational_table' => DB::table('probe')->insert(['value' => 'evil']),
|
||||
'network' => Http::get('https://example.org/'),
|
||||
'webhook' => Http::withHeaders(['X-Signature' => 'x'])->post('https://n8n.example/webhook/channel-task', ['task' => 1]),
|
||||
'imap' => app(MailboxReader::class)->fetchAll(),
|
||||
'mail_other_mailer' => Mail::mailer('smtp')->raw('Test', fn ($message) => $message->to('someone@example.org')),
|
||||
'file_outside' => Storage::build(['driver' => 'local', 'root' => base_path()])->put('sandbox-probe.txt', 'evil'),
|
||||
'cache_other_store' => Cache::store('database')->put('probe', 'evil'),
|
||||
'signed_link' => EffectLedger::record('probe', ['url' => URL::temporarySignedRoute('offers.show', now()->addDay(), ['booking' => 1, 'v' => 1])]),
|
||||
'environment' => EffectLedger::record('probe', [
|
||||
'db_password_env' => getenv('DB_PASSWORD'),
|
||||
'connections' => array_keys((array) config('database.connections')),
|
||||
'mailers' => array_keys((array) config('mail.mailers')),
|
||||
'smtp_password' => config('mail.mailers.smtp.password'),
|
||||
'app_key_differs' => config('app.key') !== getenv('FEWO_SANDBOX_PROBE_PARENT_KEY'),
|
||||
'bookings' => DB::table('bookings')->count(),
|
||||
'guests' => DB::table('guests')->count(),
|
||||
]),
|
||||
default => null,
|
||||
};
|
||||
EffectLedger::record('probe', ['case' => $case, 'outcome' => 'no exception']);
|
||||
} catch (Throwable $exception) {
|
||||
EffectLedger::record('probe', ['case' => $case, 'outcome' => class_basename($exception), 'message' => mb_substr($exception->getMessage(), 0, 200)]);
|
||||
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user