Files
portal/app/tests/Feature/Database/TenantsRlsAndRoutingTzTest.php
T

40 lines
1.6 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
use Illuminate\Support\Facades\DB;
// Защита-в-глубину: на таблице tenants (ключ — id) должна быть включена RLS
// с политикой самоизоляции (компания видит только свою строку), чтобы у БД был
// второй замок поверх app-фильтра. Админка/онбординг идут под BYPASSRLS-ролями —
// их это не задевает. См. db/CHANGELOG_schema.md.
it('на таблице tenants включена RLS', function () {
$row = DB::selectOne(
"select relrowsecurity::int as rls from pg_class
where relname = 'tenants' and relnamespace = 'public'::regnamespace"
);
expect($row)->not->toBeNull();
expect((int) $row->rls)->toBe(1);
});
it('у tenants есть политика самоизоляции по id', function () {
$pol = DB::selectOne(
"select qual from pg_policies
where schemaname = 'public' and tablename = 'tenants'
and policyname = 'tenants_self_isolation'"
);
expect($pol)->not->toBeNull();
expect($pol->qual)->toContain('current_setting');
expect($pol->qual)->toContain('id');
});
it('project_routing_snapshots.created_at имеет тип timestamptz', function () {
$col = DB::selectOne(
"select data_type from information_schema.columns
where table_name = 'project_routing_snapshots' and column_name = 'created_at'"
);
expect($col)->not->toBeNull();
expect($col->data_type)->toBe('timestamp with time zone');
});