Files
osint/tests/Feature/TargetManagementTest.php
cedry2k1992andClaude Sonnet 5 873699e23e Initial commit: Laravel OSINT platform
Multi-user OSINT investigation tool with owner-controlled per-user and
per-group access grants. Includes Sherlock, theHarvester, crt.sh, WHOIS,
and ip-api.com collectors wired through a pluggable Runner/queue pipeline,
investigation search, and printable/CSV/JSON reporting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-20 10:22:05 +03:00

106 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Investigation;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class TargetManagementTest extends TestCase
{
use RefreshDatabase;
public function test_editor_can_add_a_valid_target(): void
{
$owner = User::factory()->create();
$investigation = Investigation::factory()->for($owner, 'owner')->create();
$this->actingAs($owner)
->post(route('investigations.targets.store', $investigation), [
'type' => 'username',
'value' => 'valid_user.name',
])
->assertRedirect(route('investigations.show', $investigation));
$this->assertDatabaseHas('targets', [
'investigation_id' => $investigation->id,
'type' => 'username',
'value' => 'valid_user.name',
]);
}
public function test_username_target_rejects_unsafe_characters(): void
{
$owner = User::factory()->create();
$investigation = Investigation::factory()->for($owner, 'owner')->create();
$this->actingAs($owner)
->post(route('investigations.targets.store', $investigation), [
'type' => 'username',
'value' => '../../etc/passwd',
])
->assertSessionHasErrors('value');
$this->assertDatabaseCount('targets', 0);
}
public function test_email_target_requires_valid_email_format(): void
{
$owner = User::factory()->create();
$investigation = Investigation::factory()->for($owner, 'owner')->create();
$this->actingAs($owner)
->post(route('investigations.targets.store', $investigation), [
'type' => 'email',
'value' => 'not-an-email',
])
->assertSessionHasErrors('value');
}
public function test_ip_target_requires_valid_ip_format(): void
{
$owner = User::factory()->create();
$investigation = Investigation::factory()->for($owner, 'owner')->create();
$this->actingAs($owner)
->post(route('investigations.targets.store', $investigation), [
'type' => 'ip',
'value' => 'not-an-ip',
])
->assertSessionHasErrors('value');
}
public function test_viewer_cannot_add_targets(): void
{
$owner = User::factory()->create();
$viewer = User::factory()->create();
$investigation = Investigation::factory()->for($owner, 'owner')->create();
$investigation->users()->attach($viewer, ['role' => 'viewer']);
$this->actingAs($viewer)
->post(route('investigations.targets.store', $investigation), [
'type' => 'username',
'value' => 'someone',
])
->assertForbidden();
}
public function test_editor_can_delete_a_target(): void
{
$owner = User::factory()->create();
$investigation = Investigation::factory()->for($owner, 'owner')->create();
$target = $investigation->targets()->create([
'type' => 'username',
'value' => 'someone',
'created_by' => $owner->id,
]);
$this->actingAs($owner)
->delete(route('investigations.targets.destroy', [$investigation, $target]))
->assertRedirect(route('investigations.show', $investigation));
$this->assertDatabaseMissing('targets', ['id' => $target->id]);
}
}