@davoodmehraban89 / VELYQOR / commits / 88d2344
Fork 0

Intelligence, Advanced Charting & Trading Platform

test(db): verify egress consent, wrong lease, expired lease, revoked-after-claim and public ACL

davoodmehraban89 committed Oct 23, 2026 at 02:34 UTC 88d234432fe348422adce6d68b124d811d47dedf
1 file changed +39 -1
db/tests/alert_runtime_invariants.sql
+39 -1
@@ -144,6 +144,18 @@ BEGIN
144 IF result.event_key <> 'consented-alert' OR result.claim_token IS NULL THEN
145 RAISE EXCEPTION 'consented claimant did not receive authorized pending event';
146 END IF;
147 + IF NOT public.alert_notification_egress_allowed(
148 + result.outbox_id, result.claim_token, t+interval '5 minutes 1 second') THEN
149 + RAISE EXCEPTION 'valid leased and consenting recipient denied at egress';
150 + END IF;
151 + IF public.alert_notification_egress_allowed(
152 + result.outbox_id, gen_random_uuid(), t+interval '5 minutes 1 second') THEN
153 + RAISE EXCEPTION 'wrong lease token authorized message egress';
154 + END IF;
155 + IF public.alert_notification_egress_allowed(
156 + result.outbox_id, result.claim_token, t+interval '6 minutes') THEN
157 + RAISE EXCEPTION 'expired lease permitted message egress';
158 + END IF;
159 PERFORM public.notification_outbox_finish(result.outbox_id,result.claim_token,
160 'UNKNOWN',NULL,t+interval '5 minutes 5 seconds');
161
@@ -172,6 +184,31 @@ BEGIN
184 PERFORM public.notification_outbox_finish(result.outbox_id,result.claim_token,
185 'UNKNOWN',NULL,t+interval '6 minutes 5 seconds');
186
187 + -- Consent can be revoked after a valid claim but BEFORE egress.
188 + -- A second independent DB check must fail even if the lease is current.
189 + PERFORM public.notification_outbox_enqueue(v_other,'egress-after-revocation',
190 + 'BALE',v_recipient,3);
191 + SELECT * INTO result FROM public.alert_notification_claim_consented(
192 + t+interval '7 minutes',30);
193 + IF result.event_key <> 'egress-after-revocation' THEN
194 + RAISE EXCEPTION 'unexpected queue item in revocation preflight';
195 + END IF;
196 +
197 + UPDATE public.alert_notification_consents
198 + SET revoked_at = t + interval '7 minutes 1 second'
199 + WHERE user_id=v_other AND recipient_ref=v_recipient AND channel='BALE';
200 +
201 + IF public.alert_notification_egress_allowed(
202 + result.outbox_id, result.claim_token, t+interval '7 minutes 2 seconds') THEN
203 + RAISE EXCEPTION 'revoked consent still authorized outbound message';
204 + END IF;
205 + IF public.alert_notification_egress_allowed(
206 + result.outbox_id, gen_random_uuid(), t+interval '7 minutes 2 seconds') THEN
207 + RAISE EXCEPTION 'foreign claim permitted outbound message';
208 + END IF;
209 + PERFORM public.notification_outbox_finish(result.outbox_id,result.claim_token,
210 + 'UNKNOWN',NULL,t+interval '7 minutes 3 seconds');
211 +
212 -- A revoked recipient never qualifies, even when the rule is valid.
213 UPDATE public.alert_notification_consents
214 SET revoked_at = t-interval '1 minute'
@@ -218,7 +255,8 @@ BEGIN
255 COALESCE(p.proacl,pg_catalog.acldefault('f',p.proowner))
256 ) AS acl
257 WHERE ns.nspname='public' AND p.proname IN
221 - ('alert_rule_commit','alert_notification_claim_consented')
258 + ('alert_rule_commit','alert_notification_claim_consented',
259 + 'alert_notification_egress_allowed')
260 AND acl.grantee=0 AND acl.privilege_type='EXECUTE'
261 ) THEN
262 RAISE EXCEPTION 'unsafe PUBLIC execute grant';