سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 00:30 UTC
test(db): reject direct edits outside canonical posted-source projection
davoodmehraban89 committed
Nov 17, 2026 at 21:36 UTC
6371b719170de54c25b2640203ff339e1e964df9
1 file changed
+35
supabase/tests/wp1_phase1a_stage1_sale_purchase_negatives.sql
+35
@@ -186,4 +186,39 @@ BEGIN
186
RAISE EXCEPTION 'FINORA_NEGATIVE_OR_RETRY_LEFT_VOUCHER';END IF;
187
RAISE NOTICE 'FINORA_SALE_PURCHASE_NEGATIVES_AND_REVERSED_IDEMPOTENCY_PASS';
188
END $t$;
189
+-- A server-owned projection may update only the canonical source/link fields.
190
+-- Direct payload edits and spoofed voucher links remain rejected after posting/reversal.
191
+RESET ROLE;
192
+DO $source_guard$
193
+DECLARE item record;
194
+BEGIN
195
+ FOR item IN SELECT * FROM (VALUES
196
+ ('invoices','SOURCE_C_1'),('purchases','PUR_NEG_1')
197
+ ) AS sources(collection,id)
198
+ LOOP
199
+ BEGIN
200
+ UPDATE public.records
201
+ SET data=jsonb_set(data,'{grandTotal}',to_jsonb(999999))
202
+ WHERE organization_id=current_setting('finora_test.org_a')::uuid
203
+ AND collection=item.collection AND id=item.id;
204
+ RAISE EXCEPTION 'FINORA_POSTED_SOURCE_PAYLOAD_MUTATION_ACCEPTED: %/%',item.collection,item.id;
205
+ EXCEPTION WHEN OTHERS THEN
206
+ IF SQLERRM LIKE 'FINORA_POSTED_SOURCE_PAYLOAD_MUTATION_ACCEPTED:%' THEN RAISE; END IF;
207
+ IF SQLERRM NOT LIKE '%FINORA_POSTED_SOURCE_IMMUTABLE%'
208
+ AND SQLERRM NOT LIKE '%source record linked to posted/reversed accounting history is immutable%' THEN RAISE; END IF;
209
+ END;
210
+ BEGIN
211
+ UPDATE public.records
212
+ SET data=jsonb_set(data,'{journalVoucherId}',to_jsonb('FAKE_VOUCHER'::text))
213
+ WHERE organization_id=current_setting('finora_test.org_a')::uuid
214
+ AND collection=item.collection AND id=item.id;
215
+ RAISE EXCEPTION 'FINORA_POSTED_SOURCE_LINK_MUTATION_ACCEPTED: %/%',item.collection,item.id;
216
+ EXCEPTION WHEN OTHERS THEN
217
+ IF SQLERRM LIKE 'FINORA_POSTED_SOURCE_LINK_MUTATION_ACCEPTED:%' THEN RAISE; END IF;
218
+ IF SQLERRM NOT LIKE '%FINORA_POSTED_SOURCE_LINK_PROJECTION_INVALID%'
219
+ AND SQLERRM NOT LIKE '%source record linked to posted/reversed accounting history is immutable%' THEN RAISE; END IF;
220
+ END;
221
+ END LOOP;
222
+END $source_guard$;
223
+SET LOCAL ROLE authenticated;
224
ROLLBACK;