Intelligence, Advanced Charting & Trading Platform

1 -- Disposable GitHub Actions DB ONLY. This regression verifies that the
2 -- migration's documented default-deny PostgreSQL ACL boundary is real.
3 -- The test role and all test actions are rolled back before completion.
4 BEGIN;
5
6 DO $$
7 BEGIN
8 IF current_database() <> 'velyqor_test' THEN
9 RAISE EXCEPTION 'REFUSE_NON_EPHEMERAL_DATABASE';
10 END IF;
11 END $$;
12
13 CREATE ROLE chartnova_untrusted_probe NOLOGIN;
14 SET LOCAL ROLE chartnova_untrusted_probe;
15
16 DO $$
17 DECLARE
18 function_signature TEXT;
19 table_name TEXT;
20 row_count INTEGER;
21 BEGIN
22 FOREACH table_name IN ARRAY ARRAY[
23 'notification_outbox',
24 'alert_rule_runtime',
25 'alert_notification_consents'
26 ] LOOP
27 IF has_table_privilege(current_user,
28 'public.' || table_name, 'SELECT')
29 OR has_table_privilege(current_user,
30 'public.' || table_name, 'INSERT')
31 OR has_table_privilege(current_user,
32 'public.' || table_name, 'UPDATE') THEN
33 RAISE EXCEPTION 'Untrusted role has table privileges: %', table_name;
34 END IF;
35 BEGIN
36 EXECUTE format('SELECT count(*) FROM public.%I',table_name)
37 INTO row_count;
38 RAISE EXCEPTION 'Untrusted role read protected table: %',table_name;
39 EXCEPTION WHEN insufficient_privilege THEN
40 NULL;
41 END;
42 END LOOP;
43
44 FOREACH function_signature IN ARRAY ARRAY[
45 'public.notification_outbox_enqueue(uuid,text,text,uuid,integer)',
46 'public.notification_outbox_claim(timestamptz,integer)',
47 'public.notification_outbox_finish(uuid,uuid,text,text,timestamptz,integer)',
48 'public.notification_outbox_acknowledge(uuid,uuid,timestamptz)',
49 'public.alert_rule_commit(uuid,text,bigint,jsonb,text,text,uuid,timestamptz)',
50 'public.alert_notification_claim_consented(timestamptz,integer)',
51 'public.alert_notification_begin_egress(uuid,uuid,uuid,text,timestamptz)',
52 'public.alert_notification_egress_allowed(uuid,uuid,uuid,text,timestamptz)'
53 ] LOOP
54 IF has_function_privilege(current_user,
55 function_signature,'EXECUTE') THEN
56 RAISE EXCEPTION 'Untrusted role can execute privileged function: %',
57 function_signature;
58 END IF;
59 END LOOP;
60
61 -- Test the authorization check itself, not just an explicit catalog flag.
62 BEGIN
63 PERFORM public.alert_notification_claim_consented(now(),30);
64 RAISE EXCEPTION 'Untrusted role executed protected claim function';
65 EXCEPTION WHEN insufficient_privilege THEN
66 NULL;
67 END;
68 RAISE NOTICE 'ALERT_RUNTIME_ROLE_ISOLATION_VERIFIED';
69 END $$;
70
71 ROLLBACK;