add UnixUser HostingAsset property validation tests
This commit is contained in:
parent
cf6bcc0b94
commit
ce0e99fd3a
@ -25,7 +25,7 @@ class HsUnixUserHostingAssetValidator extends HsHostingAssetEntityValidator {
|
||||
.values("/bin/false", "/bin/bash", "/bin/csh", "/bin/dash", "/usr/bin/tcsh", "/usr/bin/zsh", "/usr/bin/passwd")
|
||||
.withDefault("/bin/false"),
|
||||
stringProperty("homedir").readOnly(),
|
||||
stringProperty("totpKey").matchesRegEx("^0x\\([0-9A-Fa-f][0-9A-Fa-f]\\)+$").minLength(12).maxLength(32).writeOnly().optional(),
|
||||
stringProperty("totpKey").matchesRegEx("^0x([0-9A-Fa-f]{2})+$").minLength(12).maxLength(32).writeOnly().optional(),
|
||||
stringProperty("password").minLength(8).maxLength(40).writeOnly()); // FIXME: spec
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,7 @@ public class IntegerProperty extends ValidatableProperty<Integer> {
|
||||
if (step != null && propValue % step != 0) {
|
||||
result.add(propertyName + "' is expected to be multiple of " + step + " but is " + propValue);
|
||||
}
|
||||
// FIXME: maxFrom+minFrom not yet implemented
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -67,6 +67,9 @@ public class StringProperty extends ValidatableProperty<String> {
|
||||
if (regExPattern != null && !regExPattern.matcher(propValue).matches()) {
|
||||
result.add(propertyName + "' is expected to be match " + regExPattern + " but '" + propValue+ "' does not match");
|
||||
}
|
||||
if (readOnly && propValue != null) {
|
||||
result.add(propertyName + "' is readonly but given as '" + propValue+ "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,6 +36,15 @@ class HsUnixUserHostingAssetValidatorUnitTest {
|
||||
.parentAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET)
|
||||
.identifier("abc00-temp")
|
||||
.caption("some valid test UnixUser")
|
||||
.config(Map.ofEntries(
|
||||
entry("SSD hard quota", 1000),
|
||||
entry("SSD soft quota", 2000),
|
||||
entry("HDD hard quota", 1000),
|
||||
entry("HDD soft quota", 2000),
|
||||
entry("homedir", "/bin/bash"),
|
||||
entry("totpKey", "0x123456789abcdef0"),
|
||||
entry("password", "Hallo Computer, lass mich rein!")
|
||||
))
|
||||
.build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
|
||||
|
||||
@ -59,9 +68,10 @@ class HsUnixUserHostingAssetValidatorUnitTest {
|
||||
entry("SSD soft quota", 2000),
|
||||
entry("HDD hard quota", 1000),
|
||||
entry("HDD soft quota", 2000),
|
||||
entry("shell", "/is/invalid"),
|
||||
entry("homedir", "/is/read-only"),
|
||||
entry("totpKey", "should be a hex number"),
|
||||
entry("password", "should be a hex number")
|
||||
entry("password", "short")
|
||||
))
|
||||
.build();
|
||||
final var validator = HsHostingAssetEntityValidatorRegistry.forType(unixUserHostingAsset.getType());
|
||||
@ -70,7 +80,13 @@ class HsUnixUserHostingAssetValidatorUnitTest {
|
||||
final var result = validator.validate(unixUserHostingAsset);
|
||||
|
||||
// then
|
||||
assertThat(result).isEmpty();
|
||||
assertThat(result).containsExactlyInAnyOrder(
|
||||
// FIXME: quota valiations against parent billing item not yet implemented
|
||||
"'UNIX_USER:abc00-temp.config.shell' is expected to be one of [/bin/false, /bin/bash, /bin/csh, /bin/dash, /usr/bin/tcsh, /usr/bin/zsh, /usr/bin/passwd] but is '/is/invalid'",
|
||||
"'UNIX_USER:abc00-temp.config.homedir' is readonly but given as '/is/read-only'",
|
||||
"'UNIX_USER:abc00-temp.config.totpKey' is expected to be match ^0x([0-9A-Fa-f]{2})+$ but 'should be a hex number' does not match",
|
||||
"'UNIX_USER:abc00-temp.config.password' length is expected to be at min 8 but length of 'short' is 5"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user