Files
portal/app/tests/Feature/Database/TenantsRlsAndRoutingTzTest.php
T
Дмитрий 60c640e88a
Accessibility (Pa11y live) / a11y (push) Has been cancelled
SAST — Semgrep / Semgrep SAST scan (push) Has been cancelled
feat(db): RLS на tenants + created_at TZ (schema v8.51)
2026-06-22 18:03:42 +03:00

40 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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');
});