55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Tests\Unit\Osint;
|
||
|
|
|
||
|
|
use App\Models\Target;
|
||
|
|
use App\Osint\Runners\DnsRunner;
|
||
|
|
use App\Osint\RunnerException;
|
||
|
|
use Tests\TestCase;
|
||
|
|
|
||
|
|
class DnsRunnerTest extends TestCase
|
||
|
|
{
|
||
|
|
public function test_rejects_non_domain_targets(): void
|
||
|
|
{
|
||
|
|
$target = new Target(['type' => 'ip', 'value' => '8.8.8.8']);
|
||
|
|
|
||
|
|
$this->expectException(RunnerException::class);
|
||
|
|
|
||
|
|
(new DnsRunner)->run($target);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_rejects_unsafe_domain_format(): void
|
||
|
|
{
|
||
|
|
$target = new Target(['type' => 'domain', 'value' => '../../etc/passwd']);
|
||
|
|
|
||
|
|
$this->expectException(RunnerException::class);
|
||
|
|
|
||
|
|
(new DnsRunner)->run($target);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* example.com is IANA-controlled and has had stable NS/A records for
|
||
|
|
* decades — safe to rely on for a real (non-mocked) DNS lookup.
|
||
|
|
*/
|
||
|
|
public function test_resolves_a_real_stable_domain(): void
|
||
|
|
{
|
||
|
|
$target = new Target(['type' => 'domain', 'value' => 'example.com']);
|
||
|
|
|
||
|
|
$result = (new DnsRunner)->run($target);
|
||
|
|
|
||
|
|
$this->assertArrayHasKey('NS', $result->raw);
|
||
|
|
$this->assertNotEmpty($result->raw['NS']);
|
||
|
|
$this->assertStringContainsString('DNS record', $result->summary);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_reports_no_records_for_a_nonexistent_domain(): void
|
||
|
|
{
|
||
|
|
$target = new Target(['type' => 'domain', 'value' => 'this-domain-should-not-exist-osint-test.invalid']);
|
||
|
|
|
||
|
|
$result = (new DnsRunner)->run($target);
|
||
|
|
|
||
|
|
$this->assertSame([], $result->raw);
|
||
|
|
$this->assertSame('No DNS records found.', $result->summary);
|
||
|
|
}
|
||
|
|
}
|