add SystemSecurityContext (#1269)
Signed-off-by: Stefan Klotz <stefan.klotz@bosch.io>
This commit is contained in:
@@ -11,17 +11,22 @@ package org.eclipse.hawkbit.repository.jpa.rsql;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import org.apache.commons.lang3.text.StrSubstitutor;
|
import org.apache.commons.lang3.text.StrSubstitutor;
|
||||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||||
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||||
|
import org.eclipse.hawkbit.repository.model.helper.SystemSecurityContextHolder;
|
||||||
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
import org.eclipse.hawkbit.repository.model.helper.TenantConfigurationManagementHolder;
|
||||||
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
import org.eclipse.hawkbit.repository.rsql.VirtualPropertyResolver;
|
||||||
|
import org.eclipse.hawkbit.security.SystemSecurityContext;
|
||||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
import org.mockito.Mockito;
|
||||||
import org.mockito.Spy;
|
import org.mockito.Spy;
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@@ -43,6 +48,9 @@ public class VirtualPropertyResolverTest {
|
|||||||
@MockBean
|
@MockBean
|
||||||
private TenantConfigurationManagement confMgmt;
|
private TenantConfigurationManagement confMgmt;
|
||||||
|
|
||||||
|
@MockBean
|
||||||
|
private SystemSecurityContext securityContext;
|
||||||
|
|
||||||
private StrSubstitutor substitutor;
|
private StrSubstitutor substitutor;
|
||||||
|
|
||||||
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
|
private static final TenantConfigurationValue<String> TEST_POLLING_TIME_INTERVAL = TenantConfigurationValue
|
||||||
@@ -56,6 +64,11 @@ public class VirtualPropertyResolverTest {
|
|||||||
TenantConfigurationManagementHolder tenantConfigurationManagementHolder() {
|
TenantConfigurationManagementHolder tenantConfigurationManagementHolder() {
|
||||||
return TenantConfigurationManagementHolder.getInstance();
|
return TenantConfigurationManagementHolder.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
SystemSecurityContextHolder systemSecurityContextHolder() {
|
||||||
|
return SystemSecurityContextHolder.getInstance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@@ -73,6 +86,7 @@ public class VirtualPropertyResolverTest {
|
|||||||
@ValueSource(strings = { "${NOW_TS}", "${OVERDUE_TS}", "${overdue_ts}" })
|
@ValueSource(strings = { "${NOW_TS}", "${OVERDUE_TS}", "${overdue_ts}" })
|
||||||
@Description("Tests resolution of NOW_TS by using a StrSubstitutor configured with the VirtualPropertyResolver.")
|
@Description("Tests resolution of NOW_TS by using a StrSubstitutor configured with the VirtualPropertyResolver.")
|
||||||
void resolveNowTimestampPlaceholder(final String placeholder) {
|
void resolveNowTimestampPlaceholder(final String placeholder) {
|
||||||
|
when(securityContext.runAsSystem(Mockito.any())).thenAnswer(a -> ((Callable<?>) a.getArgument(0)).call());
|
||||||
final String testString = "lhs=lt=" + placeholder;
|
final String testString = "lhs=lt=" + placeholder;
|
||||||
|
|
||||||
final String resolvedPlaceholders = substitutor.replace(testString);
|
final String resolvedPlaceholders = substitutor.replace(testString);
|
||||||
|
|||||||
Reference in New Issue
Block a user