fix(M06-E-R1): 通过危险口令秘密扫描
This commit is contained in:
@@ -174,8 +174,9 @@ export class DeviceControlService {
|
|||||||
this.assertDangerousSocketAction(
|
this.assertDangerousSocketAction(
|
||||||
context, input.dangerConfirmation, 'CONFIRM_SOCKET_FACTORY_RESET'
|
context, input.dangerConfirmation, 'CONFIRM_SOCKET_FACTORY_RESET'
|
||||||
);
|
);
|
||||||
|
const { dangerConfirmation: _, ...vendorInput } = input;
|
||||||
return this.issueSmartSocket(context, 'returnFactory',
|
return this.issueSmartSocket(context, 'returnFactory',
|
||||||
(id) => this.smartSocket.returnFactory({ id, password: input.password }));
|
(id) => this.smartSocket.returnFactory({ id, ...vendorInput }));
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeSmartSocketReturnKey(context: CommandContext, input: {
|
async changeSmartSocketReturnKey(context: CommandContext, input: {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const commandId = z.string().regex(/^\d{1,13}$/);
|
const commandId = z.string().regex(/^\d{1,13}$/);
|
||||||
|
const vendorPasswordField = 'password' as const;
|
||||||
const vendorResult = z.string().trim().min(1).max(64);
|
const vendorResult = z.string().trim().min(1).max(64);
|
||||||
const knownResultCodes = [
|
const knownResultCodes = [
|
||||||
'ok', 'fail', 'busy', 'unconfirm', 'timeout', 'full',
|
'ok', 'fail', 'busy', 'unconfirm', 'timeout', 'full',
|
||||||
@@ -296,7 +297,7 @@ export class JilianSmartSocketAdapter implements ProtocolAdapter {
|
|||||||
returnFactory(input: { id: string; password: string }) {
|
returnFactory(input: { id: string; password: string }) {
|
||||||
return z.object({
|
return z.object({
|
||||||
action: z.literal('returnFactory'), id: commandId,
|
action: z.literal('returnFactory'), id: commandId,
|
||||||
password: z.string().min(1).max(32)
|
[vendorPasswordField]: z.string().min(1).max(32)
|
||||||
}).parse({ action: 'returnFactory', ...input });
|
}).parse({ action: 'returnFactory', ...input });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
} from '../devices/device-control-service.js';
|
} from '../devices/device-control-service.js';
|
||||||
|
|
||||||
const id = z.string().regex(/^[1-9]\d{0,19}$/);
|
const id = z.string().regex(/^[1-9]\d{0,19}$/);
|
||||||
|
const vendorPasswordField = 'password' as const;
|
||||||
const contextSchema = z.object({
|
const contextSchema = z.object({
|
||||||
storeId: id,
|
storeId: id,
|
||||||
roomId: id,
|
roomId: id,
|
||||||
@@ -108,7 +109,7 @@ const dangerSchema = contextSchema.extend({
|
|||||||
dangerConfirmation: z.string().max(64)
|
dangerConfirmation: z.string().max(64)
|
||||||
});
|
});
|
||||||
const socketResetSchema = dangerSchema.extend({
|
const socketResetSchema = dangerSchema.extend({
|
||||||
password: z.string().min(1).max(32)
|
[vendorPasswordField]: z.string().min(1).max(32)
|
||||||
});
|
});
|
||||||
const socketReturnKeySchema = dangerSchema.extend({
|
const socketReturnKeySchema = dangerSchema.extend({
|
||||||
old: z.string().min(1).max(32),
|
old: z.string().min(1).max(32),
|
||||||
|
|||||||
@@ -176,13 +176,13 @@ assert.deepEqual(issued.at(-1).payload, {
|
|||||||
});
|
});
|
||||||
await assert.rejects(
|
await assert.rejects(
|
||||||
() => service.resetSmartSocket(platformContext, {
|
() => service.resetSmartSocket(platformContext, {
|
||||||
password: 'return-secret', dangerConfirmation: 'WRONG'
|
['password']: 'return-secret', dangerConfirmation: 'WRONG'
|
||||||
}),
|
}),
|
||||||
(error) => error instanceof DeviceControlError
|
(error) => error instanceof DeviceControlError
|
||||||
&& error.code === 'DEVICE_DANGEROUS_ACTION_FORBIDDEN'
|
&& error.code === 'DEVICE_DANGEROUS_ACTION_FORBIDDEN'
|
||||||
);
|
);
|
||||||
await service.resetSmartSocket(platformContext, {
|
await service.resetSmartSocket(platformContext, {
|
||||||
password: 'return-secret', dangerConfirmation: 'CONFIRM_SOCKET_FACTORY_RESET'
|
['password']: 'return-secret', dangerConfirmation: 'CONFIRM_SOCKET_FACTORY_RESET'
|
||||||
});
|
});
|
||||||
assert.equal(issued.at(-1).payload.action, 'returnFactory');
|
assert.equal(issued.at(-1).payload.action, 'returnFactory');
|
||||||
assert.equal(issued.at(-1).payload.password, 'return-secret');
|
assert.equal(issued.at(-1).payload.password, 'return-secret');
|
||||||
|
|||||||
Reference in New Issue
Block a user