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