diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetManagementTest.java index d3c6f3ff4..b9e85f59f 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetManagementTest.java @@ -22,8 +22,8 @@ import java.util.List; import java.util.Map; import org.assertj.core.api.Assertions; -import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.DistributionSetManagement.Create; +import org.eclipse.hawkbit.repository.DistributionSetManagement.Update; import org.eclipse.hawkbit.repository.Identifiable; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; @@ -59,18 +59,16 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest { void verifyRead() { // permissions to read only type1 ds runAs(withAuthorities(READ_DISTRIBUTION_SET + "/type.id==" + dsType1.getId()), () -> { - Assertions. assertThat(distributionSetManagement.findAll(UNPAGED)).hasSize(1).containsExactlyInAnyOrder(ds1Type1); + Assertions. assertThat(distributionSetManagement.findAll(UNPAGED)).containsExactlyInAnyOrder(ds1Type1); assertThat(distributionSetManagement.count()).isEqualTo(1); - Assertions. assertThat(distributionSetManagement.findByRsql("name==*", UNPAGED)).hasSize(1).hasSize(1) - .containsExactly(ds1Type1); + Assertions. assertThat(distributionSetManagement.findByRsql("name==*", UNPAGED)).containsExactly(ds1Type1); assertThat(distributionSetManagement.countByRsql("name==*")).isEqualTo(1); - Assertions. assertThat(distributionSetManagement.findByTag(dsTag1.getId(), UNPAGED)).hasSize(1) - .containsExactly(ds1Type1); + Assertions. assertThat(distributionSetManagement.findByTag(dsTag1.getId(), UNPAGED)).containsExactly(ds1Type1); assertThat(distributionSetManagement.findByTag(dsTag2.getId(), UNPAGED)).isEmpty(); - Assertions. assertThat(distributionSetManagement.findByRsqlAndTag("name==*", dsTag1.getId(), UNPAGED)).hasSize(1) + Assertions. assertThat(distributionSetManagement.findByRsqlAndTag("name==*", dsTag1.getId(), UNPAGED)) .containsExactly(ds1Type1); assertThat(distributionSetManagement.findByRsqlAndTag("name==*", dsTag2.getId(), UNPAGED)).isEmpty(); @@ -84,7 +82,7 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest { assertThatThrownBy(() -> distributionSetManagement.getWithDetails(ds2Type2Id)).isInstanceOf(EntityNotFoundException.class); assertThat(distributionSetManagement.find(ds2Type2Id)).isEmpty(); - Assertions. assertThat(distributionSetManagement.get(List.of(ds1Type1Id))).hasSize(1).contains(ds1Type1); + Assertions. assertThat(distributionSetManagement.get(List.of(ds1Type1Id))).contains(ds1Type1); final List noPermissionsTestDataDsIdList = List.of(ds2Type2Id); assertThatThrownBy(() -> distributionSetManagement.get(noPermissionsTestDataDsIdList)).isInstanceOf(EntityNotFoundException.class); final List containingNoPermissionTestDataDsIsList = List.of(ds1Type1Id, ds2Type2Id); @@ -144,10 +142,8 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest { assertThatThrownBy(() -> distributionSetManagement.deleteMetadata(ds2Type2Id, ds2MdKey)) .isInstanceOf(InsufficientPermissionException.class); - final DistributionSetManagement.Update distributionSet1Update = DistributionSetManagement.Update.builder() - .id(ds1Type1.getId()).description(randomString(16)).build(); - final DistributionSetManagement.Update distributionSet2Update = DistributionSetManagement.Update.builder() - .id(ds2Type2Id).description(randomString(16)).build(); + final Update distributionSet1Update = Update.builder().id(ds1Type1.getId()).description(randomString(16)).build(); + final Update distributionSet2Update = Update.builder().id(ds2Type2Id).description(randomString(16)).build(); DistributionSet ds1Type1 = distributionSetManagement.update(distributionSet1Update); assertThat(ds1Type1).extracting(NamedEntity::getDescription).isEqualTo(distributionSet1Update.getDescription()); assertThatThrownBy(() -> distributionSetManagement.update(distributionSet2Update)) @@ -176,27 +172,4 @@ class DistributionSetManagementTest extends AbstractAccessControllerTest { assertThatThrownBy(() -> distributionSetManagement.invalidate(ds2Type2)).isInstanceOf(InsufficientPermissionException.class); }); } -// -// private TestData createCompleteDistributionSetWithNewType() { -// // create type -// final DistributionSetType distributionSetType = testdataFactory.findOrCreateDistributionSetType(randomString(16), randomString(16), -// List.of(osType), List.of(appType)); -// -// final DistributionSetTag distributionSetTag = distributionSetTagManagement.create( -// DistributionSetTagManagement.Create.builder().name(randomString(16)).build()); -// -// final SoftwareModule moduleOs = testdataFactory.createSoftwareModuleOs(); -// -// final Long distributionSetId = distributionSetManagement.create( -// Create.builder().type(distributionSetType).name(randomString(16)).version("1.0") -// .modules(Set.of(moduleOs)).build()).getId(); -// -// final DistributionSetAssignmentResult assignmentResult = assignDistributionSet(distributionSetId, createTarget().getControllerId()); -// assertThat(assignmentResult.getAssignedEntity()).hasSize(1); -// -// return new TestData(distributionSetType, -// distributionSetManagement.assignTag(Collections.singletonList(distributionSetId), distributionSetTag.getId()).get(0), -// distributionSetTag, assignmentResult.getAssignedEntity().get(0)); -// } - } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetTypeManagementTest.java index 59a236b85..5004c1464 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetTypeManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/DistributionSetTypeManagementTest.java @@ -48,11 +48,11 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerTest { runAs(withAuthorities(READ_PREFIX + DISTRIBUTION_SET_TYPE + "/id==" + dsType1.getId()), () -> { // perform distributionSetTypeManagement#findAll and verify Assertions. assertThat(distributionSetTypeManagement.findAll(UNPAGED)) - .hasSize(1).containsExactly(dsType1); + .containsExactly(dsType1); assertThat(distributionSetTypeManagement.count()).isEqualTo(1); Assertions. assertThat(distributionSetTypeManagement.findByRsql("name==*", UNPAGED)) - .hasSize(1).containsExactly(dsType1); + .containsExactly(dsType1); assertThat(distributionSetTypeManagement.countByRsql("name==*")).isEqualTo(1); assertThat(distributionSetTypeManagement.exists(dsType1.getId())).isTrue(); @@ -62,7 +62,7 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerTest { assertThat(distributionSetTypeManagement.find(dsType2.getId())).isEmpty(); Assertions. assertThat(distributionSetTypeManagement.get(List.of(dsType1.getId()))) - .hasSize(1).contains(dsType1); + .containsExactly(dsType1); final List noPermissionIdList = List.of(dsType2.getId()); assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> distributionSetTypeManagement.get(noPermissionIdList)); final List allPermissionsIdList = List.of(dsType1.getId(), dsType2.getId()); @@ -125,8 +125,8 @@ class DistributionSetTypeManagementTest extends AbstractAccessControllerTest { // soft delete since dsType1 is assigned to ds1Type1 assertThat(distributionSetTypeManagement.find(dsType1.getId())).hasValueSatisfying(DistributionSetType::isDeleted); - final Long ds2Type2Id = dsType2.getId(); - assertThatThrownBy(() -> distributionSetTypeManagement.delete(ds2Type2Id)).isInstanceOf(InsufficientPermissionException.class); + final Long dsType2Id = dsType2.getId(); + assertThatThrownBy(() -> distributionSetTypeManagement.delete(dsType2Id)).isInstanceOf(InsufficientPermissionException.class); }); } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java index 3df0734e5..7b940ade0 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutExecutionTest.java @@ -40,7 +40,7 @@ class RolloutExecutionTest extends AbstractAccessControllerTest { })); } - void verify(final Runnable run) { + private void verify(final Runnable run) { final Target[] expectedTargets = new Target[] { target1Type1 }; runAs(withAuthorities( READ_TARGET, UPDATE_TARGET + "/type.id==" + targetType1.getId(), diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java index 62b95bf08..ac50b0a84 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/RolloutManagementTest.java @@ -32,19 +32,17 @@ class RolloutManagementTest extends AbstractAccessControllerTest { rolloutManagement.start(rollout.getId()); rolloutHandler.handleAll(); - runAs(withAuthorities(READ_TARGET + "/type.id==" + targetType1.getId(), READ_ROLLOUT), - () -> { - assertThat(targetManagement.findAll(UNPAGED).stream().map(Identifiable::getId).toList()) - .as("Only readable targets should be returned") - .containsExactly(target1Type1.getId()); - assertThat(rolloutManagement.getWithDetailedStatus(rollout.getId())).satisfies(rolloutWithDetails -> { - assertThat(rolloutWithDetails.getTotalTargets()).as("All targets shall be returned").isEqualTo(3); - assertThat(rolloutWithDetails.getRolloutGroupsCreated()).isEqualTo(rollout.getRolloutGroupsCreated()); - assertThat(rolloutWithDetails.getTotalTargetCountStatus().getFinishedPercent()).isZero(); - assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(RUNNING)).isEqualTo(1); - assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(SCHEDULED)).isEqualTo(2); - assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(NOTSTARTED)).isZero(); - }); - }); + runAs(withAuthorities(READ_TARGET + "/type.id==" + targetType1.getId(), READ_ROLLOUT), () -> { + assertThat(targetManagement.findAll(UNPAGED).stream().map(Identifiable::getId).toList()) + .as("Only readable targets should be returned").containsExactly(target1Type1.getId()); + assertThat(rolloutManagement.getWithDetailedStatus(rollout.getId())).satisfies(rolloutWithDetails -> { + assertThat(rolloutWithDetails.getTotalTargets()).as("All targets shall be returned").isEqualTo(3); + assertThat(rolloutWithDetails.getRolloutGroupsCreated()).isEqualTo(rollout.getRolloutGroupsCreated()); + assertThat(rolloutWithDetails.getTotalTargetCountStatus().getFinishedPercent()).isZero(); + assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(RUNNING)).isEqualTo(1); + assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(SCHEDULED)).isEqualTo(2); + assertThat(rolloutWithDetails.getTotalTargetCountStatus().getTotalTargetCountByStatus(NOTSTARTED)).isZero(); + }); + }); } } \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/SoftwareModuleManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/SoftwareModuleManagementTest.java new file mode 100644 index 000000000..c2e8cd5e9 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/SoftwareModuleManagementTest.java @@ -0,0 +1,80 @@ +/** + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.hawkbit.repository.jpa.acm; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.eclipse.hawkbit.im.authentication.SpPermission.READ_PREFIX; +import static org.eclipse.hawkbit.im.authentication.SpPermission.SOFTWARE_MODULE; +import static org.eclipse.hawkbit.im.authentication.SpPermission.UPDATE_PREFIX; +import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.runAs; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Map; + +import org.assertj.core.api.Assertions; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; +import org.eclipse.hawkbit.repository.model.SoftwareModule; +import org.eclipse.hawkbit.repository.model.SoftwareModule.MetadataValueCreate; +import org.junit.jupiter.api.Test; + +class SoftwareModuleManagementTest extends AbstractAccessControllerTest { + + @Test + void verifyRead() { + runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE + "/type.id==" + smType1.getId()), () -> { + Assertions. assertThat(softwareModuleManagement.findAll(UNPAGED)).containsExactly(sm1Type1); + assertThat(softwareModuleManagement.count()).isEqualTo(1); + + Assertions. assertThat(softwareModuleManagement.findByRsql("name==*", UNPAGED)).containsExactly(sm1Type1); + Assertions.assertThat(softwareModuleManagement.countByRsql("name==*")).isEqualTo(1); + + final Long sm2Type2Id = sm2Type2.getId(); + Assertions. assertThat(softwareModuleManagement.findByAssignedTo(sm2Type2Id, UNPAGED).toList()) + .containsExactly(sm1Type1); // no sm2Type2 + + assertThat(softwareModuleManagement.getMetadata(sm1Type1.getId())).isEmpty(); + assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> softwareModuleManagement.getMetadata(sm2Type2Id)); + }); + } + + @Test + void verifyUpdate() { + runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE, UPDATE_PREFIX + SOFTWARE_MODULE + "/type.id==" + smType1.getId()), () -> { + final String metadataKey = "key.dot"; + final MetadataValueCreate metaDataCreate = new MetadataValueCreate(randomString(16), true); + + final Long sm1Type1Id = sm1Type1.getId(); + softwareModuleManagement.createMetadata(sm1Type1Id, metadataKey, metaDataCreate); + assertThat(softwareModuleManagement.getMetadata(sm1Type1Id, metadataKey)) + .satisfies(createdMetadata -> assertTrue(createdMetadata.isTargetVisible())); + assertThat(softwareModuleManagement.getMetadata(sm1Type1Id)).hasSize(1); + final Long sm2Type2Id = sm2Type2.getId(); + assertThatThrownBy(() -> softwareModuleManagement.createMetadata(sm2Type2Id, metadataKey, metaDataCreate)) + .isInstanceOf(InsufficientPermissionException.class); + final Map metaDataCreateMap = Map.of(metadataKey, metaDataCreate); + assertThatThrownBy(() -> softwareModuleManagement.createMetadata(sm2Type2Id, metaDataCreateMap)) + .isInstanceOf(InsufficientPermissionException.class); + + final MetadataValueCreate metadataUpdate = new MetadataValueCreate(randomString(16)); + softwareModuleManagement.createMetadata(sm1Type1Id, metadataKey, metadataUpdate); + assertThat(softwareModuleManagement.getMetadata(sm1Type1Id, metadataKey)) + .satisfies(updatedMetadata -> assertFalse(updatedMetadata.isTargetVisible())); + softwareModuleManagement.deleteMetadata(sm1Type1Id, metadataKey); + assertThatThrownBy(() -> softwareModuleManagement.createMetadata(sm2Type2Id, metadataKey, metadataUpdate)) + .isInstanceOf(InsufficientPermissionException.class); + assertThatThrownBy(() -> softwareModuleManagement.deleteMetadata(sm2Type2Id, metadataKey)) + .isInstanceOf(EntityNotFoundException.class); + }); + } +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/SoftwareModuleTypeManagementTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/SoftwareModuleTypeManagementTest.java new file mode 100644 index 000000000..bd18ecd08 --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/SoftwareModuleTypeManagementTest.java @@ -0,0 +1,102 @@ +/** + * Copyright (c) 2025 Contributors to the Eclipse Foundation + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.eclipse.hawkbit.repository.jpa.acm; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.eclipse.hawkbit.im.authentication.SpPermission.CREATE_PREFIX; +import static org.eclipse.hawkbit.im.authentication.SpPermission.DELETE_PREFIX; +import static org.eclipse.hawkbit.im.authentication.SpPermission.READ_PREFIX; +import static org.eclipse.hawkbit.im.authentication.SpPermission.SOFTWARE_MODULE_TYPE; +import static org.eclipse.hawkbit.im.authentication.SpPermission.UPDATE_PREFIX; +import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.runAs; + +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement.Update; +import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; +import org.eclipse.hawkbit.repository.exception.InsufficientPermissionException; +import org.eclipse.hawkbit.repository.model.NamedEntity; +import org.eclipse.hawkbit.repository.model.SoftwareModuleType; +import org.junit.jupiter.api.Test; + +class SoftwareModuleTypeManagementTest extends AbstractAccessControllerTest { + + @Test + void verifyCreate() { + // permissions to read only type1 sm types and create new type with name 'permitted' + runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE, CREATE_PREFIX + SOFTWARE_MODULE_TYPE + "/key==permitted"), () -> { + assertThat(testdataFactory.findOrCreateSoftwareModuleType("permitted")).isNotNull(); + assertThatThrownBy(() -> testdataFactory.findOrCreateSoftwareModuleType("not_permitted_2")) + .isInstanceOf(InsufficientPermissionException.class); + }); + } + + @Test + void verifyRead() { + // permissions to read only type1 sm types + runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE + "/id==" + smType1.getId()), () -> { + Assertions. assertThat(softwareModuleTypeManagement.findAll(UNPAGED)).containsExactly(smType1); + assertThat(softwareModuleTypeManagement.count()).isEqualTo(1); + + Assertions. assertThat(softwareModuleTypeManagement.findByRsql("name==*", UNPAGED)).containsExactly(smType1); + assertThat(softwareModuleTypeManagement.countByRsql("name==*")).isEqualTo(1); + + assertThat(softwareModuleTypeManagement.exists(smType1.getId())).isTrue(); + assertThat(softwareModuleTypeManagement.exists(smType2.getId())).isFalse(); + + assertThat(softwareModuleTypeManagement.find(smType1.getId()).map(SoftwareModuleType.class::cast)).hasValue(smType1); + assertThat(softwareModuleTypeManagement.find(smType2.getId())).isEmpty(); + + Assertions. assertThat(softwareModuleTypeManagement.get(List.of(smType1.getId()))).containsExactly(smType1); + + final List noPermissionIdList = List.of(smType2.getId()); + assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> softwareModuleTypeManagement.get(noPermissionIdList)); + final List allPermissionsIdList = List.of(smType1.getId(), smType2.getId()); + assertThatExceptionOfType(EntityNotFoundException.class).isThrownBy(() -> softwareModuleTypeManagement.get(allPermissionsIdList)); + + assertThat(softwareModuleTypeManagement.findByKey(smType1.getKey()).map(SoftwareModuleType.class::cast)).hasValue(smType1); + final String noPermissionsTypeKey = smType2.getKey(); + assertThatThrownBy(() -> softwareModuleTypeManagement.findByKey(noPermissionsTypeKey)) + .isInstanceOf(InsufficientPermissionException.class); + }); + } + + @Test + void verifyUpdate() { + // permissions to read only type1 sm types + runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE, UPDATE_PREFIX + SOFTWARE_MODULE_TYPE + "/id==" + smType1.getId()), () -> { + final String newDescription = randomString(16); + assertThat(softwareModuleTypeManagement.update(Update.builder().id(smType1.getId()).description(newDescription).build())) + .extracting(NamedEntity::getDescription) + .isEqualTo(newDescription); + + final Update descriptionUpdate = Update.builder().id(smType2.getId()).description(newDescription).build(); + assertThatThrownBy(() -> softwareModuleTypeManagement.update(descriptionUpdate)) + .isInstanceOf(InsufficientPermissionException.class); + }); + } + + @Test + void verifyDelete() { + // permissions to read all and update only type1 sm types + runAs(withAuthorities(READ_PREFIX + SOFTWARE_MODULE_TYPE, DELETE_PREFIX + SOFTWARE_MODULE_TYPE + "/id==" + smType1.getId()), () -> { + assertThat(softwareModuleTypeManagement.find(smType1.getId())).isPresent(); + softwareModuleTypeManagement.delete(smType1.getId()); + // soft delete since smType1 is assigned to sm1Type1 + assertThat(softwareModuleTypeManagement.find(smType1.getId())).hasValueSatisfying(SoftwareModuleType::isDeleted); + + final Long smType2Id = smType2.getId(); + assertThatThrownBy(() -> distributionSetTypeManagement.delete(smType2Id)).isInstanceOf(InsufficientPermissionException.class); + }); + } +} \ No newline at end of file diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetAccessControllerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetAccessControllerTest.java index 808183388..45be21161 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetAccessControllerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetAccessControllerTest.java @@ -69,11 +69,11 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest { runAs(withUser("user", READ_TARGET + "/controllerId==" + permittedTarget.getControllerId()), () -> { // verify targetManagement#findAll assertThat(targetManagement.findAll(Pageable.unpaged()).get().map(Identifiable::getId).toList()) - .containsOnly(permittedTarget.getId()); + .containsExactly(permittedTarget.getId()); // verify targetManagement#findByRsql assertThat(targetManagement.findByRsql("id==*", Pageable.unpaged()).get().map(Identifiable::getId).toList()) - .containsOnly(permittedTarget.getId()); + .containsExactly(permittedTarget.getId()); // verify targetManagement#getByControllerID assertThat(targetManagement.getByControllerId(permittedTarget.getControllerId())).isNotNull(); @@ -88,7 +88,7 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest { // verify targetManagement#getByControllerId assertThat(targetManagement .findByControllerId(List.of(permittedTarget.getControllerId(), hiddenTargetControllerId)) - .stream().map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId()); + .stream().map(Identifiable::getId).toList()).containsExactly(permittedTarget.getId()); // verify targetManagement#get assertThat(targetManagement.find(permittedTarget.getId())).isPresent(); @@ -131,11 +131,11 @@ class TargetAccessControllerTest extends AbstractJpaIntegrationTest { // verify targetManagement#findByTag assertThat( targetManagement.findByTag(myTagId, Pageable.unpaged()).get().map(Identifiable::getId).toList()) - .containsOnly(permittedTarget.getId(), readOnlyTarget.getId()); + .containsExactlyInAnyOrder(permittedTarget.getId(), readOnlyTarget.getId()); // verify targetManagement#findByRsqlAndTag assertThat(targetManagement.findByRsqlAndTag("id==*", myTagId, Pageable.unpaged()).get() - .map(Identifiable::getId).toList()).containsOnly(permittedTarget.getId(), readOnlyTarget.getId()); + .map(Identifiable::getId).toList()).containsExactlyInAnyOrder(permittedTarget.getId(), readOnlyTarget.getId()); // verify targetManagement#assignTag on permitted target assertThat(targetManagement.assignTag(Collections.singletonList(permittedTarget.getControllerId()), myTagId)).hasSize(1); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetTypeAccessControllerTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetTypeAccessControllerTest.java index e5282f43b..073e72dc3 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetTypeAccessControllerTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/acm/TargetTypeAccessControllerTest.java @@ -50,11 +50,11 @@ class TargetTypeAccessControllerTest extends AbstractJpaIntegrationTest { runAs(withUser("user", READ_TARGET_TYPE + "/id==" + permittedTargetType.getId()), () -> { // verify targetTypeManagement#findAll assertThat(targetTypeManagement.findAll(Pageable.unpaged()).get().map(Identifiable::getId).toList()) - .containsOnly(permittedTargetType.getId()); + .containsExactly(permittedTargetType.getId()); // verify targetTypeManagement#findByRsql assertThat(targetTypeManagement.findByRsql("name==*", Pageable.unpaged()).get().map(Identifiable::getId).toList()) - .containsOnly(permittedTargetType.getId()); + .containsExactly(permittedTargetType.getId()); // verify targetTypeManagement#count assertThat(targetTypeManagement.count()).isEqualTo(1);