amendmends according to code-review
This commit is contained in:
parent
d22d81e71c
commit
274b74514c
@ -10,8 +10,8 @@ import static net.hostsharing.hsadminng.hs.validation.StringProperty.stringPrope
|
|||||||
|
|
||||||
class HsEMailAliasHostingAssetValidator extends HsHostingAssetEntityValidator {
|
class HsEMailAliasHostingAssetValidator extends HsHostingAssetEntityValidator {
|
||||||
|
|
||||||
private static final String UNIX_USER_REGEX = "^[a-z]{3}[0-9]{2}(-[a-z0-9]+)?$";
|
private static final String UNIX_USER_REGEX = "^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9]+)?$"; // also accepts legacy pac-names
|
||||||
private static final String EMAIL_ADDRESS_REGEX = "^[a-zA-Z0-9_.±]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$";
|
private static final String EMAIL_ADDRESS_REGEX = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"; // RFC 5322
|
||||||
public static final int EMAIL_ADDRESS_MAX_LENGTH = 320; // according to RFC 5321 and RFC 5322
|
public static final int EMAIL_ADDRESS_MAX_LENGTH = 320; // according to RFC 5321 and RFC 5322
|
||||||
|
|
||||||
HsEMailAliasHostingAssetValidator() {
|
HsEMailAliasHostingAssetValidator() {
|
||||||
|
@ -6,15 +6,15 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static java.util.Arrays.stream;
|
import static java.util.Arrays.stream;
|
||||||
import static net.hostsharing.hsadminng.mapper.Array.insertAfterEntries;
|
import static net.hostsharing.hsadminng.mapper.Array.insertNewEntriesAfterExistingEntry;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
public class ArrayProperty<P extends ValidatableProperty<?, E>, E> extends ValidatableProperty<ArrayProperty<P, E>, E[]> {
|
public class ArrayProperty<P extends ValidatableProperty<?, E>, E> extends ValidatableProperty<ArrayProperty<P, E>, E[]> {
|
||||||
|
|
||||||
private static final String[] KEY_ORDER =
|
private static final String[] KEY_ORDER =
|
||||||
insertAfterEntries(
|
insertNewEntriesAfterExistingEntry(
|
||||||
insertAfterEntries(ValidatableProperty.KEY_ORDER, "required", "minLength" ,"maxLength"),
|
insertNewEntriesAfterExistingEntry(ValidatableProperty.KEY_ORDER, "required", "minLength" ,"maxLength"),
|
||||||
"propertyName", "elementProperty");
|
"propertyName", "elementsOf");
|
||||||
private final ValidatableProperty<?, E> elementsOf;
|
private final ValidatableProperty<?, E> elementsOf;
|
||||||
private Integer minLength;
|
private Integer minLength;
|
||||||
private Integer maxLength;
|
private Integer maxLength;
|
||||||
|
@ -8,12 +8,12 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import static java.util.Optional.ofNullable;
|
import static java.util.Optional.ofNullable;
|
||||||
import static net.hostsharing.hsadminng.hash.LinuxEtcShadowHashGenerator.hash;
|
import static net.hostsharing.hsadminng.hash.LinuxEtcShadowHashGenerator.hash;
|
||||||
import static net.hostsharing.hsadminng.mapper.Array.insertAfterEntries;
|
import static net.hostsharing.hsadminng.mapper.Array.insertNewEntriesAfterExistingEntry;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
public class PasswordProperty extends StringProperty<PasswordProperty> {
|
public class PasswordProperty extends StringProperty<PasswordProperty> {
|
||||||
|
|
||||||
private static final String[] KEY_ORDER = insertAfterEntries(StringProperty.KEY_ORDER, "computed", "hashedUsing");
|
private static final String[] KEY_ORDER = insertNewEntriesAfterExistingEntry(StringProperty.KEY_ORDER, "computed", "hashedUsing");
|
||||||
|
|
||||||
private Algorithm hashedUsing;
|
private Algorithm hashedUsing;
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ public class Array {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
public static <T> T[] insertAfterEntries(final T[] array, final T entryToFind, final T... newEntries) {
|
public static <T> T[] insertNewEntriesAfterExistingEntry(final T[] array, final T entryToFind, final T... newEntries) {
|
||||||
final var arrayList = new ArrayList<>(asList(array));
|
final var arrayList = new ArrayList<>(asList(array));
|
||||||
final var index = arrayList.indexOf(entryToFind);
|
final var index = arrayList.indexOf(entryToFind);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
|
@ -22,7 +22,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
|
assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder(
|
||||||
"{type=string[], propertyName=target, elementProperty={type=string, propertyName=target, matchesRegEx=[^[a-z]{3}[0-9]{2}(-[a-z0-9]+)?$, ^[a-zA-Z0-9_.±]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$], maxLength=320}, required=true, minLength=1}");
|
"{type=string[], propertyName=target, elementsOf={type=string, propertyName=target, matchesRegEx=[^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9]+)?$, ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$], maxLength=320}, required=true, minLength=1}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -63,7 +63,7 @@ class HsEMailAliasHostingAssetValidatorUnitTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result).containsExactlyInAnyOrder(
|
assertThat(result).containsExactlyInAnyOrder(
|
||||||
"'EMAIL_ALIAS:xyz00-office.config.target' is expected to match any of [^[a-z]{3}[0-9]{2}(-[a-z0-9]+)?$, ^[a-zA-Z0-9_.±]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$] but 'garbage' does not match any");
|
"'EMAIL_ALIAS:xyz00-office.config.target' is expected to match any of [^[a-z][a-z0-9]{2}[0-9]{2}(-[a-z0-9]+)?$, ^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$] but 'garbage' does not match any");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user