fix(app): grant expiry ends the chosen day in Paris; species order 0..9999 (V1-2.5 L2)
Owner checkpoint 2026-11-02: expiry 23:59:59.999 Europe/Paris (picker, validation, display), tests under non-Paris zones and DST days; M7 redefines create_species and update_inactive_species with the range check; pgTAP 015 and 022; « Relecteur ou relectrice »; object_conflict EN; setup key selectable, no Copy.
This commit is contained in:
1 parent
4111efa1d1
commit
51225cacf6
17 files changed
+437
-61
No files matched your search
@@ -5,7 +5,7 @@
|
||||
-- proven in packages/supabase/tests/sandbox/sheets.sandbox.ts, the seed owner's
|
||||
-- factors on an upgraded stack in seed-owner-mfa.sandbox.ts.
|
||||
begin;
|
||||
select plan(37);
|
||||
select plan(44);
|
||||
|
||||
insert into auth.users (id, email, email_confirmed_at) values
|
||||
('d0000000-0000-0000-0000-000000000001', 'own@t.local', now()), -- owner
|
||||
@@ -190,6 +190,57 @@ select ok(not private.grant_active('d0000000-0000-0000-0000-00000000000c','catal
|
||||
set local role authenticated;
|
||||
select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2');
|
||||
|
||||
-- Expiry instants (owner 2026-11-02, Europe/Paris end of day): the stored
|
||||
-- instant is the same whatever the session TimeZone; the DST days are future
|
||||
-- ones the RPC accepts. One fresh account per grant (one active row per kind).
|
||||
reset role;
|
||||
insert into auth.users (id, email, email_confirmed_at) values
|
||||
('d0000000-0000-0000-0000-0000000000b1', 'tz1@t.local', now()),
|
||||
('d0000000-0000-0000-0000-0000000000b2', 'tz2@t.local', now()),
|
||||
('d0000000-0000-0000-0000-0000000000b3', 'tz3@t.local', now()),
|
||||
('d0000000-0000-0000-0000-0000000000b4', 'tz4@t.local', now()),
|
||||
('d0000000-0000-0000-0000-0000000000b5', 'st1@t.local', now()),
|
||||
('d0000000-0000-0000-0000-0000000000b6', 'st2@t.local', now()),
|
||||
('d0000000-0000-0000-0000-0000000000b7', 'st3@t.local', now());
|
||||
set local role authenticated;
|
||||
select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2');
|
||||
set local timezone to 'UTC';
|
||||
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b1', 'catalog_reader', 'tz', null, '2027-03-28T23:59:59.999+02:00');
|
||||
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b2', 'catalog_reader', 'tz', null, '2027-10-31T23:59:59.999+01:00');
|
||||
set local timezone to 'America/New_York';
|
||||
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b3', 'catalog_reader', 'tz', null, '2027-03-28T23:59:59.999+02:00');
|
||||
select public.grant_catalog_right('d0000000-0000-0000-0000-0000000000b4', 'catalog_reader', 'tz', null, '2027-10-31T23:59:59.999+01:00');
|
||||
reset role;
|
||||
select is((select string_agg(to_char(expires_at at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS'), ',' order by user_id)
|
||||
from public.anatomical_catalog_grants where user_id in (
|
||||
'd0000000-0000-0000-0000-0000000000b1', 'd0000000-0000-0000-0000-0000000000b2')),
|
||||
'2027-03-28T21:59:59.999,2027-10-31T22:59:59.999', 'the 2027 DST days store the same instants under UTC');
|
||||
select is((select string_agg(to_char(expires_at at time zone 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS.MS'), ',' order by user_id)
|
||||
from public.anatomical_catalog_grants where user_id in (
|
||||
'd0000000-0000-0000-0000-0000000000b3', 'd0000000-0000-0000-0000-0000000000b4')),
|
||||
'2027-03-28T21:59:59.999,2027-10-31T22:59:59.999', 'the 2027 DST days store the same instants under America/New_York');
|
||||
select is((select count(*)::int from public.anatomical_catalog_grants where user_id in (
|
||||
'd0000000-0000-0000-0000-0000000000b1', 'd0000000-0000-0000-0000-0000000000b2')
|
||||
and expires_at in ('2027-03-28T21:59:59.999Z'::timestamptz, '2027-10-31T22:59:59.999Z'::timestamptz)), 2,
|
||||
'the stored instants equal the Paris end of day (summer +02:00, winter +01:00)');
|
||||
set local timezone to 'UTC';
|
||||
-- The list state at each boundary (direct inserts with an earlier granted_at).
|
||||
insert into public.anatomical_catalog_grants (user_id, grant_kind, reason, granted_by, granted_at, expires_at) values
|
||||
('d0000000-0000-0000-0000-0000000000b5', 'catalog_reader', 'x', 'd0000000-0000-0000-0000-000000000001', now() - interval '2 days', now() - interval '1 minute'),
|
||||
('d0000000-0000-0000-0000-0000000000b6', 'catalog_reader', 'x', 'd0000000-0000-0000-0000-000000000001', now() - interval '2 days', now() + interval '1 minute'),
|
||||
('d0000000-0000-0000-0000-0000000000b7', 'catalog_reader', 'x', 'd0000000-0000-0000-0000-000000000001', now() - interval '2 days', now() + interval '30 days 1 minute');
|
||||
set local role authenticated;
|
||||
select pg_temp.act('d0000000-0000-0000-0000-000000000001', 'd1000000-0000-0000-0000-000000000001', 'aal2');
|
||||
create function pg_temp.grant_state(p_user uuid) returns text language sql stable as $$
|
||||
select (e ->> 'state') || '/' || (e ->> 'effective')
|
||||
from jsonb_array_elements(public.list_catalog_grants()) e where (e ->> 'user_id')::uuid = p_user;
|
||||
$$;
|
||||
grant execute on function pg_temp.grant_state(uuid) to authenticated;
|
||||
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b5'), 'expired/false', 'expiry 1 minute ago: expired, not effective');
|
||||
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b6'), 'expiring/true', 'expiry in 1 minute: expiring, effective');
|
||||
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b7'), 'active/true', 'expiry in 30 days and 1 minute: active, effective');
|
||||
select is(pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b3') like 'expiring/%' or pg_temp.grant_state('d0000000-0000-0000-0000-0000000000b3') like 'active/%', true, 'a future DST-day grant is listed live');
|
||||
|
||||
-- only the owner (aal2) lists grants
|
||||
select ok((select jsonb_typeof(public.list_catalog_grants()) = 'array'), 'owner lists grants');
|
||||
select pg_temp.act('d0000000-0000-0000-0000-00000000000a', 'd1000000-0000-0000-0000-00000000000a', 'aal2');
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
-- unknown, deleted, personal or forbidden sheet gets one answer. Fixtures are
|
||||
-- scoped to the ids created here.
|
||||
begin;
|
||||
select plan(43);
|
||||
select plan(60);
|
||||
|
||||
-- Accounts. O owner, A admin, E admin + editor, V reviewer, P admin +
|
||||
-- publisher, R reader, N no right. Every one has a verified factor and a live
|
||||
@@ -193,5 +193,37 @@ select is((select string_agg(p.provolatile::text, ',' order by p.proname) from p
|
||||
where n.nspname = 'public' and p.proname in ('list_official_sheets_admin', 'get_official_sheet_admin')), 's,s',
|
||||
'both reads are stable: no write path');
|
||||
|
||||
-- ============ Species order range (owner 2026-11-02) ============
|
||||
-- The stored order of an inactive species, read with the owner's rights (RLS hides inactive rows).
|
||||
create function pg_temp.stored_order(p_id text) returns text language plpgsql security definer as $$
|
||||
begin
|
||||
return (select sort_order::text from public.species where id = p_id);
|
||||
end $$;
|
||||
grant execute on function pg_temp.stored_order(text) to authenticated;
|
||||
select pg_temp.as_user('E', 'aal2');
|
||||
select is(pg_temp.val($$ select public.create_species('m22-neg', 'Négatif', 'Negative', -1) $$), 'P0001 invalid_input', 'create_species: -1 refused');
|
||||
select is(pg_temp.val($$ select public.create_species('m22-big', 'Grand', 'Big', 10000) $$), 'P0001 invalid_input', 'create_species: 10 000 refused');
|
||||
select is(pg_temp.val($$ select public.create_species('m22-zero', 'Zéro', 'Zero', 0) $$), 'm22-zero', 'create_species: 0 accepted');
|
||||
select is(pg_temp.val($$ select public.create_species('m22-max', 'Max', 'Max', 9999) $$), 'm22-max', 'create_species: 9 999 accepted');
|
||||
select is(pg_temp.val($$ select public.create_species('m22-null', 'Nul', 'Null', null) $$), 'm22-null', 'create_species: null accepted');
|
||||
select is(coalesce(pg_temp.stored_order('m22-neg'), 'none') || '/' || coalesce(pg_temp.stored_order('m22-big'), 'none'), 'none/none', 'create_species: refused orders store nothing');
|
||||
select is(pg_temp.stored_order('m22-zero') || ',' || pg_temp.stored_order('m22-max') || ',' || pg_temp.stored_order('m22-null'),
|
||||
'0,9999,100', 'create_species: stored orders, null keeps the default 100');
|
||||
select is(pg_temp.val($$ select public.update_inactive_species('m22-zero', 'Zéro', 'Zero', -1) $$), 'P0001 invalid_input', 'update_inactive_species: -1 refused');
|
||||
select is(pg_temp.val($$ select public.update_inactive_species('m22-zero', 'Zéro', 'Zero', 10000) $$), 'P0001 invalid_input', 'update_inactive_species: 10 000 refused');
|
||||
select is(pg_temp.val($$ select public.update_inactive_species('m22-zero', 'Zéro', 'Zero', 9999) $$), 'm22-zero', 'update_inactive_species: 9 999 accepted');
|
||||
select is(pg_temp.stored_order('m22-zero'), '9999', 'update_inactive_species: 9 999 stored');
|
||||
select is(pg_temp.val($$ select public.update_inactive_species('m22-zero', 'Zéro', 'Zero', 0) $$), 'm22-zero', 'update_inactive_species: 0 accepted');
|
||||
select is(pg_temp.stored_order('m22-zero'), '0', 'update_inactive_species: 0 stored');
|
||||
select is(pg_temp.val($$ select public.update_inactive_species('m22-max', 'Max', 'Max', null) $$), 'm22-max', 'update_inactive_species: null accepted');
|
||||
select is(pg_temp.stored_order('m22-max'), '9999', 'update_inactive_species: null keeps the stored order');
|
||||
select pg_temp.as_user('V', 'aal2');
|
||||
select is(pg_temp.val($$ select public.create_species('m22-rev', 'Rev', 'Rev', 5) $$), '42501 rights.capability', 'create_species: a reviewer is still refused');
|
||||
reset role;
|
||||
select is((select string_agg(p.prosecdef::text || '/' || (p.proconfig = array['search_path=""'])::text, ',' order by p.proname) from pg_proc p
|
||||
join pg_namespace n on n.oid = p.pronamespace
|
||||
where n.nspname = 'public' and p.proname in ('create_species', 'update_inactive_species')),
|
||||
'true/true,true/true', 'both species RPCs: security definer, empty search_path');
|
||||
|
||||
select * from finish();
|
||||
rollback;
|
||||
Reference in new issue
Block a user