Skip to content

Commit

Permalink
[PM-6012] Added device identifier header when updating trust on key r…
Browse files Browse the repository at this point in the history
…otation (#7807)

(cherry picked from commit 250e7c8)
  • Loading branch information
trmartin4 committed Feb 5, 2024
1 parent 57ccfd8 commit a394fd0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export abstract class DevicesApiServiceAbstraction {
deviceKeyEncryptedDevicePrivateKey: string,
) => Promise<DeviceResponse>;

updateTrust: (updateDevicesTrustRequestModel: UpdateDevicesTrustRequest) => Promise<void>;
updateTrust: (
updateDevicesTrustRequestModel: UpdateDevicesTrustRequest,
deviceIdentifier: string,
) => Promise<void>;

getDeviceKeys: (
deviceIdentifier: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class DeviceTrustCryptoService implements DeviceTrustCryptoServiceAbstrac
trustRequest.currentDevice = currentDeviceUpdateRequest;
trustRequest.otherDevices = [];

await this.devicesApiService.updateTrust(trustRequest);
await this.devicesApiService.updateTrust(trustRequest, deviceIdentifier);
}

async getDeviceKey(): Promise<DeviceKey> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ describe("deviceTrustCryptoService", () => {

await deviceTrustCryptoService.rotateDevicesTrust(fakeNewUserKey, "");

expect(devicesApiService.updateTrust).not.toBeCalled();
expect(devicesApiService.updateTrust).not.toHaveBeenCalled();
});

describe("is on a trusted device", () => {
Expand Down Expand Up @@ -579,14 +579,15 @@ describe("deviceTrustCryptoService", () => {

await deviceTrustCryptoService.rotateDevicesTrust(fakeNewUserKey, "my_password_hash");

expect(devicesApiService.updateTrust).toBeCalledWith(
expect(devicesApiService.updateTrust).toHaveBeenCalledWith(
matches((updateTrustModel: UpdateDevicesTrustRequest) => {
return (
updateTrustModel.currentDevice.encryptedPublicKey ===
"2.ZW5jcnlwdGVkcHVibGlj|ZW5jcnlwdGVkcHVibGlj|ZW5jcnlwdGVkcHVibGlj" &&
updateTrustModel.currentDevice.encryptedUserKey === "4.ZW5jcnlwdGVkdXNlcg=="
);
}),
expect.stringMatching("test_device_identifier"),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,20 @@ export class DevicesApiServiceImplementation implements DevicesApiServiceAbstrac
return new DeviceResponse(result);
}

async updateTrust(updateDevicesTrustRequestModel: UpdateDevicesTrustRequest): Promise<void> {
async updateTrust(
updateDevicesTrustRequestModel: UpdateDevicesTrustRequest,
deviceIdentifier: string,
): Promise<void> {
await this.apiService.send(
"POST",
"/devices/update-trust",
updateDevicesTrustRequestModel,
true,
false,
null,
(headers) => {
headers.set("X-Device-Identifier", deviceIdentifier);
},
);
}

Expand Down

0 comments on commit a394fd0

Please sign in to comment.