bus: row 236 r3, a revoke during a settle whoami ends revoked in the 401 and token-unknown branches (Dewey N5, #1742)

This commit is contained in:
jason.woltje committed 2026-10-21 22:42:26 -05:00
1 parent 95ed0b4091
commit 352eb2d00f
3 files changed
+41 -2

No files matched your search

+5 -2
View File
@@ -1808,13 +1808,16 @@ export class Broker {
try {
this.#giteaKeys.unregister(business, agent);
} catch {}
this.#store.transaction(() => {
return this.#store.transaction(() => {
if (revoked()) return 'revoked';
this.#store.run('DELETE FROM gitea_grants WHERE business=? AND agent=?', business, agent);
this.#giteaFailed(business, decision, agent, 'grant-lost', { user, ...(serviceLeft.length ? { serviceLeft } : {}) });
return 'grant-lost';
});
return 'grant-lost';
}
if (who.status === 200 && who.id !== null) {
// A revoke during the whoami unlinked the file: holding it again would name a file that is gone.
if (this.#store.transaction(revoked)) return 'revoked';
// A live token this grant didn't mint: memory drops it, and the file, the record and both tokens stay.
try {
this.#giteaKeys.hold(business, agent);
+29
View File
@@ -991,6 +991,35 @@ test('X-G11: a revoke while a sweep settles a rotation, forward or back, ends it
}
});
test('X-G11: a revoke during a settle whoami that finds a foreign token or a 401 ends it revoked, not held or lost', async (t) => {
for (const kind of ['grant-token-unknown', 'grant-lost']) {
const f = await setup(t);
const { id } = await openRotation(f);
// A token this grant did not mint, or one Gitea does not know.
const file = kind === 'grant-token-unknown' ? f.gitea.addToken(USER, 'foreign', SEAT_SCOPES).sha1 : 'f'.repeat(40);
writeFileSync(f.tokenFile, file + '\n');
let release;
const held = new Promise((r) => (release = r));
const seat = (e) => e.method === 'GET' && e.path === '/api/v1/token' && e.as !== 'mosaic-grant';
f.gitea.rule(seat, async () => {
await held;
return { pass: true };
});
const sweep = f.call('human', 'grants.sweep', { service: 'gitea' });
await until(() => f.gitea.requests.some(seat));
const revoke = f.call('human', 'grants.revoke', { service: 'gitea', agent: 'coder', reason: 'stop' });
release();
await revoke;
const swept = await sweep;
await f.broker.giteaIdle();
assert.deepEqual(swept.settled, [{ decision: id, outcome: 'revoked' }], kind);
assert.equal(f.ended(id).code, 'revoked');
assert.equal(f.grantEvents().some((e) => e.grantDecision === id && e.code === kind), false);
assert.deepEqual([...tokenUnknown(f.store, 'demo').keys()], []);
assert.equal(f.record(), undefined);
}
});
test('X-G12: a token that reaches wider than its forks fails with the repository named', async (t) => {
const collab = await setup(t);
collab.gitea.addRepo('other', 'secret', { collaborators: [USER] });