



























@@ -181,7 +181,10 @@ describe("deviceHandlers", () => {
181181});
182182183183it("disconnects active clients after revoking a device token", async () => {
184-revokeDeviceTokenMock.mockResolvedValue({ role: "operator", revokedAtMs: 456 });
184+revokeDeviceTokenMock.mockResolvedValue({
185+ok: true,
186+entry: { role: "operator", revokedAtMs: 456 },
187+});
185188const opts = createOptions("device.token.revoke", {
186189deviceId: " device-1 ",
187190role: " operator ",
@@ -193,6 +196,7 @@ describe("deviceHandlers", () => {
193196expect(revokeDeviceTokenMock).toHaveBeenCalledWith({
194197deviceId: " device-1 ",
195198role: " operator ",
199+callerScopes: [],
196200});
197201expect(opts.context.disconnectClientsForDevice).toHaveBeenCalledWith("device-1", {
198202role: "operator",
@@ -205,7 +209,10 @@ describe("deviceHandlers", () => {
205209});
206210207211it("allows admin-scoped callers to revoke another device's token", async () => {
208-revokeDeviceTokenMock.mockResolvedValue({ role: "operator", revokedAtMs: 456 });
212+revokeDeviceTokenMock.mockResolvedValue({
213+ok: true,
214+entry: { role: "operator", revokedAtMs: 456 },
215+});
209216const opts = createOptions(
210217"device.token.revoke",
211218{ deviceId: "device-2", role: "operator" },
@@ -217,6 +224,7 @@ describe("deviceHandlers", () => {
217224expect(revokeDeviceTokenMock).toHaveBeenCalledWith({
218225deviceId: "device-2",
219226role: "operator",
227+callerScopes: ["operator.admin"],
220228});
221229expect(opts.respond).toHaveBeenCalledWith(
222230true,
@@ -226,7 +234,10 @@ describe("deviceHandlers", () => {
226234});
227235228236it("treats normalized device ids as self-owned for token revocation", async () => {
229-revokeDeviceTokenMock.mockResolvedValue({ role: "operator", revokedAtMs: 456 });
237+revokeDeviceTokenMock.mockResolvedValue({
238+ok: true,
239+entry: { role: "operator", revokedAtMs: 456 },
240+});
230241const opts = createOptions(
231242"device.token.revoke",
232243{ deviceId: " device-1 ", role: "operator" },
@@ -238,6 +249,7 @@ describe("deviceHandlers", () => {
238249expect(revokeDeviceTokenMock).toHaveBeenCalledWith({
239250deviceId: " device-1 ",
240251role: "operator",
252+callerScopes: ["operator.pairing"],
241253});
242254expect(opts.respond).toHaveBeenCalledWith(
243255true,
@@ -272,6 +284,7 @@ describe("deviceHandlers", () => {
272284deviceId: " device-1 ",
273285role: " operator ",
274286scopes: ["operator.pairing"],
287+callerScopes: ["operator.pairing"],
275288});
276289expect(opts.context.disconnectClientsForDevice).toHaveBeenCalledWith("device-1", {
277290role: "operator",
@@ -308,6 +321,7 @@ describe("deviceHandlers", () => {
308321deviceId: " device-1 ",
309322role: "operator",
310323scopes: ["operator.pairing"],
324+callerScopes: ["operator.pairing"],
311325});
312326expect(opts.respond).toHaveBeenCalledWith(
313327true,
@@ -324,6 +338,7 @@ describe("deviceHandlers", () => {
324338325339it("rejects rotating a token for a role that was never approved", async () => {
326340mockPairedOperatorDevice();
341+rotateDeviceTokenMock.mockResolvedValue({ ok: false, reason: "unknown-device-or-role" });
327342const opts = createOptions(
328343"device.token.rotate",
329344{
@@ -341,7 +356,12 @@ describe("deviceHandlers", () => {
341356342357await deviceHandlers["device.token.rotate"](opts);
343358344-expect(rotateDeviceTokenMock).not.toHaveBeenCalled();
359+expect(rotateDeviceTokenMock).toHaveBeenCalledWith({
360+deviceId: "device-1",
361+role: "node",
362+scopes: undefined,
363+callerScopes: ["operator.pairing"],
364+});
345365expect(opts.context.disconnectClientsForDevice).not.toHaveBeenCalled();
346366expect(opts.respond).toHaveBeenCalledWith(
347367false,
@@ -351,7 +371,7 @@ describe("deviceHandlers", () => {
351371});
352372353373it("does not disconnect clients when token revocation fails", async () => {
354-revokeDeviceTokenMock.mockResolvedValue(null);
374+revokeDeviceTokenMock.mockResolvedValue({ ok: false, reason: "unknown-device-or-role" });
355375const opts = createOptions("device.token.revoke", {
356376deviceId: "device-1",
357377role: "operator",
@@ -363,7 +383,7 @@ describe("deviceHandlers", () => {
363383expect(opts.respond).toHaveBeenCalledWith(
364384false,
365385undefined,
366-expect.objectContaining({ message: "unknown deviceId/role" }),
386+expect.objectContaining({ message: "device token revocation denied" }),
367387);
368388});
369389此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。