Reject cross-season reuse of rebellion declaration request IDs
This commit is contained in:
parent
2643a969e7
commit
22a1ec94de
2 changed files with 11 additions and 1 deletions
|
|
@ -47,7 +47,7 @@ export function createRebellionQuests(central,keys,{clock=Date.now,authorizeProd
|
|||
const season=await readActiveXPSeason(polProgressionStore(central),clock());
|
||||
const fields={clanId:input.clanId,officeKey:input.officeKey,expectedTermId:input.expectedTermId,expectedHomeBlockId:input.expectedHomeBlockId},scope=season.season_id+':REBELLION_'+input.requestId;
|
||||
const grant=await keys.issue({accountId:actor.id,keyType:'quest',scopeId:scope,authorize:async(tx,{keyId})=>{
|
||||
const prior=await tx.first('SELECT account_id,fields_json FROM jarvis_generated_instructions WHERE request_id=? AND action_id=?',[input.requestId,DECLARE]);if(prior){if(prior.account_id!==actor.id||prior.fields_json!==JSON.stringify(fields))reject('Rebellion reference conflict.');return;}
|
||||
const prior=await tx.first('SELECT i.account_id,i.fields_json,k.scope_id FROM jarvis_generated_instructions i JOIN organisation_keys k ON k.id=i.key_id WHERE i.request_id=? AND i.action_id=?',[input.requestId,DECLARE]);if(prior){if(prior.scope_id!==scope||prior.account_id!==actor.id||prior.fields_json!==JSON.stringify(fields))reject('Rebellion reference conflict.');return;}
|
||||
const declaration={...await target(tx,actor,input.clanId,input.officeKey),seasonId:season.season_id,declaredAt:clock()};if(declaration.sourceTermId!==input.expectedTermId||declaration.homeBlockId!==input.expectedHomeBlockId)reject('The incumbent or Home Block changed. Review the current decision.');
|
||||
const active=await tx.first("SELECT i.key_id FROM jarvis_generated_instructions i JOIN organisation_keys k ON k.id=i.key_id WHERE i.action_id=? AND i.account_id=? AND i.state='issued' AND k.revoked_at IS NULL AND i.fields_json=?",[DECLARE,actor.id,JSON.stringify(fields)]);if(active)reject('This clan already has an open rebellion quest for that office.');
|
||||
await insert(tx,{keyId,requestId:input.requestId,accountId:actor.id,action:DECLARE,fields,manifest:{declaration},state:'issued'});
|
||||
|
|
|
|||
|
|
@ -26,3 +26,13 @@ test('stale confirmation and revoked evidence cannot transfer a deed or consume
|
|||
assert.equal((await f.db.first('SELECT outcome FROM political_office_terms WHERE id=?',[f.term])).outcome,'winner');
|
||||
}finally{f.db.close();}
|
||||
});
|
||||
|
||||
test('a request UUID from an earlier season cannot create an orphan declaration key',async()=>{
|
||||
const f=await fixture();try{
|
||||
await f.service.declare(f.winner,f.input);const before=(await f.keys.list(f.winner.id)).length;
|
||||
await f.db.query("UPDATE jarvis_pol_progression_seasons SET state='closed' WHERE season_id='S01'");
|
||||
await f.db.query("INSERT INTO jarvis_pol_progression_seasons(season_id,starts_at,ends_at,level_cap,curve_base,state) VALUES('S02',0,?,0,25,'active')",[f.now()+100000]);
|
||||
await assert.rejects(f.service.declare(f.winner,f.input),/reference conflict/);
|
||||
assert.equal((await f.keys.list(f.winner.id)).length,before);
|
||||
}finally{f.db.close();}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff