62 lines
2.9 KiB
PHP
62 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\User;
|
|
use App\Services\TerritoryGeometryImport;
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
use Illuminate\Support\Facades\Crypt;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
use Tests\TestCase;
|
|
|
|
class TerritoryGeometryApprovedAdministrationTest extends TestCase
|
|
{
|
|
use DatabaseTransactions;
|
|
|
|
public function test_existing_superuser_with_completed_mfa_reaches_importer_without_legacy_manager_grant(): void
|
|
{
|
|
$actor = $this->holder();
|
|
$this->actingAs($actor)->withSession(['portal.mfa_actor' => $actor->id, 'portal.mfa_at' => time(), 'portal.access_revision' => (int) $actor->portal_access_revision]);
|
|
$this->assertFalse($actor->can('manage-portal'));
|
|
// A missing exemplar must produce the source error, not deny the approved actor.
|
|
try {
|
|
app(TerritoryGeometryImport::class)->preview($actor, 1);
|
|
$this->fail('The deliberately absent source must be reported.');
|
|
} catch (HttpException $exception) {
|
|
$this->assertSame(422, $exception->getStatusCode());
|
|
}
|
|
$this->getJson('/management/territory-geometry-import')->assertStatus(422);
|
|
$this->postJson('/management/territory-geometry-import', [])->assertStatus(422);
|
|
$this->assertFalse($actor->can('manage-portal'));
|
|
}
|
|
|
|
public function test_superuser_without_mfa_session_cannot_import(): void
|
|
{
|
|
$actor = $this->holder();
|
|
$this->actingAs($actor)->getJson('/management/territory-geometry-import')->assertForbidden();
|
|
$this->postJson('/management/territory-geometry-import', [])->assertForbidden();
|
|
}
|
|
|
|
public function test_ordinary_account_does_not_gain_cartographic_administration(): void
|
|
{
|
|
$this->holder();
|
|
$actor = User::factory()->create();
|
|
$this->actingAs($actor)->getJson('/management/territory-geometry-import')->assertForbidden();
|
|
$this->postJson('/management/territory-geometry-import', [])->assertForbidden();
|
|
}
|
|
|
|
private function holder(): User
|
|
{
|
|
$identity = DB::selectOne('select current_database() as name,inet_server_port() as port');
|
|
$this->assertSame('simulator_fiscal_delta_20261021_test', $identity->name);
|
|
$this->assertSame(55441, (int) $identity->port);
|
|
config(['portal.profile_access_enabled' => true, 'portal.managers' => [], 'geometry-import.enabled' => true,
|
|
'geometry-import.directory' => storage_path('app/private/nonexistent-demarcation-source')]);
|
|
$actor = User::factory()->create(['two_factor_secret' => Crypt::encryptString('JBSWY3DPEHPK3PXP'), 'two_factor_confirmed_at' => now()]);
|
|
$other = User::factory()->create();
|
|
DB::table('portal_superuser_pair')->updateOrInsert(['id' => 1], ['first_user_id' => $actor->id, 'second_user_id' => $other->id, 'approved_by' => $other->id]);
|
|
return $actor;
|
|
}
|
|
}
|