SystemManagement getTenantMetadata - fetch details, added method getTenantMetadataWithoutDetails (#2194)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-10 15:37:57 +02:00
committed by GitHub
parent 0e4efe0987
commit b294798ae5
19 changed files with 117 additions and 131 deletions

View File

@@ -212,7 +212,8 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
final DistributionSet set = distributionSetManagement
.create(entityFactory.distributionSet().create().name("newtypesoft").version("1"));
assertThat(set.getType()).as("Type should be equal to default type of tenant")
assertThat(set.getType())
.as("Type should be equal to default type of tenant")
.isEqualTo(systemManagement.getTenantMetadata().getDefaultDsType());
}
@@ -705,13 +706,12 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Test implicit locks for a DS and skip tags.")
void isImplicitLockApplicableForDistributionSet() {
final JpaDistributionSetManagement distributionSetManagement =
(JpaDistributionSetManagement) this.distributionSetManagement;
final JpaDistributionSetManagement distributionSetManagement = (JpaDistributionSetManagement) this.distributionSetManagement;
final DistributionSet distributionSet = testdataFactory.createDistributionSet("ds-non-skip");
// assert that implicit lock is applicable for non skip tags
assertThat(distributionSetManagement.isImplicitLockApplicable(distributionSet)).isTrue();
assertThat(repositoryProperties.getSkipImplicitLockForTags().size()).isNotEqualTo(0);
assertThat(repositoryProperties.getSkipImplicitLockForTags().size()).isNotZero();
final List<DistributionSetTag> skipTags = distributionSetTagManagement.create(
repositoryProperties.getSkipImplicitLockForTags().stream()
.map(String::toLowerCase)
@@ -733,13 +733,12 @@ class DistributionSetManagementTest extends AbstractJpaIntegrationTest {
@Test
@Description("Locks an incomplete DS. Expected behaviour is to throw an exception and to do not lock it.")
void lockIncompleteDistributionSetFails() {
final DistributionSet incompleteDistributionSet = testdataFactory.createIncompleteDistributionSet();
final long incompleteDistributionSetId = testdataFactory.createIncompleteDistributionSet().getId();
assertThatExceptionOfType(IncompleteDistributionSetException.class)
.as("Locking an incomplete distribution set should throw an exception")
.isThrownBy(() -> distributionSetManagement.lock(incompleteDistributionSet.getId()));
.isThrownBy(() -> distributionSetManagement.lock(incompleteDistributionSetId));
assertThat(
distributionSetManagement.get(incompleteDistributionSet.getId()).map(DistributionSet::isLocked)
.orElse(true))
distributionSetManagement.get(incompleteDistributionSetId).map(DistributionSet::isLocked).orElse(true))
.isFalse();
}

View File

@@ -69,6 +69,15 @@ public class SystemManagementSecurityTest extends AbstractJpaIntegrationTest {
assertPermissions(() -> systemManagement.getTenantMetadata(), List.of(SpPermission.SpringEvalExpressions.CONTROLLER_ROLE), List.of(SpPermission.CREATE_REPOSITORY));
}
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void getTenantMetadataWithoutDetailsPermissionsCheck() {
assertPermissions(() -> systemManagement.getTenantMetadataWithoutDetails(), List.of(SpPermission.READ_REPOSITORY), List.of(SpPermission.CREATE_REPOSITORY));
assertPermissions(() -> systemManagement.getTenantMetadataWithoutDetails(), List.of(SpPermission.READ_TARGET), List.of(SpPermission.CREATE_REPOSITORY));
assertPermissions(() -> systemManagement.getTenantMetadataWithoutDetails(), List.of(SpPermission.READ_TENANT_CONFIGURATION), List.of(SpPermission.CREATE_REPOSITORY));
assertPermissions(() -> systemManagement.getTenantMetadataWithoutDetails(), List.of(SpPermission.SpringEvalExpressions.CONTROLLER_ROLE), List.of(SpPermission.CREATE_REPOSITORY));
}
@Test
@Description("Tests ManagementAPI PreAuthorized method with correct and insufficient permissions.")
void getTenantMetadataByTenantPermissionsCheck() {

View File

@@ -130,7 +130,7 @@ class SystemManagementTest extends AbstractJpaIntegrationTest {
final String tenantname = "TENANT" + i;
SecurityContextSwitch.runAs(SecurityContextSwitch.withUserAndTenant("bumlux", tenantname, true, true, false,
SpringEvalExpressions.SYSTEM_ROLE), () -> {
systemManagement.getTenantMetadata();
systemManagement.getTenantMetadataWithoutDetails();
if (artifactSize > 0) {
createTestArtifact(random);
createDeletedTestArtifact(random);

View File

@@ -112,11 +112,10 @@ public class MultiTenancyEntityTest extends AbstractJpaIntegrationTest {
assertThat(distributionSetTypeManagement.findAll(PAGE)).isNotEmpty();
// check that the cache is not getting in the way, i.e. "bumlux" results
// in bumlux and not
// mytenant
assertThat(SecurityContextSwitch.runAs(SecurityContextSwitch.withUserAndTenantAllSpPermissions("user", "bumlux"),
() -> systemManagement.getTenantMetadata().getTenant().toUpperCase()))
// check that the cache is not getting in the way, i.e. "bumlux" results in bumlux and not mytenant
assertThat(SecurityContextSwitch.runAs(
SecurityContextSwitch.withUserAndTenantAllSpPermissions("user", "bumlux"),
() -> systemManagement.getTenantMetadataWithoutDetails().getTenant().toUpperCase()))
.isEqualTo("bumlux".toUpperCase());
}