Fix not allowed friendly_names being allowed. #5618

This commit is contained in:
Koen Kanters 2021-01-08 20:46:04 +01:00
parent b2cd519e0b
commit d7c74ca3ad
2 changed files with 17 additions and 0 deletions

View File

@ -190,6 +190,12 @@ function toSnakeCase(value) {
function validateFriendlyName(name) {
const errors = [];
for (const endpointName of endpointNames) {
if (name.toLowerCase().endsWith('/' + endpointName)) {
errors.push(`friendly_name is not allowed to end with: '/${endpointName}'`);
}
}
if (endpointNames.includes(name)) errors.push(`Following friendly_name are not allowed: '${endpointNames}'`);
if (name.match(/.*\/\d*$/)) errors.push(`Friendly name cannot end with a "/DIGIT" ('${name}')`);
if (name.includes('#') || name.includes('+')) {

View File

@ -474,6 +474,17 @@ describe('Bridge', () => {
);
});
it('Shouldnt allow rename device with to now allowed name', async () => {
MQTT.publish.mockClear();
MQTT.events.message('zigbee2mqtt/bridge/request/device/rename', stringify({from: 'bulb', to: 'living_room/blinds/center'}));
await flushPromises();
expect(MQTT.publish).toHaveBeenCalledWith(
'zigbee2mqtt/bridge/response/device/rename',
stringify({"data":{},"status":"error","error":"friendly_name is not allowed to end with: '/center'"}),
{retain: false, qos: 0}, expect.any(Function)
);
});
it('Should allow rename group', async () => {
MQTT.publish.mockClear();
MQTT.events.message('zigbee2mqtt/bridge/request/group/rename', stringify({from: 'group_1', to: 'group_new_name'}));