mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
[PM-19838] Untrust devices that cannot be rotated (#14165)
* Untrust devices that cannot be rotated * Add tests and only send request on more than 0 failed devices * Address feedback
This commit is contained in:
@@ -38,4 +38,10 @@ export abstract class DevicesApiServiceAbstraction {
|
||||
* @param deviceId - The device ID
|
||||
*/
|
||||
deactivateDevice: (deviceId: string) => Promise<void>;
|
||||
|
||||
/**
|
||||
* Removes trust from a list of devices
|
||||
* @param deviceIds - The device IDs to be untrusted
|
||||
*/
|
||||
untrustDevices: (deviceIds: string[]) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export class UntrustDevicesRequestModel {
|
||||
constructor(public devices: string[]) {}
|
||||
}
|
||||
@@ -89,6 +89,24 @@ describe("DevicesApiServiceImplementation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("untrustDevices", () => {
|
||||
it("calls api with correct parameters", async () => {
|
||||
const deviceIds = ["device1", "device2"];
|
||||
apiService.send.mockResolvedValue(true);
|
||||
|
||||
await devicesApiService.untrustDevices(deviceIds);
|
||||
expect(apiService.send).toHaveBeenCalledWith(
|
||||
"POST",
|
||||
"/devices/untrust",
|
||||
{
|
||||
devices: deviceIds,
|
||||
},
|
||||
true,
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("error handling", () => {
|
||||
it("propagates api errors", async () => {
|
||||
const error = new Error("API Error");
|
||||
|
||||
@@ -5,6 +5,7 @@ import { ListResponse } from "../../models/response/list.response";
|
||||
import { Utils } from "../../platform/misc/utils";
|
||||
import { DeviceResponse } from "../abstractions/devices/responses/device.response";
|
||||
import { DevicesApiServiceAbstraction } from "../abstractions/devices-api.service.abstraction";
|
||||
import { UntrustDevicesRequestModel } from "../models/request/untrust-devices.request";
|
||||
import { UpdateDevicesTrustRequest } from "../models/request/update-devices-trust.request";
|
||||
import { ProtectedDeviceResponse } from "../models/response/protected-device.response";
|
||||
|
||||
@@ -117,4 +118,14 @@ export class DevicesApiServiceImplementation implements DevicesApiServiceAbstrac
|
||||
async deactivateDevice(deviceId: string): Promise<void> {
|
||||
await this.apiService.send("POST", `/devices/${deviceId}/deactivate`, null, true, false);
|
||||
}
|
||||
|
||||
async untrustDevices(deviceIds: string[]): Promise<void> {
|
||||
await this.apiService.send(
|
||||
"POST",
|
||||
"/devices/untrust",
|
||||
new UntrustDevicesRequestModel(deviceIds),
|
||||
true,
|
||||
false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user