Skip to content

Commit fb7805f

Browse files
committed
bug(auth): Address case where sender is empty, null, or missing
1 parent 0403c92 commit fb7805f

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

packages/fxa-auth-server/lib/routes/devices-and-sessions.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ module.exports = (
271271
// command, which should match to an "invoked" event emitted when it was invoked.
272272
for (const msg of response.messages) {
273273
const data = msg.data || {}; // should always be present, but you never know...
274+
275+
// Response validation allows an optional sender, but empty or null values are
276+
// not allowed. Delete empty/null/undefined data to adhere to validation schema.
277+
if (!data.sender) {
278+
delete data.sender;
279+
}
280+
274281
log.info('device.command.retrieved', {
275282
uid,
276283
target: deviceId,

packages/fxa-auth-server/test/local/routes/devices-and-sessions.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,12 @@ describe('/account/device/commands', () => {
784784
last: true,
785785
index: 4,
786786
messages: [
787-
{ index: 3, data: { command: 'three', payload: {} } },
788-
{ index: 4, data: { command: 'four', payload: {} } },
787+
{
788+
index: 2,
789+
data: { command: 'two', payload: {}, sender: '1'.repeat(32) },
790+
},
791+
{ index: 3, data: { command: 'three', payload: {}, sender: '' } },
792+
{ index: 4, data: { command: 'four', payload: {}, sender: null } },
789793
],
790794
};
791795
const mockPushbox = mocks.mockPushbox();
@@ -809,7 +813,18 @@ describe('/account/device/commands', () => {
809813
return runTest(route, mockRequest).then((response) => {
810814
assert.equal(mockPushbox.retrieve.callCount, 1, 'pushbox was called');
811815
assert.calledWithExactly(mockPushbox.retrieve, uid, deviceId, 100, 2);
812-
assert.deepEqual(response, mockResponse);
816+
assert.deepEqual(response, {
817+
last: true,
818+
index: 4,
819+
messages: [
820+
{
821+
index: 2,
822+
data: { command: 'two', payload: {}, sender: '1'.repeat(32) },
823+
},
824+
{ index: 3, data: { command: 'three', payload: {} } },
825+
{ index: 4, data: { command: 'four', payload: {} } },
826+
],
827+
});
813828
});
814829
});
815830

0 commit comments

Comments
 (0)