mirror of
https://github.com/bitwarden/browser
synced 2025-12-12 14:23:32 +00:00
[PM-6012] Added device identifier header when updating trust on key rotation (#7807)
This commit is contained in:
@@ -18,7 +18,10 @@ export abstract class DevicesApiServiceAbstraction {
|
|||||||
deviceKeyEncryptedDevicePrivateKey: string,
|
deviceKeyEncryptedDevicePrivateKey: string,
|
||||||
) => Promise<DeviceResponse>;
|
) => Promise<DeviceResponse>;
|
||||||
|
|
||||||
updateTrust: (updateDevicesTrustRequestModel: UpdateDevicesTrustRequest) => Promise<void>;
|
updateTrust: (
|
||||||
|
updateDevicesTrustRequestModel: UpdateDevicesTrustRequest,
|
||||||
|
deviceIdentifier: string,
|
||||||
|
) => Promise<void>;
|
||||||
|
|
||||||
getDeviceKeys: (
|
getDeviceKeys: (
|
||||||
deviceIdentifier: string,
|
deviceIdentifier: string,
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ export class DeviceTrustCryptoService implements DeviceTrustCryptoServiceAbstrac
|
|||||||
trustRequest.currentDevice = currentDeviceUpdateRequest;
|
trustRequest.currentDevice = currentDeviceUpdateRequest;
|
||||||
trustRequest.otherDevices = [];
|
trustRequest.otherDevices = [];
|
||||||
|
|
||||||
await this.devicesApiService.updateTrust(trustRequest);
|
await this.devicesApiService.updateTrust(trustRequest, deviceIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDeviceKey(): Promise<DeviceKey> {
|
async getDeviceKey(): Promise<DeviceKey> {
|
||||||
|
|||||||
@@ -502,7 +502,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
await deviceTrustCryptoService.rotateDevicesTrust(fakeNewUserKey, "");
|
await deviceTrustCryptoService.rotateDevicesTrust(fakeNewUserKey, "");
|
||||||
|
|
||||||
expect(devicesApiService.updateTrust).not.toBeCalled();
|
expect(devicesApiService.updateTrust).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("is on a trusted device", () => {
|
describe("is on a trusted device", () => {
|
||||||
@@ -579,7 +579,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
|
|
||||||
await deviceTrustCryptoService.rotateDevicesTrust(fakeNewUserKey, "my_password_hash");
|
await deviceTrustCryptoService.rotateDevicesTrust(fakeNewUserKey, "my_password_hash");
|
||||||
|
|
||||||
expect(devicesApiService.updateTrust).toBeCalledWith(
|
expect(devicesApiService.updateTrust).toHaveBeenCalledWith(
|
||||||
matches((updateTrustModel: UpdateDevicesTrustRequest) => {
|
matches((updateTrustModel: UpdateDevicesTrustRequest) => {
|
||||||
return (
|
return (
|
||||||
updateTrustModel.currentDevice.encryptedPublicKey ===
|
updateTrustModel.currentDevice.encryptedPublicKey ===
|
||||||
@@ -587,6 +587,7 @@ describe("deviceTrustCryptoService", () => {
|
|||||||
updateTrustModel.currentDevice.encryptedUserKey === "4.ZW5jcnlwdGVkdXNlcg=="
|
updateTrustModel.currentDevice.encryptedUserKey === "4.ZW5jcnlwdGVkdXNlcg=="
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
expect.stringMatching("test_device_identifier"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -71,13 +71,20 @@ export class DevicesApiServiceImplementation implements DevicesApiServiceAbstrac
|
|||||||
return new DeviceResponse(result);
|
return new DeviceResponse(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateTrust(updateDevicesTrustRequestModel: UpdateDevicesTrustRequest): Promise<void> {
|
async updateTrust(
|
||||||
|
updateDevicesTrustRequestModel: UpdateDevicesTrustRequest,
|
||||||
|
deviceIdentifier: string,
|
||||||
|
): Promise<void> {
|
||||||
await this.apiService.send(
|
await this.apiService.send(
|
||||||
"POST",
|
"POST",
|
||||||
"/devices/update-trust",
|
"/devices/update-trust",
|
||||||
updateDevicesTrustRequestModel,
|
updateDevicesTrustRequestModel,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
|
null,
|
||||||
|
(headers) => {
|
||||||
|
headers.set("X-Device-Identifier", deviceIdentifier);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user