Feature extend target attributes constraints (#799)
* extended target attributes key limit to 128 characters Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com> * fixed tests Signed-off-by: Bogdan Bondar <Bogdan.Bondar@bosch-si.com>
This commit is contained in:
committed by
Dominic Schabel
parent
caca308f47
commit
473b6b2cc5
@@ -41,6 +41,7 @@ import org.eclipse.hawkbit.repository.model.Action.Status;
|
||||
import org.eclipse.hawkbit.repository.model.ActionStatus;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSet;
|
||||
import org.eclipse.hawkbit.repository.model.DistributionSetAssignmentResult;
|
||||
import org.eclipse.hawkbit.repository.model.Target;
|
||||
import org.eclipse.hawkbit.repository.model.TargetUpdateStatus;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.Expect;
|
||||
import org.eclipse.hawkbit.repository.test.matcher.ExpectEvents;
|
||||
@@ -782,10 +783,10 @@ public class AmqpMessageHandlerServiceIntegrationTest extends AbstractAmqpServic
|
||||
// setup
|
||||
final String target = "ControllerAttributeTestTarget";
|
||||
registerAndAssertTargetWithExistingTenant(target);
|
||||
final String keyTooLong = "123456789012345678901234567890123";
|
||||
final String keyValid = "12345678901234567890123456789012";
|
||||
final String valueTooLong = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
||||
final String valueValid = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678";
|
||||
final String keyTooLong = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE + 1);
|
||||
final String keyValid = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE);
|
||||
final String valueTooLong = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE + 1);
|
||||
final String valueValid = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE);
|
||||
|
||||
sendUpdateAttributesMessageWithGivenAttributes(target, keyTooLong, valueValid);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public interface Target extends NamedEntity {
|
||||
/**
|
||||
* Maximum length of key of controller attribute
|
||||
*/
|
||||
int CONTROLLER_ATTRIBUTE_KEY_SIZE = 32;
|
||||
int CONTROLLER_ATTRIBUTE_KEY_SIZE = 128;
|
||||
|
||||
/**
|
||||
* Maximum length of value of controller attribute
|
||||
|
||||
@@ -156,8 +156,8 @@ public class JpaTarget extends AbstractJpaNamedEntity implements Target, EventAw
|
||||
*/
|
||||
@CascadeOnDelete
|
||||
@ElementCollection
|
||||
@Column(name = "attribute_value", length = 128)
|
||||
@MapKeyColumn(name = "attribute_key", nullable = false, length = 32)
|
||||
@Column(name = "attribute_value", length = Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE)
|
||||
@MapKeyColumn(name = "attribute_key", nullable = false, length = Target.CONTROLLER_ATTRIBUTE_KEY_SIZE)
|
||||
@CollectionTable(name = "sp_target_attributes", joinColumns = {
|
||||
@JoinColumn(name = "target_id", nullable = false, updatable = false) }, foreignKey = @ForeignKey(value = ConstraintMode.CONSTRAINT, name = "fk_targ_attrib_target"))
|
||||
private final Map<String, String> controllerAttributes = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sp_target_attributes ALTER COLUMN attribute_key SET DATA TYPE VARCHAR(128);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sp_target_attributes ALTER COLUMN attribute_key VARCHAR(128);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sp_target_attributes MODIFY attribute_key VARCHAR(128);
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE sp_target_attributes ALTER COLUMN attribute_key VARCHAR(128);
|
||||
@@ -847,10 +847,10 @@ public class ControllerManagementTest extends AbstractJpaIntegrationTest {
|
||||
@Test
|
||||
@Description("Checks if invalid values of attribute-key and attribute-value are handled correctly")
|
||||
public void updateTargetAttributesFailsForInvalidAttributes() {
|
||||
final String keyTooLong = "123456789012345678901234567890123";
|
||||
final String keyValid = "12345678901234567890123456789012";
|
||||
final String valueTooLong = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
||||
final String valueValid = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678";
|
||||
final String keyTooLong = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE + 1);
|
||||
final String keyValid = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE);
|
||||
final String valueTooLong = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE + 1);
|
||||
final String valueValid = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE);
|
||||
final String keyNull = null;
|
||||
|
||||
final String controllerId = "targetId123";
|
||||
|
||||
@@ -18,6 +18,7 @@ import java.time.ZonedDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
@@ -414,4 +415,18 @@ public abstract class AbstractIntegrationTest {
|
||||
final ZonedDateTime currentTime = ZonedDateTime.now();
|
||||
return currentTime.getOffset().getId().replace("Z", "+00:00");
|
||||
}
|
||||
|
||||
protected static String generateRandomStringWithLength(final int length) {
|
||||
final StringBuilder randomStringBuilder = new StringBuilder(length);
|
||||
final Random rand = new Random();
|
||||
final int lowercaseACode = 97;
|
||||
final int lowercaseZCode = 122;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
final char randomCharacter = (char) (rand.nextInt(lowercaseZCode - lowercaseACode + 1) + lowercaseACode);
|
||||
randomStringBuilder.append(randomCharacter);
|
||||
}
|
||||
|
||||
return randomStringBuilder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,11 @@ import io.qameta.allure.Story;
|
||||
@Story("Config Data Resource")
|
||||
public class DdiConfigDataTest extends AbstractDDiApiIntegrationTest {
|
||||
|
||||
private static final String KEY_TOO_LONG = "123456789012345678901234567890123";
|
||||
private static final String KEY_VALID = "12345678901234567890123456789012";
|
||||
private static final String VALUE_TOO_LONG = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
|
||||
private static final String VALUE_VALID = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678";
|
||||
private static final String KEY_TOO_LONG = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE + 1);
|
||||
private static final String KEY_VALID = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_KEY_SIZE);
|
||||
private static final String VALUE_TOO_LONG = generateRandomStringWithLength(
|
||||
Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE + 1);
|
||||
private static final String VALUE_VALID = generateRandomStringWithLength(Target.CONTROLLER_ATTRIBUTE_VALUE_SIZE);
|
||||
|
||||
@Test
|
||||
@Description("We verify that the config data (i.e. device attributes like serial number, hardware revision etc.) "
|
||||
|
||||
Reference in New Issue
Block a user