-- Integration checks against a database with two existing test/seed accounts. -- All fixture rows and edits are rolled back; no storage uploads or game revisions. begin; do $$ declare owner uuid; player uuid; root uuid; child uuid; m jsonb; cm jsonb; info jsonb; begin select id into owner from public.profiles where role='moderator' limit 1; select id into player from public.profiles where id<>owner limit 1; if owner is null or player is null then raise exception 'Seed two accounts before running this test'; end if; m:=jsonb_build_object('format','minegeo-dataset/v1','minecraftVersion','1.21.11','dimension','minecraft:overworld', 'source','plugin','name','Server check rollback fixture','serverName','Server check rollback fixture','serverAddress',' PLAY.EXAMPLE.COM.:25565 ', 'north','-z','bounds',jsonb_build_object('minX',0,'minZ',0,'maxX',64,'maxZ',64), 'viewpoints',(select jsonb_agg(jsonb_build_object('id','p'||n,'x',n,'y',65,'z',n)) from generate_series(1,5) n), 'assets',jsonb_build_array(jsonb_build_object('path','terrain.json.gz','bytes',1,'sha256',repeat('a',64)))); root:=public.create_upload(owner,m); update public.datasets set state='draft' where id=root; update public.dataset_inputs set validated=true where dataset_id=root; perform public.set_contributions(root,owner,true); info:=public.contribution_capacity(root,player); if info->>'serverAddress'<>'play.example.com' then raise exception 'Initial address not canonical'; end if; cm:=m||jsonb_build_object('contributionTo',root,'viewpoints',jsonb_build_array(m->'viewpoints'->0)); begin perform public.create_upload(player,cm||jsonb_build_object('serverAddress','other.example.com')); raise exception 'Mismatch accepted'; exception when others then if sqlerrm not like 'Wrong capture server:%' then raise; end if; end; begin perform public.create_upload(player,cm-'serverAddress'); raise exception 'Missing capture address accepted'; exception when others then if sqlerrm not like 'Wrong capture server:%' then raise; end if; end; begin perform public.set_contribution_server(root,player,null); raise exception 'Non-owner changed address'; exception when others then if sqlerrm<>'Map owner permission required' then raise; end if; end; child:=public.create_upload(player,cm||jsonb_build_object('serverAddress','play.example.com')); perform public.set_contribution_server(root,owner,'other.example.com:25566'); begin perform public.finalize_upload(child,player); raise exception 'Retry finalized after the server changed'; exception when others then if sqlerrm not like 'Wrong capture server:%' then raise; end if; end; update public.datasets set state='draft',panorama_count=1 where id=child; update public.dataset_inputs set validated=true where dataset_id=child; begin perform public.submit_draft(child,player); raise exception 'Mismatching submission accepted'; exception when others then if sqlerrm not like 'Wrong capture server:%' then raise; end if; end; perform public.set_contribution_server(root,owner,''); perform public.submit_draft(child,player); perform public.set_contribution_server(root,owner,'other.example.com'); begin perform public.review_contribution(root,child,owner,'accept'); raise exception 'Owner accepted mismatching contribution while check enabled'; exception when others then if sqlerrm not like 'Wrong capture server:%' then raise; end if; end; perform public.set_contribution_server(root,owner,null); perform public.review_contribution(root,child,owner,'accept'); if (select contribution_status from public.datasets where id=child)<>'accepted' then raise exception 'Cleared check did not allow owner approval'; end if; if public.normalize_server_address('[2001:DB8::1]:25565')<>'[2001:db8::1]' then raise exception 'IPv6 normalization differs'; end if; if has_function_privilege('anon','public.set_contribution_server(uuid,uuid,text)','execute') or has_function_privilege('authenticated','public.check_contribution_server(uuid,uuid)','execute') then raise exception 'Private RPC exposed'; end if; end; $$; select 'server address enforcement, overrides, opt-out, retries, approvals and permissions passed' as result; rollback;