From cf461047664706057e755c7baf096bf1e0909f77 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 11 Sep 2024 19:56:54 +0200 Subject: [PATCH] user definable verificationCode --- .../HsDomainSetupBookingItemValidator.java | 5 ++-- .../hs/validation/ValidatableProperty.java | 2 +- ...mainSetupBookingItemValidatorUnitTest.java | 24 +++++++++++++++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidator.java index 3d62b765..c9fd731a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidator.java @@ -25,8 +25,9 @@ class HsDomainSetupBookingItemValidator extends HsBookingItemEntityValidator { .notMatchesRegEx(REGISTRAR_LEVEL_DOMAINS).describedAs("is a forbidden registrar-level domain name") .required(), stringProperty(VERIFICATION_CODE_PROPERTY_NAME) - .readOnly().initializedBy(HsDomainSetupBookingItemValidator::generateVerificationCode) - + .minLength(12) + .maxLength(64) + .initializedBy(HsDomainSetupBookingItemValidator::generateVerificationCode) ); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java b/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java index d0966a5e..fb51e7fe 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/validation/ValidatableProperty.java @@ -266,7 +266,7 @@ public abstract class ValidatableProperty

, T private boolean isSpecPotentiallyComplete() { return required == null && requiresAtLeastOneOf == null && requiresAtMaxOneOf == null && !readOnly && !writeOnly - && defaultValue == null; + && defaultValue == null && computedBy == null; } @SuppressWarnings("unchecked") diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidatorUnitTest.java index 9fbdac45..643c5e54 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsDomainSetupBookingItemValidatorUnitTest.java @@ -28,7 +28,7 @@ class HsDomainSetupBookingItemValidatorUnitTest { private EntityManager em; @Test - void acceptsRegisterableDomain() { + void acceptsRegisterableDomainWithGeneratedVerificationCode() { // given final var domainSetupBookingItemEntity = HsBookingItemRealEntity.builder() .type(DOMAIN_SETUP) @@ -46,6 +46,26 @@ class HsDomainSetupBookingItemValidatorUnitTest { assertThat(result).isEmpty(); } + @Test + void acceptsRegisterableDomainWithExplicitVerifiactionCode() { + // given + final var domainSetupBookingItemEntity = HsBookingItemRealEntity.builder() + .type(DOMAIN_SETUP) + .project(project) + .caption("Test-Domain") + .resources(Map.ofEntries( + entry("domainName", "example.org"), + entry("verificationCode", "1234-5678-9100") + )) + .build(); + + // when + final var result = HsBookingItemEntityValidatorRegistry.doValidate(em, domainSetupBookingItemEntity); + + // then + assertThat(result).isEmpty(); + } + @Test void acceptsMaximumDomainNameLength() { final var domainSetupBookingItemEntity = HsBookingItemRealEntity.builder() @@ -150,6 +170,6 @@ class HsDomainSetupBookingItemValidatorUnitTest { // then assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder( "{type=string, propertyName=domainName, matchesRegEx=[^((?!-)[A-Za-z0-9-]{1,63}(?