Fix auth -> authentication in some props in SDK (#2839)
Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
|
||||
import org.eclipse.hawkbit.repository.exception.InvalidTenantConfigurationKeyException;
|
||||
import org.eclipse.hawkbit.repository.exception.TenantConfigurationValidatorException;
|
||||
import org.eclipse.hawkbit.repository.jpa.AbstractJpaIntegrationTest;
|
||||
@@ -25,6 +26,7 @@ import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationProperties.TenantConfigurationKey;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -35,8 +37,16 @@ import org.springframework.core.env.Environment;
|
||||
*/
|
||||
class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest implements EnvironmentAware {
|
||||
|
||||
private TenantConfigurationManagement tenantConfigurationManagement;
|
||||
private Environment env;
|
||||
|
||||
@BeforeEach
|
||||
@Override
|
||||
public void beforeAll() throws Exception {
|
||||
super.beforeAll();
|
||||
tenantConfigurationManagement = tenantConfigurationManagement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnvironment(final Environment env) {
|
||||
this.env = env;
|
||||
@@ -51,7 +61,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
assertThat(envPropertyDefault).isNotNull();
|
||||
|
||||
// get the configuration from the system management
|
||||
final TenantConfigurationValue<String> defaultConfigValue = tenantConfigurationManagement().getConfigurationValue(
|
||||
final TenantConfigurationValue<String> defaultConfigValue = tenantConfigurationManagement.getConfigurationValue(
|
||||
TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, String.class);
|
||||
|
||||
assertThat(defaultConfigValue.isGlobal()).isTrue();
|
||||
@@ -60,11 +70,11 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
// update the tenant specific configuration, create
|
||||
final String newConfigurationValue = "thisIsAnotherTokenName";
|
||||
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue.getValue());
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(
|
||||
TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, newConfigurationValue);
|
||||
|
||||
// verify that new configuration value is used
|
||||
final TenantConfigurationValue<String> updatedConfigurationValue = tenantConfigurationManagement()
|
||||
final TenantConfigurationValue<String> updatedConfigurationValue = tenantConfigurationManagement
|
||||
.getConfigurationValue(TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, String.class);
|
||||
|
||||
assertThat(updatedConfigurationValue.isGlobal()).isFalse();
|
||||
@@ -73,16 +83,15 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
// update the tenant specific configuration, create
|
||||
final String newConfigurationValue2 = "thisIsAnotherTokenName2";
|
||||
assertThat(newConfigurationValue2).isNotEqualTo(updatedConfigurationValue.getValue());
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(
|
||||
TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, newConfigurationValue2);
|
||||
|
||||
// verify that new configuration value is used
|
||||
final TenantConfigurationValue<String> updatedConfigurationValue2 = tenantConfigurationManagement()
|
||||
final TenantConfigurationValue<String> updatedConfigurationValue2 = tenantConfigurationManagement
|
||||
.getConfigurationValue(TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, String.class);
|
||||
|
||||
assertThat(updatedConfigurationValue2.isGlobal()).isFalse();
|
||||
assertThat(updatedConfigurationValue2.getValue()).isEqualTo(newConfigurationValue2);
|
||||
// assertThat(tenantConfigurationManagement().getTenantConfigurations()).hasSize(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,12 +104,12 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
final String value2 = "secondValue";
|
||||
|
||||
// add value first
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, value1);
|
||||
assertThat(tenantConfigurationManagement().getConfigurationValue(configKey, String.class).getValue()).isEqualTo(value1);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
|
||||
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isEqualTo(value1);
|
||||
|
||||
// update to value second
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, value2);
|
||||
assertThat(tenantConfigurationManagement().getConfigurationValue(configKey, String.class).getValue()).isEqualTo(value2);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value2);
|
||||
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isEqualTo(value2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,12 +123,12 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
}};
|
||||
|
||||
// add value first
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configuration);
|
||||
assertThat(tenantConfigurationManagement().getConfigurationValue(
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configuration);
|
||||
assertThat(tenantConfigurationManagement.getConfigurationValue(
|
||||
TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, String.class).getValue())
|
||||
.isEqualTo("token_123");
|
||||
assertThat(
|
||||
tenantConfigurationManagement().getConfigurationValue(TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED, Boolean.class).getValue())
|
||||
tenantConfigurationManagement.getConfigurationValue(TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED, Boolean.class).getValue())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@@ -130,11 +139,11 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
void storeAndUpdateTenantSpecificConfigurationAsBoolean() {
|
||||
final String configKey = TenantConfigurationKey.AUTHENTICATION_HEADER_ENABLED;
|
||||
final Boolean value1 = true;
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, value1);
|
||||
assertThat(tenantConfigurationManagement().getConfigurationValue(configKey, Boolean.class).getValue()).isEqualTo(value1);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
|
||||
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Boolean.class).getValue()).isEqualTo(value1);
|
||||
final Boolean value2 = false;
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, value2);
|
||||
assertThat(tenantConfigurationManagement().getConfigurationValue(configKey, Boolean.class).getValue()).isEqualTo(value2);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value2);
|
||||
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Boolean.class).getValue()).isEqualTo(value2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +155,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
final String value1 = "thisIsNotABoolean";
|
||||
|
||||
// add value as String
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().addOrUpdateConfiguration(configKey, value1))
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1))
|
||||
.as("Should not have worked as value is not a boolean")
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
@@ -163,15 +172,15 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
}};
|
||||
|
||||
try {
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configuration);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configuration);
|
||||
fail("should not have worked as type is wrong");
|
||||
} catch (final TenantConfigurationValidatorException e) {
|
||||
assertThat(
|
||||
tenantConfigurationManagement().getConfigurationValue(
|
||||
tenantConfigurationManagement.getConfigurationValue(
|
||||
TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY, String.class).getValue())
|
||||
.isNotEqualTo("token_123");
|
||||
assertThat(
|
||||
tenantConfigurationManagement().getConfigurationValue(
|
||||
tenantConfigurationManagement.getConfigurationValue(
|
||||
TenantConfigurationKey.ROLLOUT_APPROVAL_ENABLED, Boolean.class).getValue())
|
||||
.isNotEqualTo(true);
|
||||
}
|
||||
@@ -185,22 +194,22 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
final String configKey = TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY;
|
||||
|
||||
// gateway token does not have default value so no configuration value should be available
|
||||
final String defaultConfigValue = tenantConfigurationManagement().getConfigurationValue(configKey, String.class).getValue();
|
||||
final String defaultConfigValue = tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue();
|
||||
assertThat(defaultConfigValue).isEmpty();
|
||||
|
||||
// update the tenant specific configuration
|
||||
final String newConfigurationValue = "thisIsAnotherValueForPolling";
|
||||
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue);
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, newConfigurationValue);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, newConfigurationValue);
|
||||
|
||||
// verify that new configuration value is used
|
||||
final String updatedConfigurationValue = tenantConfigurationManagement().getConfigurationValue(configKey, String.class).getValue();
|
||||
final String updatedConfigurationValue = tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue();
|
||||
assertThat(updatedConfigurationValue).isEqualTo(newConfigurationValue);
|
||||
|
||||
// delete the tenant specific configuration
|
||||
tenantConfigurationManagement().deleteConfiguration(configKey);
|
||||
tenantConfigurationManagement.deleteConfiguration(configKey);
|
||||
// ensure that now gateway token is set again, because is deleted and must be empty now
|
||||
assertThat(tenantConfigurationManagement().getConfigurationValue(configKey, String.class).getValue()).isEmpty();
|
||||
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +219,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
void storesIntegerWhenStringIsExpected() {
|
||||
final String configKey = TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_KEY;
|
||||
final Integer wrongDatType = 123;
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().addOrUpdateConfiguration(configKey, wrongDatType))
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDatType))
|
||||
.as("Should not have worked as integer is not a string")
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
@@ -222,7 +231,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
void storesIntegerWhenBooleanIsExpected() {
|
||||
final String configKey = TenantConfigurationKey.AUTHENTICATION_GATEWAY_SECURITY_TOKEN_ENABLED;
|
||||
final Integer wrongDataType = 123;
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().addOrUpdateConfiguration(configKey, wrongDataType))
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataType))
|
||||
.as("Should not have worked as integer is not a boolean")
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
@@ -234,7 +243,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
void storesIntegerWhenPollingIntervalIsExpected() {
|
||||
final String configKey = TenantConfigurationKey.POLLING_TIME;
|
||||
final Integer wrongDataType = 123;
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().addOrUpdateConfiguration(configKey, wrongDataType))
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataType))
|
||||
.as("Should not have worked as integer is not a time field")
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
@@ -246,7 +255,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
void storesWrongFormattedStringAsPollingInterval() {
|
||||
final String configKey = TenantConfigurationKey.POLLING_TIME;
|
||||
final String wrongFormatted = "wrongFormatted";
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().addOrUpdateConfiguration(configKey, wrongFormatted))
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongFormatted))
|
||||
.as("should not have worked as string is not a time field")
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
@@ -259,7 +268,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
final String configKey = TenantConfigurationKey.POLLING_TIME;
|
||||
|
||||
final String tooSmallDuration = DurationHelper.toString(getDurationByTimeValues(0, 0, 1));
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().addOrUpdateConfiguration(configKey, tooSmallDuration))
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration))
|
||||
.as("Should not have worked as string has an invalid format")
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
@@ -274,9 +283,9 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
final Duration duration = getDurationByTimeValues(1, 2, 0);
|
||||
assertThat(duration).isEqualTo(Duration.ofHours(1).plusMinutes(2));
|
||||
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, DurationHelper.toString(duration));
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, DurationHelper.toString(duration));
|
||||
|
||||
final String storedDurationString = tenantConfigurationManagement().getConfigurationValue(configKey, String.class).getValue();
|
||||
final String storedDurationString = tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue();
|
||||
assertThat(duration).isEqualTo(DurationHelper.fromString(storedDurationString));
|
||||
}
|
||||
|
||||
@@ -285,7 +294,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
*/
|
||||
@Test
|
||||
void requestConfigValueWithWrongType() {
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().getConfigurationValue(
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.getConfigurationValue(
|
||||
TenantConfigurationKey.POLLING_TIME, Serializable.class))
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
@@ -319,7 +328,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
@Test
|
||||
void storeTenantConfigurationWhichIsNotDeclaredThrowsException() {
|
||||
final String configKeyWhichDoesNotExists = "configKeyWhichDoesNotExists";
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement().addOrUpdateConfiguration(configKeyWhichDoesNotExists, "value"))
|
||||
assertThatThrownBy(() -> tenantConfigurationManagement.addOrUpdateConfiguration(configKeyWhichDoesNotExists, "value"))
|
||||
.as("Expected InvalidTenantConfigurationKeyException for tenant configuration key which is not declared")
|
||||
.isInstanceOf(InvalidTenantConfigurationKeyException.class);
|
||||
}
|
||||
@@ -328,16 +337,16 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
void storeTenantConfigNumberValue() {
|
||||
final String configKey = TenantConfigurationKey.ACTION_CLEANUP_AUTO_EXPIRY;
|
||||
// set auto cleanup for 1 day in Integer ms
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, 86400000);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, 86400000);
|
||||
|
||||
// expect long
|
||||
Long autoCleanupDaysInMs = tenantConfigurationManagement().getConfigurationValue(configKey, Long.class).getValue();
|
||||
Long autoCleanupDaysInMs = tenantConfigurationManagement.getConfigurationValue(configKey, Long.class).getValue();
|
||||
Assertions.assertEquals(86400000, autoCleanupDaysInMs);
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, 86400000);
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, 86400000);
|
||||
|
||||
// 30 days 2,592,000,000 ms as Long
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, 2592000000L);
|
||||
autoCleanupDaysInMs = tenantConfigurationManagement().getConfigurationValue(configKey, Long.class).getValue();
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, 2592000000L);
|
||||
autoCleanupDaysInMs = tenantConfigurationManagement.getConfigurationValue(configKey, Long.class).getValue();
|
||||
Assertions.assertEquals(2592000000L, autoCleanupDaysInMs);
|
||||
}
|
||||
|
||||
@@ -346,7 +355,7 @@ class TenantConfigurationManagementTest extends AbstractJpaIntegrationTest imple
|
||||
final String configKey = TenantConfigurationKey.ACTION_CLEANUP_AUTO_EXPIRY;
|
||||
// set auto cleanup for 1 day in String ms
|
||||
assertThatThrownBy(() ->
|
||||
tenantConfigurationManagement().addOrUpdateConfiguration(configKey, "86400000"))
|
||||
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, "86400000"))
|
||||
.as("Cannot convert the value 86400000 of type String to the type Long defined by the configuration key.")
|
||||
.isInstanceOf(TenantConfigurationValidatorException.class);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user