MC/website/integrations/mybb/test-board-key-publication.php
2026-11-27 23:43:05 +00:00

19 lines
2.4 KiB
PHP

<?php
define('IN_MYBB',1);require __DIR__.'/board-key-publication.php';
function check($condition,$message){if(!$condition)throw new RuntimeException($message);}
function rejected(callable $call){try{$call();}catch(Throwable $e){return;}throw new RuntimeException('Invalid board batch was accepted');}
$desired=['version'=>1,'organisation'=>['kind'=>'clan','id'=>'11111111-1111-4111-8111-111111111111','name'=>'A & B','lifecycle'=>'active'],'template'=>['id'=>'private-organisation','version'=>1]];
$json=json_encode($desired,JSON_UNESCAPED_SLASHES);$record=['keyId'=>'22222222-2222-4222-8222-222222222222','revision'=>1,'fingerprint'=>hash('sha256',$json),'desiredJson'=>$json];
$parsed=dune_board_key_records([$record]);check($parsed[0]['organisation']['name']==='A & B','Organisation title must survive key decoding');
foreach([array_merge($record,['revision'=>1.5]),array_merge($record,['fingerprint'=>str_repeat('0',64)]),array_merge($record,['keyId'=>'not-a-key'])]as $invalid)rejected(fn()=>dune_board_key_records([$invalid]));
rejected(fn()=>dune_board_key_records([$record,$record]));
$unknown=$desired;$unknown['template']['version']=2;$raw=json_encode($unknown);rejected(fn()=>dune_board_key_records([array_merge($record,['desiredJson'=>$raw,'fingerprint'=>hash('sha256',$raw)])]));
$existing=['board_key_id'=>$record['keyId'],'board_revision'=>1,'board_fingerprint'=>$record['fingerprint'],'fid'=>55,'member_gid'=>16,'leader_gid'=>17];
check(dune_board_key_order(null,$record)==='apply','New record must adopt its existing organisation mapping');
check(dune_board_key_order($existing,$record)==='replay','Same revision/hash must be replayable');
check(dune_board_key_order($existing,array_merge($record,['revision'=>2]))==='apply','Newer board revision must apply');
check(dune_board_key_order(array_merge($existing,['board_revision'=>2]),$record)==='superseded','Older delivery must not restore old state');
check(dune_board_key_order($existing,array_merge($record,['fingerprint'=>str_repeat('f',64)]))==='review','Same revision with different data must fail closed');
check(dune_board_key_order($existing,array_merge($record,['keyId'=>'33333333-3333-4333-8333-333333333333']))==='review','A different key must not replace the adopted native mapping');
check($existing['fid']===55&&$existing['member_gid']===16&&$existing['leader_gid']===17,'Ordering must not rewrite native identity');
echo "Native board key payload, revision, replay and mapping checks passed\n";