Files
osint/tests/Unit/Osint/CrtShRunnerTest.php
T

65 lines
1.8 KiB
PHP
Raw Normal View History

2026-07-20 10:22:05 +03:00
<?php
namespace Tests\Unit\Osint;
use App\Models\Target;
use App\Osint\Runners\CrtShRunner;
use App\Osint\RunnerException;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class CrtShRunnerTest extends TestCase
{
public function test_parses_and_deduplicates_subdomains(): void
{
Http::fake([
'crt.sh/*' => Http::response(json_encode([
['name_value' => "www.example.com\nexample.com"],
['name_value' => "*.example.com\nwww.example.com"],
])),
]);
$target = new Target(['type' => 'domain', 'value' => 'example.com']);
$result = (new CrtShRunner)->run($target);
$this->assertSame(
['*.example.com', 'example.com', 'www.example.com'],
$result->raw['subdomains']
);
$this->assertStringContainsString('3 unique subdomains', $result->summary);
}
public function test_handles_empty_response(): void
{
Http::fake(['crt.sh/*' => Http::response('')]);
$target = new Target(['type' => 'domain', 'value' => 'nonexistent-domain-xyz.com']);
$result = (new CrtShRunner)->run($target);
$this->assertSame([], $result->raw['subdomains']);
$this->assertSame('No certificates found.', $result->summary);
}
public function test_rejects_non_domain_targets(): void
{
$target = new Target(['type' => 'ip', 'value' => '8.8.8.8']);
$this->expectException(RunnerException::class);
(new CrtShRunner)->run($target);
}
public function test_throws_on_http_failure(): void
{
Http::fake(['crt.sh/*' => Http::response('', 500)]);
$target = new Target(['type' => 'domain', 'value' => 'example.com']);
$this->expectException(RunnerException::class);
(new CrtShRunner)->run($target);
}
}