Skip to content

Commit 701b98b

Browse files
committed
test: fix two flaky backend tests
- silence route logs in billing route tests; stdout can corrupt the node:test IPC stream (nodejs/node#64061) - tamper with the first ciphertext character; the old edit sometimes changed only base64 padding bits
1 parent 4f4ccca commit 701b98b

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎backend/tests/billingRoutes.test.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ beforeEach(() => {
4747
});
4848
currentUser = { _id: USER_ID, githubId: '1', username: 'dev', email: '[email protected]', trialEndsAt: new Date(Date.now() + 60_000) };
4949
stripeCalls = { customers: [], sessions: [], portal: [] };
50+
// Route logs on stdout can corrupt the node:test IPC stream (nodejs/node#64061)
51+
mock.method(console, 'log', () => {});
52+
mock.method(console, 'error', () => {});
5053
mock.method(User, 'findById', () => {
5154
const result = Promise.resolve(currentUser);
5255
result.select = () => Promise.resolve(currentUser);

‎backend/tests/crypto.test.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ test('returns legacy plaintext unchanged', () => {
2828

2929
test('rejects tampered ciphertext', () => {
3030
const encrypted = encryptSecret('value');
31-
const last = encrypted.at(-2) === 'A' ? 'B' : 'A';
32-
assert.equal(decryptSecret(encrypted.slice(0, -2) + last + encrypted.at(-1)), null);
31+
// Edit the first ciphertext character: trailing base64 characters can hold only padding bits
32+
const i = encrypted.lastIndexOf(':') + 1;
33+
const swapped = encrypted[i] === 'A' ? 'B' : 'A';
34+
assert.equal(decryptSecret(encrypted.slice(0, i) + swapped + encrypted.slice(i + 1)), null);
3335
});

0 commit comments

Comments
 (0)