From bd199e6c84866086e0349a78ac3136dd82bd6ba3 Mon Sep 17 00:00:00 2001 From: Viacheslav Klimov Date: Thu, 12 Nov 2026 05:23:24 +0200 Subject: [PATCH] Resolve the IoT Hub dashboard group within the tenant --- .../service/iot_hub/DefaultIotHubService.java | 2 +- .../iot_hub/DefaultIotHubServiceTest.java | 39 ++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java b/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java index c74c8be477..b7c1a4b44d 100644 --- a/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java +++ b/application/src/main/java/org/thingsboard/server/service/iot_hub/DefaultIotHubService.java @@ -297,7 +297,7 @@ public class DefaultIotHubService implements IotHubService { } private EntityGroupInfo checkEntityGroup(SecurityUser user, EntityGroupId entityGroupId) throws ThingsboardException { - EntityGroupInfo entityGroup = entityGroupService.findEntityGroupInfoById(user.getTenantId(), entityGroupId); + EntityGroupInfo entityGroup = entityGroupService.findEntityGroupInfoByTenantIdAndId(user.getTenantId(), entityGroupId); if (entityGroup == null) { throw new IllegalArgumentException("Entity group with id [" + entityGroupId + "] is not found"); } diff --git a/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java b/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java index cb9221db18..687b0ad91d 100644 --- a/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java +++ b/application/src/test/java/org/thingsboard/server/service/iot_hub/DefaultIotHubServiceTest.java @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 package org.thingsboard.server.service.iot_hub; import com.fasterxml.jackson.databind.JsonNode; @@ -13,13 +14,19 @@ import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import org.thingsboard.common.util.JacksonUtil; +import org.thingsboard.server.common.data.EntityType; +import org.thingsboard.server.common.data.group.EntityGroupInfo; +import org.thingsboard.server.common.data.id.EntityGroupId; import org.thingsboard.server.common.data.id.IotHubInstalledItemId; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.iot_hub.DashboardInstalledItemDescriptor; import org.thingsboard.server.common.data.iot_hub.IotHubInstalledItem; +import org.thingsboard.server.dao.group.EntityGroupService; import org.thingsboard.server.dao.iot_hub.IotHubInstalledItemService; import org.thingsboard.server.service.security.model.SecurityUser; +import org.thingsboard.server.service.security.permission.AccessControlService; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.UUID; @@ -33,6 +40,7 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -48,6 +56,10 @@ class DefaultIotHubServiceTest { private IotHubRestClient iotHubRestClient; @Mock private IotHubInstalledItemService iotHubInstalledItemService; + @Mock + private EntityGroupService entityGroupService; + @Mock + private AccessControlService accessControlService; @Spy @InjectMocks @@ -411,4 +423,29 @@ class DefaultIotHubServiceTest { assertThat(result.isRolledBack()).isFalse(); assertThat(result.getErrorMessage()).contains("install failed"); } + + @Test + void installItemVersion_dashboardWithGroupOfAnotherTenant_reportsGroupNotFound() throws Exception { + mockTenant(); + String versionId = UUID.randomUUID().toString(); + when(iotHubRestClient.getVersionInfo(versionId)) + .thenReturn(version(versionId, UUID.randomUUID().toString(), "DASHBOARD", "Dashboard", "1.0")); + when(iotHubRestClient.getVersionFileData(versionId)).thenReturn("{\"title\":\"Dashboard\"}".getBytes(StandardCharsets.UTF_8)); + + TenantId otherTenantId = TenantId.fromUUID(UUID.randomUUID()); + EntityGroupInfo otherTenantGroup = new EntityGroupInfo(); + otherTenantGroup.setId(new EntityGroupId(UUID.randomUUID())); + otherTenantGroup.setTenantId(otherTenantId); + otherTenantGroup.setOwnerId(otherTenantId); + otherTenantGroup.setType(EntityType.DASHBOARD); + otherTenantGroup.setName("Dashboards"); + lenient().when(entityGroupService.findEntityGroupInfoById(tenantId, otherTenantGroup.getId())).thenReturn(otherTenantGroup); + JsonNode data = JacksonUtil.newObjectNode().put("entityGroupId", otherTenantGroup.getId().getId().toString()); + + InstallItemVersionResult result = service.installItemVersion(user, versionId, data, null); + + assertThat(result.isSuccess()).isFalse(); + assertThat(result.getErrorMessage()).isEqualTo("Entity group with id [" + otherTenantGroup.getId() + "] is not found"); + verify(accessControlService, never()).checkEntityGroupInfoPermission(any(), any(), any()); + } }