Fix tenant in TestdataFactory#rolloutHandleAll (#2543)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-07-11 12:45:05 +03:00
committed by GitHub
parent f249544f5d
commit 7ffd64c6da
2 changed files with 13 additions and 4 deletions

View File

@@ -169,11 +169,11 @@ public class TestConfiguration implements AsyncConfigurer {
final DeploymentManagement deploymentManagement, final DistributionSetTagManagement distributionSetTagManagement, final DeploymentManagement deploymentManagement, final DistributionSetTagManagement distributionSetTagManagement,
final RolloutManagement rolloutManagement, final RolloutHandler rolloutHandler, final RolloutManagement rolloutManagement, final RolloutHandler rolloutHandler,
final QuotaManagement quotaManagement, final QuotaManagement quotaManagement,
final EntityFactory entityFactory) { final EntityFactory entityFactory, final TenantAware tenantAware) {
return new TestdataFactory(controllerManagement, artifactManagement, softwareModuleManagement, softwareModuleTypeManagement, return new TestdataFactory(controllerManagement, artifactManagement, softwareModuleManagement, softwareModuleTypeManagement,
distributionSetManagement, distributionSetInvalidationManagement, distributionSetTypeManagement, targetManagement, distributionSetManagement, distributionSetInvalidationManagement, distributionSetTypeManagement, targetManagement,
targetFilterQueryManagement, targetTypeManagement, targetTagManagement, deploymentManagement, targetFilterQueryManagement, targetTypeManagement, targetTagManagement, deploymentManagement,
distributionSetTagManagement, rolloutManagement, rolloutHandler, quotaManagement, entityFactory); distributionSetTagManagement, rolloutManagement, rolloutHandler, quotaManagement, entityFactory, tenantAware);
} }
@Bean @Bean

View File

@@ -11,6 +11,8 @@ package org.eclipse.hawkbit.repository.test.util;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.SYSTEM_ROLE; import static org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions.SYSTEM_ROLE;
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.runAs;
import static org.eclipse.hawkbit.repository.test.util.SecurityContextSwitch.withUserAndTenant;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
@@ -78,6 +80,7 @@ import org.eclipse.hawkbit.repository.model.TargetFilterQuery;
import org.eclipse.hawkbit.repository.model.TargetTag; import org.eclipse.hawkbit.repository.model.TargetTag;
import org.eclipse.hawkbit.repository.model.TargetType; import org.eclipse.hawkbit.repository.model.TargetType;
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus; import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@@ -156,6 +159,7 @@ public class TestdataFactory {
private final RolloutHandler rolloutHandler; private final RolloutHandler rolloutHandler;
private final QuotaManagement quotaManagement; private final QuotaManagement quotaManagement;
private final EntityFactory entityFactory; private final EntityFactory entityFactory;
private final TenantAware tenantAware;
public TestdataFactory( public TestdataFactory(
final ControllerManagement controllerManagement, final ArtifactManagement artifactManagement, final ControllerManagement controllerManagement, final ArtifactManagement artifactManagement,
@@ -168,7 +172,7 @@ public class TestdataFactory {
final DeploymentManagement deploymentManagement, final DistributionSetTagManagement distributionSetTagManagement, final DeploymentManagement deploymentManagement, final DistributionSetTagManagement distributionSetTagManagement,
final RolloutManagement rolloutManagement, final RolloutHandler rolloutHandler, final RolloutManagement rolloutManagement, final RolloutHandler rolloutHandler,
final QuotaManagement quotaManagement, final QuotaManagement quotaManagement,
final EntityFactory entityFactory) { final EntityFactory entityFactory, final TenantAware tenantAware) {
this.controllerManagement = controllerManagement; this.controllerManagement = controllerManagement;
this.softwareModuleManagement = softwareModuleManagement; this.softwareModuleManagement = softwareModuleManagement;
this.softwareModuleTypeManagement = softwareModuleTypeManagement; this.softwareModuleTypeManagement = softwareModuleTypeManagement;
@@ -186,6 +190,7 @@ public class TestdataFactory {
this.rolloutManagement = rolloutManagement; this.rolloutManagement = rolloutManagement;
this.rolloutHandler = rolloutHandler; this.rolloutHandler = rolloutHandler;
this.quotaManagement = quotaManagement; this.quotaManagement = quotaManagement;
this.tenantAware = tenantAware;
} }
public static String randomString(final int len) { public static String randomString(final int len) {
@@ -1259,7 +1264,11 @@ public class TestdataFactory {
} }
private void rolloutHandleAll() { private void rolloutHandleAll() {
SecurityContextSwitch.runAs(SecurityContextSwitch.withUser("system", SYSTEM_ROLE), rolloutHandler::handleAll); final String tenant = tenantAware.getCurrentTenant();
if (tenant == null) {
throw new IllegalStateException("Tenant is null");
}
runAs(withUserAndTenant("system", tenant, false, false, false, SYSTEM_ROLE), rolloutHandler::handleAll);
} }
private Rollout reloadRollout(final Rollout rollout) { private Rollout reloadRollout(final Rollout rollout) {