1
0
Fork 0
fahrPool/supabase/tests/firmen_app_icon_pfad_test.sql

68 lines
3.1 KiB
PL/PgSQL

begin;
select plan(7);
insert into public.firmen (id, name) values ('00000000-0000-0000-0000-00000000f002', 'Firma B');
insert into auth.users (id, email) values
('a0000000-0000-0000-0000-0000000000a2', 'dispo-a@icon.test.local'),
('b0000000-0000-0000-0000-0000000000b1', 'admin-b@icon.test.local'),
('b0000000-0000-0000-0000-0000000000b2', 'dispo-b@icon.test.local');
update public.profiles set firma_id = '00000000-0000-0000-0000-00000000f001', role = 'disponent' where id = 'a0000000-0000-0000-0000-0000000000a2';
update public.profiles set firma_id = '00000000-0000-0000-0000-00000000f002', role = 'admin' where id = 'b0000000-0000-0000-0000-0000000000b1';
update public.profiles set firma_id = '00000000-0000-0000-0000-00000000f002', role = 'disponent' where id = 'b0000000-0000-0000-0000-0000000000b2';
-- ====================== Disponent B: darf die Firma nicht aendern
set local role authenticated;
set local request.jwt.claims to '{"sub": "b0000000-0000-0000-0000-0000000000b2", "role": "authenticated"}';
update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/app-icon-1.png'
where id = '00000000-0000-0000-0000-00000000f002';
select is((select app_icon_pfad from public.firmen where id = '00000000-0000-0000-0000-00000000f002'), null,
'Disponent kann app_icon_pfad nicht setzen');
-- ====================== Admin B
set local request.jwt.claims to '{"sub": "b0000000-0000-0000-0000-0000000000b1", "role": "authenticated"}';
select lives_ok(
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/app-icon-1.png'
where id = '00000000-0000-0000-0000-00000000f002' $$,
'Admin setzt App-Icon-Pfad im eigenen Firmenordner'
);
select throws_ok(
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/../00000000-0000-0000-0000-00000000f001/app-icon-1.png'
where id = '00000000-0000-0000-0000-00000000f002' $$,
'23514', null,
'Pfad mit ../ in den Ordner einer fremden Firma wird abgelehnt'
);
select throws_ok(
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/x.png'
where id = '00000000-0000-0000-0000-00000000f002' $$,
'23514', null,
'Pfad im eigenen Ordner, aber nicht im Format app-icon-<zahl>.<endung>, wird abgelehnt'
);
select throws_ok(
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f001/app-icon-1.png'
where id = '00000000-0000-0000-0000-00000000f002' $$,
'23514', null,
'Pfad im Ordner einer fremden Firma wird abgelehnt'
);
-- ====================== Nutzer A: sieht Firma B nicht
set local request.jwt.claims to '{"sub": "a0000000-0000-0000-0000-0000000000a2", "role": "authenticated"}';
select is_empty(
$$ select app_icon_pfad from public.firmen where id = '00000000-0000-0000-0000-00000000f002' $$,
'Nutzer von Firma A liest app_icon_pfad von Firma B nicht'
);
reset role;
select is((select app_icon_pfad from public.firmen where id = '00000000-0000-0000-0000-00000000f002'),
'00000000-0000-0000-0000-00000000f002/app-icon-1.png', 'Gueltiger Pfad ist gespeichert');
select * from finish();
rollback;