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

62 lines
1.7 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\IpApiRunner;
use App\Osint\RunnerException;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class IpApiRunnerTest extends TestCase
{
public function test_parses_successful_lookup(): void
{
Http::fake([
'ip-api.com/*' => Http::response([
'status' => 'success',
'country' => 'United States',
'regionName' => 'Virginia',
'city' => 'Ashburn',
'isp' => 'Google LLC',
'org' => 'Google Public DNS',
'query' => '8.8.8.8',
]),
]);
$target = new Target(['type' => 'ip', 'value' => '8.8.8.8']);
$result = (new IpApiRunner)->run($target);
$this->assertSame('Ashburn, Virginia, United States (Google LLC)', $result->summary);
$this->assertSame('8.8.8.8', $result->raw['query']);
}
public function test_throws_when_lookup_reports_failure(): void
{
Http::fake([
'ip-api.com/*' => Http::response([
'status' => 'fail',
'message' => 'private range',
'query' => '10.0.0.1',
]),
]);
$target = new Target(['type' => 'ip', 'value' => '10.0.0.1']);
$this->expectException(RunnerException::class);
$this->expectExceptionMessage('private range');
(new IpApiRunner)->run($target);
}
public function test_rejects_non_ip_targets(): void
{
$target = new Target(['type' => 'domain', 'value' => 'example.com']);
$this->expectException(RunnerException::class);
(new IpApiRunner)->run($target);
}
}