Files
BetterDesk/web-nodejs/tests/rdclient.protocol.test.js
T
UNITRONIX 35995fed08 fix(remote): send 2FA code with correct protobuf field (#171)
Web remote was encoding Auth2FA under auth2Fa, which protobuf.js drops as an
empty message, so RustDesk peers never received the TOTP code after Verify.
2026-06-06 14:55:03 +02:00

33 lines
1.1 KiB
JavaScript

/**
* Regression: Auth2FA must serialize under auth_2fa (not auth2Fa).
* Wrong field names produce empty Message payloads — peer never receives the code.
*/
const protobuf = require('protobufjs');
const path = require('path');
describe('RDClient Auth2FA protobuf encoding', () => {
let Message;
beforeAll(async () => {
const root = await protobuf.load([
path.join(__dirname, '../protos/message.proto')
]);
Message = root.lookupType('hbb.Message');
});
it('encodes auth_2fa with a non-empty payload', () => {
const msg = Message.fromObject({ auth_2fa: { code: '741626' } });
const buf = Message.encode(msg).finish();
expect(buf.length).toBeGreaterThan(0);
const decoded = Message.decode(buf).toJSON();
expect(decoded.auth_2fa).toEqual({ code: '741626' });
});
it('does not encode auth2Fa camelCase alias (protobuf.js quirk)', () => {
const msg = Message.fromObject({ auth2Fa: { code: '741626' } });
const buf = Message.encode(msg).finish();
expect(buf.length).toBe(0);
});
});