Browse Source

IoT Hub device packages: an update step may not share the key of a form, whose values are saved under it

pull/16647/head
dshvaika 3 weeks ago
parent
commit
8a71a82c36
  1. 3
      application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateService.java
  2. 14
      application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateServiceTest.java
  3. 2
      ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts

3
application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateService.java

@ -209,7 +209,8 @@ public class DefaultDevicePackageUpdateService extends AbstractTbEntityService i
throw new IllegalArgumentException("The update has no steps");
}
Set<UUID> ownedIds = ownedIds(devicePackage.descriptor());
Set<String> stateKeys = new HashSet<>();
// A form's values are saved under its key too, so an entity step may not share it
Set<String> stateKeys = request.getInstallState() != null ? new HashSet<>(request.getInstallState().keySet()) : new HashSet<>();
for (DeviceUpdateRequest.Step step : request.getSteps()) {
if (step.getName() == null || step.getAction() == null || !isKnownType(step.getType())) {
throw new IllegalArgumentException("Invalid update step: " + step.getName());

14
application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultDevicePackageUpdateServiceTest.java

@ -497,6 +497,20 @@ class DefaultDevicePackageUpdateServiceTest {
verify(transactionTemplate, never()).execute(any());
}
@Test
void stepWithTheKeyOfAForm_isRejected() {
DeviceUpdateRequest.Step step = keep("Dashboard", "DASHBOARD", dashboardId);
step.setId("Settings");
DeviceUpdateRequest request = request(step);
request.setInstallState(Map.of("Settings", JacksonUtil.newObjectNode().set("formValues", JacksonUtil.newObjectNode().put("interval", 10))));
DeviceUpdateResult result = service.apply(user, installedItem.getId(), request);
assertThat(result.isSuccess()).isFalse();
assertThat(result.getErrorMessage()).isEqualTo("Duplicate update step: Settings");
verify(transactionTemplate, never()).execute(any());
}
@Test
void stepsOfOneNameAndAnotherType_eachKeepTheirOwnState() {
// Installed when the state was keyed by name: the integration's state replaced the converter's

2
ui-ngx/src/app/modules/home/components/iot-hub/device-install-dialog/device-install-dialog.component.ts

@ -2609,7 +2609,7 @@ export class TbDeviceInstallDialogComponent extends DialogComponent<TbDeviceInst
/**
* The key of the step's install state: its id, or else its type and name, so that two steps of an install method
* never share it. A form without an id keeps its name, which no entity step's type-and-name key equals; a step id
* equal to a form's name is caught by the duplicate check.
* equal to a form's name is caught by the duplicate check on install, and by the server on update.
* The server keys the steps of an update the same way.
*/
private stateKeyOf(step: DeviceInstallStep): string {

Loading…
Cancel
Save