instance(\App\Services\Ssh\RemoteShell::class, $shell); app(SecureHostFirewall::class)->execute( \App\Models\ProvisioningRun::factory()->forHost(Host::factory()->create())->create() ); $regelwerk = $shell->files()['/etc/nftables.conf'] ?? ''; $established = strpos($regelwerk, 'ct state established,related accept'); $sperre = strpos($regelwerk, '@clupilot_blocked'); expect($established)->not->toBeFalse() ->and($sperre)->not->toBeFalse() ->and($established)->toBeLessThan($sperre); // Beide Mengen, und beide mit Ablaufzeit — ohne `flags timeout` nimmt // nftables die Zeitangabe beim Eintragen gar nicht an. expect($regelwerk)->toContain('set clupilot_blocked') ->and($regelwerk)->toContain('set clupilot_blocked6') ->and(substr_count($regelwerk, 'flags timeout'))->toBe(2); }); it('traegt eine Adresse mit Ablaufzeit ein und nimmt sie wieder heraus', function () { $shell = new FakeRemoteShell; app()->instance(\App\Services\Ssh\RemoteShell::class, $shell); $host = Host::factory()->active()->create(['ssh_host_key' => 'SHA256:abc']); app(HostFirewall::class)->block($host, '203.0.113.7', 3600); app(HostFirewall::class)->release($host, '203.0.113.7'); expect($shell->ran('add element inet clupilot_filter clupilot_blocked { 203.0.113.7 timeout 3600s }'))->toBeTrue() ->and($shell->ran('delete element inet clupilot_filter clupilot_blocked { 203.0.113.7 }'))->toBeTrue(); }); it('waehlt fuer eine IPv6-Adresse die zweite Menge', function () { $shell = new FakeRemoteShell; app()->instance(\App\Services\Ssh\RemoteShell::class, $shell); $host = Host::factory()->active()->create(['ssh_host_key' => 'SHA256:abc']); app(HostFirewall::class)->block($host, '2001:db8::1', 3600); expect($shell->ran('clupilot_blocked6 { 2001:db8::1 timeout 3600s }'))->toBeTrue(); });