A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
test(api): make the harvest token tamper test deterministic (#2894)
Hampus045dd5d027d3
diff --git a/fluxer_api/src/api/user/services/__tests__/HarvestDownloadToken.test.ts b/fluxer_api/src/api/user/services/__tests__/HarvestDownloadToken.test.tsindex 96d4aee7f..14c0a7ace 100644--- a/fluxer_api/src/api/user/services/__tests__/HarvestDownloadToken.test.ts+++ b/fluxer_api/src/api/user/services/__tests__/HarvestDownloadToken.test.ts@@ -43,7 +43,10 @@ describe('HarvestDownloadToken', () => {test('rejects a tampered signature', () => {const token = signHarvestDownloadToken(payload(), SECRET);- expect(verifyHarvestDownloadToken(`${token.slice(0, -2)}xy`, SECRET)).toBeNull();+ const [encoded, signature] = token.split('.');+ const tampered = Buffer.from(signature as string, 'base64url');+ tampered[0] = (tampered[0] as number) ^ 0x01;+ expect(verifyHarvestDownloadToken(`${encoded}.${tampered.toString('base64url')}`, SECRET)).toBeNull();});test('rejects malformed input', () => {