diff --git a/api/src/gateway/gateway.service.spec.ts b/api/src/gateway/gateway.service.spec.ts index 45eeb8e..b77e669 100644 --- a/api/src/gateway/gateway.service.spec.ts +++ b/api/src/gateway/gateway.service.spec.ts @@ -279,12 +279,17 @@ describe('GatewayService', () => { { _id: 'device2', model: 'iPhone 13' }, ] - it('should return all devices for a user', async () => { + it('should return a user\'s devices without the push token or serial', async () => { mockDeviceModel.find.mockResolvedValue(mockDevices) const result = await service.getDevicesForUser(mockUser) - expect(mockDeviceModel.find).toHaveBeenCalledWith({ user: mockUser._id }) + const [filter, projection] = mockDeviceModel.find.mock.calls[0] + expect(filter).toEqual({ user: mockUser._id }) + // fcmToken is a push credential and serial is a hardware id; neither + // should be shipped to the browser in the device list. + expect(projection).toContain('-fcmToken') + expect(projection).toContain('-serial') expect(result).toEqual(mockDevices) }) }) diff --git a/api/src/gateway/gateway.service.ts b/api/src/gateway/gateway.service.ts index 139ef1f..b0e2c38 100644 --- a/api/src/gateway/gateway.service.ts +++ b/api/src/gateway/gateway.service.ts @@ -140,7 +140,11 @@ export class GatewayService { } async getDevicesForUser(user: User): Promise { - return await this.deviceModel.find({ user: user._id }) + // Exclude the push credential and hardware serial from the client response. + return await this.deviceModel.find( + { user: user._id }, + '-fcmToken -serial', + ) } async getDeviceById(deviceId: string): Promise {