From 2a4728bc7e3575edef42c5dabd410adcc6061fd6 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 9 Jul 2024 15:53:03 +0200 Subject: [PATCH 1/8] add HsDomainSetupHostingAssetValidator --- ...ttpSetupHostingAssetValidatorUnitTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java index c84dd2b1..fa75cded 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java @@ -14,6 +14,12 @@ import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMA import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_COMMENT; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_DATA; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_TYPE; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_IN; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_NAME; +import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_TTL; import static org.assertj.core.api.Assertions.assertThat; class HsDomainHttpSetupHostingAssetValidatorUnitTest { @@ -160,4 +166,32 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest { "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(? Date: Tue, 9 Jul 2024 17:02:07 +0200 Subject: [PATCH 2/8] add HsDomainEMailSubmissionSetupHostingAssetValidator --- .../hs/booking/item/HsBookingItemType.java | 4 +- .../HostingAssetEntityValidatorRegistry.java | 1 + ...lSubmissionSetupHostingAssetValidator.java | 34 +++++ .../hs-hosting/hs-hosting-asset-schemas.yaml | 3 +- .../HsHostingAssetControllerRestTest.java | 22 ++- ...ingAssetPropsControllerAcceptanceTest.java | 3 +- .../asset/HsHostingAssetTypeUnitTest.java | 6 - ...gAssetEntityValidatorRegistryUnitTest.java | 3 +- ...ionSetupHostingAssetValidatorUnitTest.java | 133 ++++++++++++++++++ 9 files changed, 195 insertions(+), 14 deletions(-) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemType.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemType.java index 720b3ecc..8b51def8 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemType.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/HsBookingItemType.java @@ -8,9 +8,7 @@ public enum HsBookingItemType implements Node { PRIVATE_CLOUD, CLOUD_SERVER(PRIVATE_CLOUD), MANAGED_SERVER(PRIVATE_CLOUD), - MANAGED_WEBSPACE(MANAGED_SERVER), - DOMAIN_DNS_SETUP, // TODO.spec: experimental - DOMAIN_EMAIL_SUBMISSION_SETUP; // TODO.spec: experimental + MANAGED_WEBSPACE(MANAGED_SERVER); private final HsBookingItemType parentItemType; diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java index 62e47dec..6efbed70 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java @@ -23,6 +23,7 @@ public class HostingAssetEntityValidatorRegistry { register(DOMAIN_SETUP, new HsDomainSetupHostingAssetValidator()); register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator()); register(DOMAIN_HTTP_SETUP, new HsDomainHttpSetupHostingAssetValidator()); + register(DOMAIN_EMAIL_SUBMISSION_SETUP, new HsDomainEMailSubmissionSetupHostingAssetValidator()); } private static void register(final Enum type, final HsEntityValidator validator) { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java new file mode 100644 index 00000000..aa80d332 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java @@ -0,0 +1,34 @@ +package net.hostsharing.hsadminng.hs.hosting.asset.validators; + +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; + +import java.util.regex.Pattern; + +import static java.util.Optional.ofNullable; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP; + +class HsDomainEMailSubmissionSetupHostingAssetValidator extends HostingAssetEntityValidator { + + public static final String IDENTIFIER_SUFFIX = "|SMTP"; + + HsDomainEMailSubmissionSetupHostingAssetValidator() { + super( + DOMAIN_EMAIL_SUBMISSION_SETUP, + AlarmContact.isOptional(), + + NO_EXTRA_PROPERTIES); + } + + @Override + protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$"); + } + + @Override + public void preprocessEntity(final HsHostingAssetEntity entity) { + super.preprocessEntity(entity); + if (entity.getIdentifier() == null) { + ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX)); + } + } +} diff --git a/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml b/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml index a9ab7f64..11cb1050 100644 --- a/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml +++ b/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml @@ -13,7 +13,8 @@ components: - DOMAIN_SETUP - DOMAIN_DNS_SETUP - DOMAIN_HTTP_SETUP - - DOMAIN_EMAIL_SETUP + - DOMAIN_EMAIL_SUBMISSION_SETUP + - DOMAIN_EMAIL_MAILBOX_SETUP - EMAIL_ALIAS - EMAIL_ADDRESS - PGSQL_USER diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java index bdaacf04..76c5a379 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java @@ -251,7 +251,7 @@ public class HsHostingAssetControllerRestTest { List.of( HsHostingAssetEntity.builder() .type(HsHostingAssetType.DOMAIN_HTTP_SETUP) - .identifier("example.org") + .identifier("example.org|HTTP") .caption("some fake Domain-HTTP-Setup") .config(Map.ofEntries( entry("htdocsfallback", false), @@ -276,7 +276,7 @@ public class HsHostingAssetControllerRestTest { [ { "type": "DOMAIN_HTTP_SETUP", - "identifier": "example.org", + "identifier": "example.org|HTTP", "caption": "some fake Domain-HTTP-Setup", "alarmContact": null, "config": { @@ -299,6 +299,24 @@ public class HsHostingAssetControllerRestTest { } } ] + """), + DOMAIN_EMAIL_SUBMISSION_SETUP( + List.of( + HsHostingAssetEntity.builder() + .type(HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP) + .identifier("example.org|SMTP") + .caption("some fake Domain-SMTP-Setup") + .build()), + """ + [ + { + "type": "DOMAIN_EMAIL_SUBMISSION_SETUP", + "identifier": "example.org|SMTP", + "caption": "some fake Domain-SMTP-Setup", + "alarmContact": null, + "config": {} + } + ] """); final HsHostingAssetType assetType; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java index dd4afc09..ac011d68 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java @@ -38,7 +38,8 @@ class HsHostingAssetPropsControllerAcceptanceTest { "EMAIL_ALIAS", "DOMAIN_SETUP", "DOMAIN_DNS_SETUP", - "DOMAIN_HTTP_SETUP" + "DOMAIN_HTTP_SETUP", + "DOMAIN_EMAIL_SUBMISSION_SETUP" ] """)); // @formatter:on diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java index 794c3f25..91d141a2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java @@ -25,8 +25,6 @@ class HsHostingAssetTypeUnitTest { entity BI_CLOUD_SERVER entity BI_MANAGED_SERVER entity BI_MANAGED_WEBSPACE - entity BI_DOMAIN_DNS_SETUP - entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP } package Hosting #feb28c{ @@ -96,8 +94,6 @@ class HsHostingAssetTypeUnitTest { entity BI_CLOUD_SERVER entity BI_MANAGED_SERVER entity BI_MANAGED_WEBSPACE - entity BI_DOMAIN_DNS_SETUP - entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP } package Hosting #feb28c{ @@ -160,8 +156,6 @@ class HsHostingAssetTypeUnitTest { entity BI_CLOUD_SERVER entity BI_MANAGED_SERVER entity BI_MANAGED_WEBSPACE - entity BI_DOMAIN_DNS_SETUP - entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP } package Hosting #feb28c{ diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java index daf0704f..a041742b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java @@ -36,7 +36,8 @@ class HostingAssetEntityValidatorRegistryUnitTest { HsHostingAssetType.EMAIL_ALIAS, HsHostingAssetType.DOMAIN_SETUP, HsHostingAssetType.DOMAIN_DNS_SETUP, - HsHostingAssetType.DOMAIN_HTTP_SETUP + HsHostingAssetType.DOMAIN_HTTP_SETUP, + HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP ); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java new file mode 100644 index 00000000..57c847fc --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java @@ -0,0 +1,133 @@ +package net.hostsharing.hsadminng.hs.hosting.asset.validators; + +import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; +import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static java.util.Map.entry; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; +import static org.assertj.core.api.Assertions.assertThat; + +class HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest { + + static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() + .type(DOMAIN_SETUP) + .identifier("example.org") + .build(); + + static HsHostingAssetEntityBuilder validEntityBuilder() { + return HsHostingAssetEntity.builder() + .type(DOMAIN_EMAIL_SUBMISSION_SETUP) + .parentAsset(validDomainSetupEntity) + .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .identifier("example.org|SMTP"); + } + + @Test + void containsExpectedProperties() { + // when + final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_EMAIL_SUBMISSION_SETUP); + + // then + assertThat(validator.properties()).map(Map::toString).isEmpty(); + } + + @Test + void preprocessesTakesIdentifierFromParent() { + // given + final var givenEntity = validEntityBuilder().build(); + assertThat(givenEntity.getParentAsset().getIdentifier()).as("precondition failed").isEqualTo("example.org"); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + validator.preprocessEntity(givenEntity); + + // then + assertThat(givenEntity.getIdentifier()).isEqualTo("example.org|SMTP"); + } + + @Test + void rejectsInvalidIdentifier() { + // given + final var givenEntity = validEntityBuilder().identifier("example.org").build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + final var result = validator.validateEntity(givenEntity); + + // then + assertThat(result).containsExactly( + "'identifier' expected to match '^example.org\\Q|SMTP\\E$', but is 'example.org'" + ); + } + + @Test + void acceptsValidIdentifier() { + // given + final var givenEntity = validEntityBuilder().identifier(validDomainSetupEntity.getIdentifier()+"|SMTP").build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + final var result = validator.validateEntity(givenEntity); + + // then + assertThat(result).isEmpty(); + } + + @Test + void rejectsInvalidReferencedEntities() { + // given + final var mangedServerHostingAssetEntity = validEntityBuilder() + .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) + .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(null) + .build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(mangedServerHostingAssetEntity); + + // then + assertThat(result).containsExactlyInAnyOrder( + "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.bookingItem' must be null but is of type CLOUD_SERVER", + "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.parentAsset' must be of type DOMAIN_SETUP but is of type MANAGED_WEBSPACE", + "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.assignedToAsset' must be of type MANAGED_WEBSPACE but is null"); + } + + @Test + void acceptsValidEntity() { + // given + final var givenEntity = validEntityBuilder().build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + final var errors = validator.validateEntity(givenEntity); + + // then + assertThat(errors).isEmpty(); + } + + @Test + void rejectsInvalidProperties() { + // given + final var mangedServerHostingAssetEntity = validEntityBuilder() + .config(Map.ofEntries( + entry("any", "false") + )) + .build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(mangedServerHostingAssetEntity); + + // then + assertThat(result).containsExactlyInAnyOrder( + "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.config.any' is not expected but is set to 'false'"); + } +} -- 2.39.5 From fa943d409d17f9cbfe614e545251bd8a962fecca Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 10 Jul 2024 08:41:55 +0200 Subject: [PATCH 3/8] add HsDomainEMailMailboxSetupHostingAssetValidator --- .../HostingAssetEntityValidatorRegistry.java | 1 + ...MailMailboxSetupHostingAssetValidator.java | 34 +++++ .../HsHostingAssetControllerRestTest.java | 18 +++ ...boxSetupHostingAssetValidatorUnitTest.java | 133 ++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java index 6efbed70..5b287a14 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java @@ -24,6 +24,7 @@ public class HostingAssetEntityValidatorRegistry { register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator()); register(DOMAIN_HTTP_SETUP, new HsDomainHttpSetupHostingAssetValidator()); register(DOMAIN_EMAIL_SUBMISSION_SETUP, new HsDomainEMailSubmissionSetupHostingAssetValidator()); + register(DOMAIN_EMAIL_MAILBOX_SETUP, new HsDomainEMailMailboxSetupHostingAssetValidator()); } private static void register(final Enum type, final HsEntityValidator validator) { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java new file mode 100644 index 00000000..5e919b00 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java @@ -0,0 +1,34 @@ +package net.hostsharing.hsadminng.hs.hosting.asset.validators; + +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; + +import java.util.regex.Pattern; + +import static java.util.Optional.ofNullable; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP; + +class HsDomainEMailMailboxSetupHostingAssetValidator extends HostingAssetEntityValidator { + + public static final String IDENTIFIER_SUFFIX = "|MBOX"; + + HsDomainEMailMailboxSetupHostingAssetValidator() { + super( + DOMAIN_EMAIL_SUBMISSION_SETUP, + AlarmContact.isOptional(), + + NO_EXTRA_PROPERTIES); + } + + @Override + protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$"); + } + + @Override + public void preprocessEntity(final HsHostingAssetEntity entity) { + super.preprocessEntity(entity); + if (entity.getIdentifier() == null) { + ofNullable(entity.getParentAsset()).ifPresent(pa -> entity.setIdentifier(pa.getIdentifier() + IDENTIFIER_SUFFIX)); + } + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java index 76c5a379..79841ae6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java @@ -317,6 +317,24 @@ public class HsHostingAssetControllerRestTest { "config": {} } ] + """), + DOMAIN_EMAIL_MAILBOX_SETUP( + List.of( + HsHostingAssetEntity.builder() + .type(HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP) + .identifier("example.org|MBOX") + .caption("some fake Domain-MBOX-Setup") + .build()), + """ + [ + { + "type": "DOMAIN_EMAIL_MAILBOX_SETUP", + "identifier": "example.org|MBOX", + "caption": "some fake Domain-MBOX-Setup", + "alarmContact": null, + "config": {} + } + ] """); final HsHostingAssetType assetType; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java new file mode 100644 index 00000000..50d195d9 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java @@ -0,0 +1,133 @@ +package net.hostsharing.hsadminng.hs.hosting.asset.validators; + +import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemEntity; +import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity.HsHostingAssetEntityBuilder; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static java.util.Map.entry; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; +import static org.assertj.core.api.Assertions.assertThat; + +class HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest { + + static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() + .type(DOMAIN_SETUP) + .identifier("example.org") + .build(); + + static HsHostingAssetEntityBuilder validEntityBuilder() { + return HsHostingAssetEntity.builder() + .type(DOMAIN_EMAIL_MAILBOX_SETUP) + .parentAsset(validDomainSetupEntity) + .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .identifier("example.org|MBOX"); + } + + @Test + void containsExpectedProperties() { + // when + final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_EMAIL_MAILBOX_SETUP); + + // then + assertThat(validator.properties()).map(Map::toString).isEmpty(); + } + + @Test + void preprocessesTakesIdentifierFromParent() { + // given + final var givenEntity = validEntityBuilder().build(); + assertThat(givenEntity.getParentAsset().getIdentifier()).as("precondition failed").isEqualTo("example.org"); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + validator.preprocessEntity(givenEntity); + + // then + assertThat(givenEntity.getIdentifier()).isEqualTo("example.org|MBOX"); + } + + @Test + void rejectsInvalidIdentifier() { + // given + final var givenEntity = validEntityBuilder().identifier("example.org").build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + final var result = validator.validateEntity(givenEntity); + + // then + assertThat(result).containsExactly( + "'identifier' expected to match '^example.org\\Q|MBOX\\E$', but is 'example.org'" + ); + } + + @Test + void acceptsValidIdentifier() { + // given + final var givenEntity = validEntityBuilder().identifier(validDomainSetupEntity.getIdentifier()+"|MBOX").build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + final var result = validator.validateEntity(givenEntity); + + // then + assertThat(result).isEmpty(); + } + + @Test + void rejectsInvalidReferencedEntities() { + // given + final var mangedServerHostingAssetEntity = validEntityBuilder() + .bookingItem(HsBookingItemEntity.builder().type(HsBookingItemType.CLOUD_SERVER).build()) + .parentAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) + .assignedToAsset(null) + .build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(mangedServerHostingAssetEntity); + + // then + assertThat(result).containsExactlyInAnyOrder( + "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.bookingItem' must be null but is of type CLOUD_SERVER", + "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.parentAsset' must be of type DOMAIN_SETUP but is of type MANAGED_WEBSPACE", + "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.assignedToAsset' must be of type MANAGED_WEBSPACE but is null"); + } + + @Test + void acceptsValidEntity() { + // given + final var givenEntity = validEntityBuilder().build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(givenEntity.getType()); + + // when + final var errors = validator.validateEntity(givenEntity); + + // then + assertThat(errors).isEmpty(); + } + + @Test + void rejectsInvalidProperties() { + // given + final var mangedServerHostingAssetEntity = validEntityBuilder() + .config(Map.ofEntries( + entry("any", "false") + )) + .build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(mangedServerHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(mangedServerHostingAssetEntity); + + // then + assertThat(result).containsExactlyInAnyOrder( + "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.config.any' is not expected but is set to 'false'"); + } +} -- 2.39.5 From 9c7f35c7de229145d41b155258e6d5697a9c44b2 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Wed, 10 Jul 2024 10:09:39 +0200 Subject: [PATCH 4/8] add HsEMailAddressHostingAssetValidator --- .../HostingAssetEntityValidatorRegistry.java | 1 + .../HsEMailAddressHostingAssetValidator.java | 51 ++++++++ .../HsHostingAssetControllerRestTest.java | 28 +++++ ...ingAssetPropsControllerAcceptanceTest.java | 4 +- ...gAssetEntityValidatorRegistryUnitTest.java | 4 +- ...lAddressHostingAssetValidatorUnitTest.java | 114 ++++++++++++++++++ 6 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java create mode 100644 src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java index 5b287a14..f44be666 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java @@ -25,6 +25,7 @@ public class HostingAssetEntityValidatorRegistry { register(DOMAIN_HTTP_SETUP, new HsDomainHttpSetupHostingAssetValidator()); register(DOMAIN_EMAIL_SUBMISSION_SETUP, new HsDomainEMailSubmissionSetupHostingAssetValidator()); register(DOMAIN_EMAIL_MAILBOX_SETUP, new HsDomainEMailMailboxSetupHostingAssetValidator()); + register(EMAIL_ADDRESS, new HsEMailAddressHostingAssetValidator()); } private static void register(final Enum type, final HsEntityValidator validator) { diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java new file mode 100644 index 00000000..d77451e7 --- /dev/null +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidator.java @@ -0,0 +1,51 @@ +package net.hostsharing.hsadminng.hs.hosting.asset.validators; + +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType; + +import java.util.regex.Pattern; + +import static java.util.Optional.ofNullable; +import static net.hostsharing.hsadminng.hs.validation.ArrayProperty.arrayOf; +import static net.hostsharing.hsadminng.hs.validation.StringProperty.stringProperty; + +class HsEMailAddressHostingAssetValidator extends HostingAssetEntityValidator { + + 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_LOCAL_PART_REGEX = "[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+"; // RFC 5322 + private static final String EMAIL_ADDRESS_DOMAIN_PART_REGEX = "[a-zA-Z0-9.-]+"; + private static final String EMAIL_ADDRESS_FULL_REGEX = "^" + EMAIL_ADDRESS_LOCAL_PART_REGEX + "@" + EMAIL_ADDRESS_DOMAIN_PART_REGEX + "$"; + public static final int EMAIL_ADDRESS_MAX_LENGTH = 320; // according to RFC 5321 and RFC 5322 + + HsEMailAddressHostingAssetValidator() { + super( HsHostingAssetType.EMAIL_ADDRESS, + AlarmContact.isOptional(), + + stringProperty("local-part").matchesRegEx("^" + EMAIL_ADDRESS_LOCAL_PART_REGEX + "$").required(), + stringProperty("sub-domain").matchesRegEx("^" + EMAIL_ADDRESS_LOCAL_PART_REGEX + "$").optional(), + arrayOf( + stringProperty("target").maxLength(EMAIL_ADDRESS_MAX_LENGTH).matchesRegEx(UNIX_USER_REGEX, EMAIL_ADDRESS_FULL_REGEX) + ).required().minLength(1)); + } + + @Override + public void preprocessEntity(final HsHostingAssetEntity entity) { + super.preprocessEntity(entity); + super.preprocessEntity(entity); + if (entity.getIdentifier() == null) { + entity.setIdentifier(combineIdentifier(entity)); + } + } + + @Override + protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { + return Pattern.compile("^"+ Pattern.quote(combineIdentifier(assetEntity)) + "$"); + } + + private static String combineIdentifier(final HsHostingAssetEntity emailAddressAssetEntity) { + return emailAddressAssetEntity.getDirectValue("local-part", String.class) + + ofNullable(emailAddressAssetEntity.getDirectValue("sub-domain", String.class)).map(s -> "." + s).orElse("") + + "@" + + emailAddressAssetEntity.getParentAsset().getIdentifier(); + } +} diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java index 79841ae6..9df023a1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java @@ -335,6 +335,34 @@ public class HsHostingAssetControllerRestTest { "config": {} } ] + """), + EMAIL_ADDRESS( + List.of( + HsHostingAssetEntity.builder() + .type(HsHostingAssetType.EMAIL_ADDRESS) + .parentAsset(HsHostingAssetEntity.builder() + .type(HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP) + .identifier("example.org|MBOX") + .caption("some fake Domain-MBOX-Setup") + .build()) + .identifier("office@example.org") + .caption("some fake EMail-Address") + .config(Map.ofEntries( + entry("target", Array.of("xyz00", "xyz00-abc", "office@example.com")) + )) + .build()), + """ + [ + { + "type": "EMAIL_ADDRESS", + "identifier": "office@example.org", + "caption": "some fake EMail-Address", + "alarmContact": null, + "config": { + "target": ["xyz00","xyz00-abc","office@example.com"] + } + } + ] """); final HsHostingAssetType assetType; diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java index ac011d68..37affab1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java @@ -39,7 +39,9 @@ class HsHostingAssetPropsControllerAcceptanceTest { "DOMAIN_SETUP", "DOMAIN_DNS_SETUP", "DOMAIN_HTTP_SETUP", - "DOMAIN_EMAIL_SUBMISSION_SETUP" + "DOMAIN_EMAIL_SUBMISSION_SETUP", + "DOMAIN_EMAIL_MAILBOX_SETUP", + "EMAIL_ADDRESS" ] """)); // @formatter:on diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java index a041742b..3f6b4917 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java @@ -37,7 +37,9 @@ class HostingAssetEntityValidatorRegistryUnitTest { HsHostingAssetType.DOMAIN_SETUP, HsHostingAssetType.DOMAIN_DNS_SETUP, HsHostingAssetType.DOMAIN_HTTP_SETUP, - HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP + HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP, + HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP, + HsHostingAssetType.EMAIL_ADDRESS ); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java new file mode 100644 index 00000000..878f45e3 --- /dev/null +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java @@ -0,0 +1,114 @@ +package net.hostsharing.hsadminng.hs.hosting.asset.validators; + +import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; +import net.hostsharing.hsadminng.mapper.Array; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static java.util.Map.entry; +import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ADDRESS; +import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; +import static org.assertj.core.api.Assertions.assertThat; + +class HsEMailAddressHostingAssetValidatorUnitTest { + + final static HsHostingAssetEntity domainEmailMailboxSetup = HsHostingAssetEntity.builder() + .type(DOMAIN_EMAIL_MAILBOX_SETUP) + .identifier("example.org") + .build(); + static HsHostingAssetEntity.HsHostingAssetEntityBuilder validEntityBuilder() { + return HsHostingAssetEntity.builder() + .type(EMAIL_ADDRESS) + .parentAsset(domainEmailMailboxSetup) + .identifier("test@example.org") + .config(Map.ofEntries( + entry("local-part", "test"), + entry("target", Array.of("xyz00", "xyz00-abc", "office@example.com")) + )); + } + + @Test + void containsAllValidations() { + // when + final var validator = HostingAssetEntityValidatorRegistry.forType(EMAIL_ADDRESS); + + // then + assertThat(validator.properties()).map(Map::toString).containsExactlyInAnyOrder( + "{type=string, propertyName=local-part, matchesRegEx=[^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+$], required=true}", + "{type=string, propertyName=sub-domain, matchesRegEx=[^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+$]}", + "{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 + void acceptsValidEntity() { + // given + final var emailAddressHostingAssetEntity = validEntityBuilder().build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAddressHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(emailAddressHostingAssetEntity); + + // then + assertThat(result).isEmpty(); + } + + @Test + void rejectsInvalidProperties() { + // given + final var emailAddressHostingAssetEntity = validEntityBuilder() + .config(Map.ofEntries( + entry("local-part", "no@allowed"), + entry("sub-domain", "no@allowedeither"), + entry("target", Array.of("xyz00", "xyz00-abc", "garbage", "office@example.com")))) + .build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAddressHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(emailAddressHostingAssetEntity); + + // then + assertThat(result).containsExactlyInAnyOrder( + "'EMAIL_ADDRESS:test@example.org.config.local-part' is expected to match any of [^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+$] but 'no@allowed' does not match", + "'EMAIL_ADDRESS:test@example.org.config.sub-domain' is expected to match any of [^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+$] but 'no@allowedeither' does not match", + "'EMAIL_ADDRESS:test@example.org.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 + void rejectsInvalidIdentifier() { + // given + final var emailAddressHostingAssetEntity = validEntityBuilder() + .identifier("abc00-office") + .build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAddressHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(emailAddressHostingAssetEntity); + + // then + assertThat(result).containsExactlyInAnyOrder( + "'identifier' expected to match '^\\Qtest@example.org\\E$', but is 'abc00-office'"); + } + + @Test + void validatesInvalidReferences() { + // given + final var emailAddressHostingAssetEntity = validEntityBuilder() + .bookingItem(TEST_MANAGED_SERVER_BOOKING_ITEM) + .parentAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .assignedToAsset(TEST_MANAGED_SERVER_HOSTING_ASSET) + .build(); + final var validator = HostingAssetEntityValidatorRegistry.forType(emailAddressHostingAssetEntity.getType()); + + // when + final var result = validator.validateEntity(emailAddressHostingAssetEntity); + + // then + assertThat(result).containsExactlyInAnyOrder( + "'EMAIL_ADDRESS:test@example.org.bookingItem' must be null but is of type MANAGED_SERVER", + "'EMAIL_ADDRESS:test@example.org.parentAsset' must be of type DOMAIN_EMAIL_MAILBOX_SETUP but is of type MANAGED_SERVER", + "'EMAIL_ADDRESS:test@example.org.assignedToAsset' must be null but is of type MANAGED_SERVER"); + } +} -- 2.39.5 From 197b6c44367f8699e8bc3cda0ae8875adda2ff94 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 11 Jul 2024 09:01:31 +0200 Subject: [PATCH 5/8] add test-data and rename HA_DOMAIN_EMAIL_..._SETUP to SMTP/MBOX --- doc/hs-hosting-asset-type-structure.md | 20 ++++---- ...HsManagedWebspaceBookingItemValidator.java | 4 +- .../hs/hosting/asset/HsHostingAssetType.java | 14 +++--- .../HostingAssetEntityValidatorRegistry.java | 4 +- ...MailMailboxSetupHostingAssetValidator.java | 4 +- ...lSubmissionSetupHostingAssetValidator.java | 4 +- .../hs-hosting/hs-hosting-asset-schemas.yaml | 4 +- .../7010-hs-hosting-asset.sql | 10 ++-- .../7018-hs-hosting-asset-test-data.sql | 49 ++++++++++--------- ...gedServerBookingItemValidatorUnitTest.java | 2 +- .../HsHostingAssetControllerRestTest.java | 14 +++--- ...ingAssetPropsControllerAcceptanceTest.java | 4 +- .../asset/HsHostingAssetTypeUnitTest.java | 16 +++--- ...gAssetEntityValidatorRegistryUnitTest.java | 4 +- ...boxSetupHostingAssetValidatorUnitTest.java | 14 +++--- ...ionSetupHostingAssetValidatorUnitTest.java | 14 +++--- ...lAddressHostingAssetValidatorUnitTest.java | 6 +-- 17 files changed, 97 insertions(+), 90 deletions(-) diff --git a/doc/hs-hosting-asset-type-structure.md b/doc/hs-hosting-asset-type-structure.md index b03b7ced..f2af876b 100644 --- a/doc/hs-hosting-asset-type-structure.md +++ b/doc/hs-hosting-asset-type-structure.md @@ -12,7 +12,7 @@ package Booking #feb28c { entity BI_MANAGED_SERVER entity BI_MANAGED_WEBSPACE entity BI_DOMAIN_DNS_SETUP - entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP + entity BI_DOMAIN_SMTP_SETUP } package Hosting #feb28c{ @@ -20,8 +20,8 @@ package Hosting #feb28c{ entity HA_DOMAIN_SETUP entity HA_DOMAIN_DNS_SETUP entity HA_DOMAIN_HTTP_SETUP - entity HA_DOMAIN_EMAIL_SUBMISSION_SETUP - entity HA_DOMAIN_EMAIL_MAILBOX_SETUP + entity HA_DOMAIN_SMTP_SETUP + entity HA_DOMAIN_MBOX_SETUP entity HA_EMAIL_ADDRESS } @@ -52,12 +52,12 @@ HA_DOMAIN_SETUP o..> HA_DOMAIN_SETUP HA_DOMAIN_DNS_SETUP *==> HA_DOMAIN_SETUP HA_DOMAIN_HTTP_SETUP *==> HA_DOMAIN_SETUP HA_DOMAIN_HTTP_SETUP o..> HA_UNIX_USER -HA_DOMAIN_EMAIL_SUBMISSION_SETUP *==> HA_DOMAIN_SETUP -HA_DOMAIN_EMAIL_SUBMISSION_SETUP o..> HA_MANAGED_WEBSPACE -HA_DOMAIN_EMAIL_MAILBOX_SETUP *==> HA_DOMAIN_SETUP -HA_DOMAIN_EMAIL_MAILBOX_SETUP o..> HA_MANAGED_WEBSPACE +HA_DOMAIN_SMTP_SETUP *==> HA_DOMAIN_SETUP +HA_DOMAIN_SMTP_SETUP o..> HA_MANAGED_WEBSPACE +HA_DOMAIN_MBOX_SETUP *==> HA_DOMAIN_SETUP +HA_DOMAIN_MBOX_SETUP o..> HA_MANAGED_WEBSPACE HA_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE -HA_EMAIL_ADDRESS *==> HA_DOMAIN_EMAIL_MAILBOX_SETUP +HA_EMAIL_ADDRESS *==> HA_DOMAIN_MBOX_SETUP HA_IP_NUMBER o..> HA_CLOUD_SERVER HA_IP_NUMBER o..> HA_MANAGED_SERVER HA_IP_NUMBER o..> HA_MANAGED_WEBSPACE @@ -82,7 +82,7 @@ package Booking #feb28c { entity BI_MANAGED_SERVER entity BI_MANAGED_WEBSPACE entity BI_DOMAIN_DNS_SETUP - entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP + entity BI_DOMAIN_SMTP_SETUP } package Hosting #feb28c{ @@ -145,7 +145,7 @@ package Booking #feb28c { entity BI_MANAGED_SERVER entity BI_MANAGED_WEBSPACE entity BI_DOMAIN_DNS_SETUP - entity BI_DOMAIN_EMAIL_SUBMISSION_SETUP + entity BI_DOMAIN_SMTP_SETUP } package Hosting #feb28c{ diff --git a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedWebspaceBookingItemValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedWebspaceBookingItemValidator.java index 2bca0042..1f094f36 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedWebspaceBookingItemValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedWebspaceBookingItemValidator.java @@ -8,7 +8,7 @@ import java.util.List; import static java.util.Collections.emptyList; import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_MBOX_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ADDRESS; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_DATABASE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MARIADB_USER; @@ -88,7 +88,7 @@ class HsManagedWebspaceBookingItemValidator extends HsBookingItemEntityValidator return (final HsBookingItemEntity entity, final IntegerProperty prop, final Integer factor) -> { final var unixUserCount = ofNullable(entity.getRelatedHostingAsset()) .map(ha -> ha.getSubHostingAssets().stream() - .filter(bi -> bi.getType() == DOMAIN_EMAIL_MAILBOX_SETUP) + .filter(bi -> bi.getType() == DOMAIN_MBOX_SETUP) .flatMap(domainEMailSetup -> domainEMailSetup.getSubHostingAssets().stream() .filter(subAsset -> subAsset.getType()==EMAIL_ADDRESS)) .count()) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java index 6a0846a9..b3d574e1 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java @@ -45,6 +45,10 @@ public enum HsHostingAssetType implements Node { inGroup("Webspace"), requiredParent(MANAGED_WEBSPACE)), + EMAIL_ALIAS( // named e.g. xyz00-abc + inGroup("Webspace"), + requiredParent(MANAGED_WEBSPACE)), + DOMAIN_SETUP( // named e.g. example.org inGroup("Domain"), optionalParent(SAME_TYPE) @@ -59,25 +63,21 @@ public enum HsHostingAssetType implements Node { requiredParent(DOMAIN_SETUP), assignedTo(UNIX_USER)), - DOMAIN_EMAIL_SUBMISSION_SETUP( // named e.g. example.org + DOMAIN_SMTP_SETUP( // named e.g. example.org inGroup("Domain"), requiredParent(DOMAIN_SETUP), assignedTo(MANAGED_WEBSPACE)), - DOMAIN_EMAIL_MAILBOX_SETUP( // named e.g. example.org + DOMAIN_MBOX_SETUP( // named e.g. example.org inGroup("Domain"), requiredParent(DOMAIN_SETUP), assignedTo(MANAGED_WEBSPACE)), // TODO.spec: SECURE_MX - EMAIL_ALIAS( // named e.g. xyz00-abc - inGroup("Webspace"), - requiredParent(MANAGED_WEBSPACE)), - EMAIL_ADDRESS( // named e.g. sample@example.org inGroup("Domain"), - requiredParent(DOMAIN_EMAIL_MAILBOX_SETUP)), + requiredParent(DOMAIN_MBOX_SETUP)), PGSQL_INSTANCE( // TODO.spec: identifier to be specified inGroup("PostgreSQL"), diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java index f44be666..927d0070 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java @@ -23,8 +23,8 @@ public class HostingAssetEntityValidatorRegistry { register(DOMAIN_SETUP, new HsDomainSetupHostingAssetValidator()); register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator()); register(DOMAIN_HTTP_SETUP, new HsDomainHttpSetupHostingAssetValidator()); - register(DOMAIN_EMAIL_SUBMISSION_SETUP, new HsDomainEMailSubmissionSetupHostingAssetValidator()); - register(DOMAIN_EMAIL_MAILBOX_SETUP, new HsDomainEMailMailboxSetupHostingAssetValidator()); + register(DOMAIN_SMTP_SETUP, new HsDomainEMailSubmissionSetupHostingAssetValidator()); + register(DOMAIN_MBOX_SETUP, new HsDomainEMailMailboxSetupHostingAssetValidator()); register(EMAIL_ADDRESS, new HsEMailAddressHostingAssetValidator()); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java index 5e919b00..85291aeb 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java @@ -5,7 +5,7 @@ import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; import java.util.regex.Pattern; import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; class HsDomainEMailMailboxSetupHostingAssetValidator extends HostingAssetEntityValidator { @@ -13,7 +13,7 @@ class HsDomainEMailMailboxSetupHostingAssetValidator extends HostingAssetEntityV HsDomainEMailMailboxSetupHostingAssetValidator() { super( - DOMAIN_EMAIL_SUBMISSION_SETUP, + DOMAIN_SMTP_SETUP, AlarmContact.isOptional(), NO_EXTRA_PROPERTIES); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java index aa80d332..7c1bbecb 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java @@ -5,7 +5,7 @@ import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; import java.util.regex.Pattern; import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; class HsDomainEMailSubmissionSetupHostingAssetValidator extends HostingAssetEntityValidator { @@ -13,7 +13,7 @@ class HsDomainEMailSubmissionSetupHostingAssetValidator extends HostingAssetEnti HsDomainEMailSubmissionSetupHostingAssetValidator() { super( - DOMAIN_EMAIL_SUBMISSION_SETUP, + DOMAIN_SMTP_SETUP, AlarmContact.isOptional(), NO_EXTRA_PROPERTIES); diff --git a/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml b/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml index 11cb1050..f4a25607 100644 --- a/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml +++ b/src/main/resources/api-definition/hs-hosting/hs-hosting-asset-schemas.yaml @@ -13,8 +13,8 @@ components: - DOMAIN_SETUP - DOMAIN_DNS_SETUP - DOMAIN_HTTP_SETUP - - DOMAIN_EMAIL_SUBMISSION_SETUP - - DOMAIN_EMAIL_MAILBOX_SETUP + - DOMAIN_SMTP_SETUP + - DOMAIN_MBOX_SETUP - EMAIL_ALIAS - EMAIL_ADDRESS - PGSQL_USER diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql index eb335238..c1b4bbcc 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7010-hs-hosting-asset.sql @@ -12,7 +12,8 @@ create type HsHostingAssetType as enum ( 'DOMAIN_SETUP', 'DOMAIN_DNS_SETUP', 'DOMAIN_HTTP_SETUP', - 'DOMAIN_EMAIL_SETUP', + 'DOMAIN_SMTP_SETUP', + 'DOMAIN_MBOX_SETUP', 'EMAIL_ALIAS', 'EMAIL_ADDRESS', 'PGSQL_USER', @@ -64,12 +65,13 @@ begin when 'MANAGED_SERVER' then null when 'MANAGED_WEBSPACE' then 'MANAGED_SERVER' when 'UNIX_USER' then 'MANAGED_WEBSPACE' + when 'EMAIL_ALIAS' then 'MANAGED_WEBSPACE' when 'DOMAIN_SETUP' then null when 'DOMAIN_DNS_SETUP' then 'DOMAIN_SETUP' when 'DOMAIN_HTTP_SETUP' then 'DOMAIN_SETUP' - when 'DOMAIN_EMAIL_SETUP' then 'DOMAIN_SETUP' - when 'EMAIL_ALIAS' then 'MANAGED_WEBSPACE' - when 'EMAIL_ADDRESS' then 'DOMAIN_EMAIL_SETUP' + when 'DOMAIN_SMTP_SETUP' then 'DOMAIN_SETUP' + when 'DOMAIN_MBOX_SETUP' then 'DOMAIN_SETUP' + when 'EMAIL_ADDRESS' then 'DOMAIN_MBOX_SETUP' when 'PGSQL_USER' then 'MANAGED_WEBSPACE' when 'PGSQL_DATABASE' then 'MANAGED_WEBSPACE' when 'MARIADB_USER' then 'MANAGED_WEBSPACE' diff --git a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql index 26ef2ac8..f43edef0 100644 --- a/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql +++ b/src/main/resources/db/changelog/7-hs-hosting/701-hosting-asset/7018-hs-hosting-asset-test-data.sql @@ -14,16 +14,17 @@ declare currentTask varchar; relatedProject hs_booking_project; relatedDebitor hs_office_debitor; - relatedPrivateCloudBookingItem hs_booking_item; - relatedManagedServerBookingItem hs_booking_item; - relatedCloudServerBookingItem hs_booking_item; - relatedManagedWebspaceBookingItem hs_booking_item; + privateCloudBI hs_booking_item; + managedServerBI hs_booking_item; + cloudServerBI hs_booking_item; + managedWebspaceBI hs_booking_item; debitorNumberSuffix varchar; defaultPrefix varchar; managedServerUuid uuid; managedWebspaceUuid uuid; webUnixUserUuid uuid; domainSetupUuid uuid; + domainMBoxSetupUuid uuid; begin currentTask := 'creating hosting-asset test-data ' || givenProjectCaption; call defineContext(currentTask, null, 'superuser-alex@hostsharing.net', 'global#global:ADMIN'); @@ -39,47 +40,51 @@ begin where debitor.uuid = relatedProject.debitorUuid; assert relatedDebitor.uuid is not null, 'relatedDebitor for "' || givenProjectCaption || '" must not be null'; - select item.* into relatedPrivateCloudBookingItem + select item.* into privateCloudBI from hs_booking_item item where item.projectUuid = relatedProject.uuid and item.type = 'PRIVATE_CLOUD'; - assert relatedPrivateCloudBookingItem.uuid is not null, 'relatedPrivateCloudBookingItem for "' || givenProjectCaption|| '" must not be null'; + assert privateCloudBI.uuid is not null, 'relatedPrivateCloudBookingItem for "' || givenProjectCaption|| '" must not be null'; - select item.* into relatedManagedServerBookingItem + select item.* into managedServerBI from hs_booking_item item where item.projectUuid = relatedProject.uuid and item.type = 'MANAGED_SERVER'; - assert relatedManagedServerBookingItem.uuid is not null, 'relatedManagedServerBookingItem for "' || givenProjectCaption|| '" must not be null'; + assert managedServerBI.uuid is not null, 'relatedManagedServerBookingItem for "' || givenProjectCaption|| '" must not be null'; - select item.* into relatedCloudServerBookingItem + select item.* into cloudServerBI from hs_booking_item item - where item.parentItemuuid = relatedPrivateCloudBookingItem.uuid + where item.parentItemuuid = privateCloudBI.uuid and item.type = 'CLOUD_SERVER'; - assert relatedCloudServerBookingItem.uuid is not null, 'relatedCloudServerBookingItem for "' || givenProjectCaption|| '" must not be null'; + assert cloudServerBI.uuid is not null, 'relatedCloudServerBookingItem for "' || givenProjectCaption|| '" must not be null'; - select item.* into relatedManagedWebspaceBookingItem + select item.* into managedWebspaceBI from hs_booking_item item where item.projectUuid = relatedProject.uuid and item.type = 'MANAGED_WEBSPACE'; - assert relatedManagedWebspaceBookingItem.uuid is not null, 'relatedManagedWebspaceBookingItem for "' || givenProjectCaption|| '" must not be null'; + assert managedWebspaceBI.uuid is not null, 'relatedManagedWebspaceBookingItem for "' || givenProjectCaption|| '" must not be null'; select uuid_generate_v4() into managedServerUuid; select uuid_generate_v4() into managedWebspaceUuid; select uuid_generate_v4() into webUnixUserUuid; select uuid_generate_v4() into domainSetupUuid; + select uuid_generate_v4() into domainMBoxSetupUuid; debitorNumberSuffix := relatedDebitor.debitorNumberSuffix; defaultPrefix := relatedDebitor.defaultPrefix; insert into hs_hosting_asset - (uuid, bookingitemuuid, type, parentAssetUuid, assignedToAssetUuid, identifier, caption, config) - values (managedServerUuid, relatedManagedServerBookingItem.uuid, 'MANAGED_SERVER', null, null, 'vm10' || debitorNumberSuffix, 'some ManagedServer', '{ "monit_max_cpu_usage": 90, "monit_max_ram_usage": 80, "monit_max_ssd_usage": 70 }'::jsonb), - (uuid_generate_v4(), relatedCloudServerBookingItem.uuid, 'CLOUD_SERVER', null, null, 'vm20' || debitorNumberSuffix, 'another CloudServer', '{}'::jsonb), - (managedWebspaceUuid, relatedManagedWebspaceBookingItem.uuid, 'MANAGED_WEBSPACE', managedServerUuid, null, defaultPrefix || '01', 'some Webspace', '{}'::jsonb), - (uuid_generate_v4(), null, 'EMAIL_ALIAS', managedWebspaceUuid, null, defaultPrefix || '01-web', 'some E-Mail-Alias', '{ "target": [ "office@example.org", "archive@example.com" ] }'::jsonb), - (webUnixUserUuid, null, 'UNIX_USER', managedWebspaceUuid, null, defaultPrefix || '01-web', 'some UnixUser for Website', '{ "SSD-soft-quota": "128", "SSD-hard-quota": "256", "HDD-soft-quota": "512", "HDD-hard-quota": "1024"}'::jsonb), - (domainSetupUuid, null, 'DOMAIN_SETUP', null, null, defaultPrefix || '.example.org', 'some Domain-Setup', '{}'::jsonb), - (uuid_generate_v4(), null, 'DOMAIN_DNS_SETUP', domainSetupUuid, null, defaultPrefix || '.example.org|DNS', 'some Domain-DNS-Setup', '{}'::jsonb), - (uuid_generate_v4(), null, 'DOMAIN_HTTP_SETUP', domainSetupUuid, webUnixUserUuid, defaultPrefix || '.example.org|HTTP', 'some Domain-HTTP-Setup', '{ "option-htdocsfallback": true, "use-fcgiphpbin": "/usr/lib/cgi-bin/php", "validsubdomainnames": "*"}'::jsonb); + (uuid, bookingitemuuid, type, parentAssetUuid, assignedToAssetUuid, identifier, caption, config) + values (managedServerUuid, managedServerBI.uuid, 'MANAGED_SERVER', null, null, 'vm10' || debitorNumberSuffix, 'some ManagedServer', '{ "monit_max_cpu_usage": 90, "monit_max_ram_usage": 80, "monit_max_ssd_usage": 70 }'::jsonb), + (uuid_generate_v4(), cloudServerBI.uuid, 'CLOUD_SERVER', null, null, 'vm20' || debitorNumberSuffix, 'another CloudServer', '{}'::jsonb), + (managedWebspaceUuid, managedWebspaceBI.uuid, 'MANAGED_WEBSPACE', managedServerUuid, null, defaultPrefix || '01', 'some Webspace', '{}'::jsonb), + (uuid_generate_v4(), null, 'EMAIL_ALIAS', managedWebspaceUuid, null, defaultPrefix || '01-web', 'some E-Mail-Alias', '{ "target": [ "office@example.org", "archive@example.com" ] }'::jsonb), + (webUnixUserUuid, null, 'UNIX_USER', managedWebspaceUuid, null, defaultPrefix || '01-web', 'some UnixUser for Website', '{ "SSD-soft-quota": "128", "SSD-hard-quota": "256", "HDD-soft-quota": "512", "HDD-hard-quota": "1024"}'::jsonb), + (domainSetupUuid, null, 'DOMAIN_SETUP', null, null, defaultPrefix || '.example.org', 'some Domain-Setup', '{}'::jsonb), + (uuid_generate_v4(), null, 'DOMAIN_DNS_SETUP', domainSetupUuid, null, defaultPrefix || '.example.org|DNS', 'some Domain-DNS-Setup', '{}'::jsonb), + (uuid_generate_v4(), null, 'DOMAIN_HTTP_SETUP', domainSetupUuid, webUnixUserUuid, defaultPrefix || '.example.org|HTTP', 'some Domain-HTTP-Setup', '{ "option-htdocsfallback": true, "use-fcgiphpbin": "/usr/lib/cgi-bin/php", "validsubdomainnames": "*"}'::jsonb), + (uuid_generate_v4(), null, 'DOMAIN_SMTP_SETUP', domainSetupUuid, managedWebspaceUuid, defaultPrefix || '.example.org|DNS', 'some Domain-SMPT-Setup', '{}'::jsonb), + (domainMBoxSetupUuid, null, 'DOMAIN_MBOX_SETUP', domainSetupUuid, managedWebspaceUuid, defaultPrefix || '.example.org|DNS', 'some Domain-MBOX-Setup', '{}'::jsonb), + (uuid_generate_v4(), null, 'EMAIL_ADDRESS', domainMBoxSetupUuid, null, 'test@' || defaultPrefix || '.example.org', 'some E-Mail-Address', '{}'::jsonb); end; $$; --// diff --git a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java index b0605239..5f95e598 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/booking/item/validators/HsManagedServerBookingItemValidatorUnitTest.java @@ -152,7 +152,7 @@ class HsManagedServerBookingItemValidatorUnitTest { "xyz00_%c%c", 2, HsHostingAssetType.MARIADB_DATABASE ), - generateDomainEmailSetupsWithEMailAddresses(26, HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP, + generateDomainEmailSetupsWithEMailAddresses(26, HsHostingAssetType.DOMAIN_MBOX_SETUP, "%c%c.example.com", 10, HsHostingAssetType.EMAIL_ADDRESS ) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java index 9df023a1..4a5bc04c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetControllerRestTest.java @@ -300,17 +300,17 @@ public class HsHostingAssetControllerRestTest { } ] """), - DOMAIN_EMAIL_SUBMISSION_SETUP( + DOMAIN_SMTP_SETUP( List.of( HsHostingAssetEntity.builder() - .type(HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP) + .type(HsHostingAssetType.DOMAIN_SMTP_SETUP) .identifier("example.org|SMTP") .caption("some fake Domain-SMTP-Setup") .build()), """ [ { - "type": "DOMAIN_EMAIL_SUBMISSION_SETUP", + "type": "DOMAIN_SMTP_SETUP", "identifier": "example.org|SMTP", "caption": "some fake Domain-SMTP-Setup", "alarmContact": null, @@ -318,17 +318,17 @@ public class HsHostingAssetControllerRestTest { } ] """), - DOMAIN_EMAIL_MAILBOX_SETUP( + DOMAIN_MBOX_SETUP( List.of( HsHostingAssetEntity.builder() - .type(HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP) + .type(HsHostingAssetType.DOMAIN_MBOX_SETUP) .identifier("example.org|MBOX") .caption("some fake Domain-MBOX-Setup") .build()), """ [ { - "type": "DOMAIN_EMAIL_MAILBOX_SETUP", + "type": "DOMAIN_MBOX_SETUP", "identifier": "example.org|MBOX", "caption": "some fake Domain-MBOX-Setup", "alarmContact": null, @@ -341,7 +341,7 @@ public class HsHostingAssetControllerRestTest { HsHostingAssetEntity.builder() .type(HsHostingAssetType.EMAIL_ADDRESS) .parentAsset(HsHostingAssetEntity.builder() - .type(HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP) + .type(HsHostingAssetType.DOMAIN_MBOX_SETUP) .identifier("example.org|MBOX") .caption("some fake Domain-MBOX-Setup") .build()) diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java index 37affab1..290777ea 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetPropsControllerAcceptanceTest.java @@ -39,8 +39,8 @@ class HsHostingAssetPropsControllerAcceptanceTest { "DOMAIN_SETUP", "DOMAIN_DNS_SETUP", "DOMAIN_HTTP_SETUP", - "DOMAIN_EMAIL_SUBMISSION_SETUP", - "DOMAIN_EMAIL_MAILBOX_SETUP", + "DOMAIN_SMTP_SETUP", + "DOMAIN_MBOX_SETUP", "EMAIL_ADDRESS" ] """)); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java index 91d141a2..24eea31d 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java @@ -32,8 +32,8 @@ class HsHostingAssetTypeUnitTest { entity HA_DOMAIN_SETUP entity HA_DOMAIN_DNS_SETUP entity HA_DOMAIN_HTTP_SETUP - entity HA_DOMAIN_EMAIL_SUBMISSION_SETUP - entity HA_DOMAIN_EMAIL_MAILBOX_SETUP + entity HA_DOMAIN_SMTP_SETUP + entity HA_DOMAIN_MBOX_SETUP entity HA_EMAIL_ADDRESS } @@ -60,16 +60,16 @@ class HsHostingAssetTypeUnitTest { HA_MANAGED_WEBSPACE *==> BI_MANAGED_WEBSPACE HA_MANAGED_WEBSPACE o..> HA_MANAGED_SERVER HA_UNIX_USER *==> HA_MANAGED_WEBSPACE + HA_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE HA_DOMAIN_SETUP o..> HA_DOMAIN_SETUP HA_DOMAIN_DNS_SETUP *==> HA_DOMAIN_SETUP HA_DOMAIN_HTTP_SETUP *==> HA_DOMAIN_SETUP HA_DOMAIN_HTTP_SETUP o..> HA_UNIX_USER - HA_DOMAIN_EMAIL_SUBMISSION_SETUP *==> HA_DOMAIN_SETUP - HA_DOMAIN_EMAIL_SUBMISSION_SETUP o..> HA_MANAGED_WEBSPACE - HA_DOMAIN_EMAIL_MAILBOX_SETUP *==> HA_DOMAIN_SETUP - HA_DOMAIN_EMAIL_MAILBOX_SETUP o..> HA_MANAGED_WEBSPACE - HA_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE - HA_EMAIL_ADDRESS *==> HA_DOMAIN_EMAIL_MAILBOX_SETUP + HA_DOMAIN_SMTP_SETUP *==> HA_DOMAIN_SETUP + HA_DOMAIN_SMTP_SETUP o..> HA_MANAGED_WEBSPACE + HA_DOMAIN_MBOX_SETUP *==> HA_DOMAIN_SETUP + HA_DOMAIN_MBOX_SETUP o..> HA_MANAGED_WEBSPACE + HA_EMAIL_ADDRESS *==> HA_DOMAIN_MBOX_SETUP HA_IP_NUMBER o..> HA_CLOUD_SERVER HA_IP_NUMBER o..> HA_MANAGED_SERVER HA_IP_NUMBER o..> HA_MANAGED_WEBSPACE diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java index 3f6b4917..c1c8a53c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistryUnitTest.java @@ -37,8 +37,8 @@ class HostingAssetEntityValidatorRegistryUnitTest { HsHostingAssetType.DOMAIN_SETUP, HsHostingAssetType.DOMAIN_DNS_SETUP, HsHostingAssetType.DOMAIN_HTTP_SETUP, - HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP, - HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP, + HsHostingAssetType.DOMAIN_SMTP_SETUP, + HsHostingAssetType.DOMAIN_MBOX_SETUP, HsHostingAssetType.EMAIL_ADDRESS ); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java index 50d195d9..6bbb2cfb 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test; import java.util.Map; import static java.util.Map.entry; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_MBOX_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static org.assertj.core.api.Assertions.assertThat; @@ -23,7 +23,7 @@ class HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest { static HsHostingAssetEntityBuilder validEntityBuilder() { return HsHostingAssetEntity.builder() - .type(DOMAIN_EMAIL_MAILBOX_SETUP) + .type(DOMAIN_MBOX_SETUP) .parentAsset(validDomainSetupEntity) .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) .identifier("example.org|MBOX"); @@ -32,7 +32,7 @@ class HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest { @Test void containsExpectedProperties() { // when - final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_EMAIL_MAILBOX_SETUP); + final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_MBOX_SETUP); // then assertThat(validator.properties()).map(Map::toString).isEmpty(); @@ -95,9 +95,9 @@ class HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.bookingItem' must be null but is of type CLOUD_SERVER", - "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.parentAsset' must be of type DOMAIN_SETUP but is of type MANAGED_WEBSPACE", - "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.assignedToAsset' must be of type MANAGED_WEBSPACE but is null"); + "'DOMAIN_MBOX_SETUP:example.org|MBOX.bookingItem' must be null but is of type CLOUD_SERVER", + "'DOMAIN_MBOX_SETUP:example.org|MBOX.parentAsset' must be of type DOMAIN_SETUP but is of type MANAGED_WEBSPACE", + "'DOMAIN_MBOX_SETUP:example.org|MBOX.assignedToAsset' must be of type MANAGED_WEBSPACE but is null"); } @Test @@ -128,6 +128,6 @@ class HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'DOMAIN_EMAIL_MAILBOX_SETUP:example.org|MBOX.config.any' is not expected but is set to 'false'"); + "'DOMAIN_MBOX_SETUP:example.org|MBOX.config.any' is not expected but is set to 'false'"); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java index 57c847fc..db87f8e6 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java @@ -9,7 +9,7 @@ import org.junit.jupiter.api.Test; import java.util.Map; import static java.util.Map.entry; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_SUBMISSION_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static org.assertj.core.api.Assertions.assertThat; @@ -23,7 +23,7 @@ class HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest { static HsHostingAssetEntityBuilder validEntityBuilder() { return HsHostingAssetEntity.builder() - .type(DOMAIN_EMAIL_SUBMISSION_SETUP) + .type(DOMAIN_SMTP_SETUP) .parentAsset(validDomainSetupEntity) .assignedToAsset(HsHostingAssetEntity.builder().type(MANAGED_WEBSPACE).build()) .identifier("example.org|SMTP"); @@ -32,7 +32,7 @@ class HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest { @Test void containsExpectedProperties() { // when - final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_EMAIL_SUBMISSION_SETUP); + final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_SMTP_SETUP); // then assertThat(validator.properties()).map(Map::toString).isEmpty(); @@ -95,9 +95,9 @@ class HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.bookingItem' must be null but is of type CLOUD_SERVER", - "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.parentAsset' must be of type DOMAIN_SETUP but is of type MANAGED_WEBSPACE", - "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.assignedToAsset' must be of type MANAGED_WEBSPACE but is null"); + "'DOMAIN_SMTP_SETUP:example.org|SMTP.bookingItem' must be null but is of type CLOUD_SERVER", + "'DOMAIN_SMTP_SETUP:example.org|SMTP.parentAsset' must be of type DOMAIN_SETUP but is of type MANAGED_WEBSPACE", + "'DOMAIN_SMTP_SETUP:example.org|SMTP.assignedToAsset' must be of type MANAGED_WEBSPACE but is null"); } @Test @@ -128,6 +128,6 @@ class HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( - "'DOMAIN_EMAIL_SUBMISSION_SETUP:example.org|SMTP.config.any' is not expected but is set to 'false'"); + "'DOMAIN_SMTP_SETUP:example.org|SMTP.config.any' is not expected but is set to 'false'"); } } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java index 878f45e3..1dacb1e2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsEMailAddressHostingAssetValidatorUnitTest.java @@ -8,7 +8,7 @@ import java.util.Map; import static java.util.Map.entry; import static net.hostsharing.hsadminng.hs.booking.item.TestHsBookingItem.TEST_MANAGED_SERVER_BOOKING_ITEM; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_EMAIL_MAILBOX_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_MBOX_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.EMAIL_ADDRESS; import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_SERVER_HOSTING_ASSET; import static org.assertj.core.api.Assertions.assertThat; @@ -16,7 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat; class HsEMailAddressHostingAssetValidatorUnitTest { final static HsHostingAssetEntity domainEmailMailboxSetup = HsHostingAssetEntity.builder() - .type(DOMAIN_EMAIL_MAILBOX_SETUP) + .type(DOMAIN_MBOX_SETUP) .identifier("example.org") .build(); static HsHostingAssetEntity.HsHostingAssetEntityBuilder validEntityBuilder() { @@ -108,7 +108,7 @@ class HsEMailAddressHostingAssetValidatorUnitTest { // then assertThat(result).containsExactlyInAnyOrder( "'EMAIL_ADDRESS:test@example.org.bookingItem' must be null but is of type MANAGED_SERVER", - "'EMAIL_ADDRESS:test@example.org.parentAsset' must be of type DOMAIN_EMAIL_MAILBOX_SETUP but is of type MANAGED_SERVER", + "'EMAIL_ADDRESS:test@example.org.parentAsset' must be of type DOMAIN_MBOX_SETUP but is of type MANAGED_SERVER", "'EMAIL_ADDRESS:test@example.org.assignedToAsset' must be null but is of type MANAGED_SERVER"); } } -- 2.39.5 From c03b43f806221923d9a2e1dc26bf63a4a7d80fa7 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 11 Jul 2024 09:23:03 +0200 Subject: [PATCH 6/8] cleanup --- .../asset/validators/HsDomainSetupHostingAssetValidator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java index 483472a7..17031c5e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSetupHostingAssetValidator.java @@ -43,7 +43,6 @@ class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator { // - user has Admin/Agent-role for all its sub-domains and the direct parent-Domain which are set up at at Hostsharing // - domain has DNS zone with TXT record approval // - parent-domain has DNS zone with TXT record approval - // - dom // // TXT-Record check: // new InitialDirContext().getAttributes("dns:_netblocks.google.com", new String[] { "TXT"}).get("TXT").getAll(); -- 2.39.5 From c58bc7a82af893befc86d98baa64cf12ec207d9a Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 11 Jul 2024 10:09:10 +0200 Subject: [PATCH 7/8] require DOMAIN_DNS_SETU.assignedTo(MANAGED_WEBSPACE) --- .../hsadminng/hs/hosting/asset/HsHostingAssetType.java | 3 ++- .../hs/hosting/asset/HsHostingAssetTypeUnitTest.java | 1 + .../HsDomainDnsSetupHostingAssetValidatorUnitTest.java | 10 ++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java index b3d574e1..0054974b 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetType.java @@ -56,7 +56,8 @@ public enum HsHostingAssetType implements Node { DOMAIN_DNS_SETUP( // named e.g. example.org inGroup("Domain"), - requiredParent(DOMAIN_SETUP)), + requiredParent(DOMAIN_SETUP), + assignedTo(MANAGED_WEBSPACE)), DOMAIN_HTTP_SETUP( // named e.g. example.org inGroup("Domain"), diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java index 24eea31d..870e2f8f 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/HsHostingAssetTypeUnitTest.java @@ -63,6 +63,7 @@ class HsHostingAssetTypeUnitTest { HA_EMAIL_ALIAS *==> HA_MANAGED_WEBSPACE HA_DOMAIN_SETUP o..> HA_DOMAIN_SETUP HA_DOMAIN_DNS_SETUP *==> HA_DOMAIN_SETUP + HA_DOMAIN_DNS_SETUP o..> HA_MANAGED_WEBSPACE HA_DOMAIN_HTTP_SETUP *==> HA_DOMAIN_SETUP HA_DOMAIN_HTTP_SETUP o..> HA_UNIX_USER HA_DOMAIN_SMTP_SETUP *==> HA_DOMAIN_SETUP diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java index 715138ec..22ed60a1 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java @@ -12,6 +12,7 @@ import java.util.Map; import static java.util.Map.entry; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_DNS_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.TestHsHostingAssetEntities.TEST_MANAGED_WEBSPACE_HOSTING_ASSET; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_COMMENT; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_DATA; import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_TYPE; @@ -23,14 +24,15 @@ import static org.assertj.core.api.Assertions.assertThat; class HsDomainDnsSetupHostingAssetValidatorUnitTest { static final HsHostingAssetEntity validDomainSetupEntity = HsHostingAssetEntity.builder() - .type(DOMAIN_SETUP) - .identifier("example.org") - .build(); + .type(DOMAIN_SETUP) + .identifier("example.org") + .build(); static HsHostingAssetEntityBuilder validEntityBuilder() { return HsHostingAssetEntity.builder() .type(DOMAIN_DNS_SETUP) .parentAsset(validDomainSetupEntity) + .assignedToAsset(TEST_MANAGED_WEBSPACE_HOSTING_ASSET) .identifier("example.org|DNS") .config(Map.ofEntries( entry("user-RR", Array.of( @@ -129,7 +131,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { assertThat(result).containsExactlyInAnyOrder( "'DOMAIN_DNS_SETUP:example.org|DNS.bookingItem' must be null but is of type CLOUD_SERVER", "'DOMAIN_DNS_SETUP:example.org|DNS.parentAsset' must be of type DOMAIN_SETUP but is null", - "'DOMAIN_DNS_SETUP:example.org|DNS.assignedToAsset' must be null but is of type DOMAIN_SETUP"); + "'DOMAIN_DNS_SETUP:example.org|DNS.assignedToAsset' must be of type MANAGED_WEBSPACE but is of type DOMAIN_SETUP"); } @Test -- 2.39.5 From c85c05c40cbbebcdbe99022c8ce95ef144c2f743 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Thu, 11 Jul 2024 10:41:21 +0200 Subject: [PATCH 8/8] amendmends after code-review --- .../HostingAssetEntityValidatorRegistry.java | 4 +-- ...HsDomainDnsSetupHostingAssetValidator.java | 2 +- ...sDomainHttpSetupHostingAssetValidator.java | 2 +- ...DomainMboxSetupHostingAssetValidator.java} | 10 +++--- ...DomainSmtpSetupHostingAssetValidator.java} | 6 ++-- ...DnsSetupHostingAssetValidatorUnitTest.java | 2 +- ...ttpSetupHostingAssetValidatorUnitTest.java | 36 +------------------ ...ainMboxHostingAssetValidatorUnitTest.java} | 4 +-- ...tpSetupHostingAssetValidatorUnitTest.java} | 4 +-- ...lAddressHostingAssetValidatorUnitTest.java | 4 +-- 10 files changed, 20 insertions(+), 54 deletions(-) rename src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsDomainEMailMailboxSetupHostingAssetValidator.java => HsDomainMboxSetupHostingAssetValidator.java} (71%) rename src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsDomainEMailSubmissionSetupHostingAssetValidator.java => HsDomainSmtpSetupHostingAssetValidator.java} (76%) rename src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsDomainEmailMailboxSetupHostingAssetValidatorUnitTest.java => HsDomainMboxHostingAssetValidatorUnitTest.java} (97%) rename src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/{HsDomainEmailSubmissionSetupHostingAssetValidatorUnitTest.java => HsDomainSmtpSetupHostingAssetValidatorUnitTest.java} (97%) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java index 927d0070..c44bf92a 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HostingAssetEntityValidatorRegistry.java @@ -23,8 +23,8 @@ public class HostingAssetEntityValidatorRegistry { register(DOMAIN_SETUP, new HsDomainSetupHostingAssetValidator()); register(DOMAIN_DNS_SETUP, new HsDomainDnsSetupHostingAssetValidator()); register(DOMAIN_HTTP_SETUP, new HsDomainHttpSetupHostingAssetValidator()); - register(DOMAIN_SMTP_SETUP, new HsDomainEMailSubmissionSetupHostingAssetValidator()); - register(DOMAIN_MBOX_SETUP, new HsDomainEMailMailboxSetupHostingAssetValidator()); + register(DOMAIN_SMTP_SETUP, new HsDomainSmtpSetupHostingAssetValidator()); + register(DOMAIN_MBOX_SETUP, new HsDomainMboxSetupHostingAssetValidator()); register(EMAIL_ADDRESS, new HsEMailAddressHostingAssetValidator()); } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java index 06e8b72a..97c44ce2 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidator.java @@ -60,7 +60,7 @@ class HsDomainDnsSetupHostingAssetValidator extends HostingAssetEntityValidator @Override protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { - return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$"); + return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java index 9065f7d9..32a2cb30 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidator.java @@ -43,7 +43,7 @@ class HsDomainHttpSetupHostingAssetValidator extends HostingAssetEntityValidator @Override protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { - return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$"); + return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxSetupHostingAssetValidator.java similarity index 71% rename from src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java rename to src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxSetupHostingAssetValidator.java index 85291aeb..0172fda4 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailMailboxSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainMboxSetupHostingAssetValidator.java @@ -5,15 +5,15 @@ import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetEntity; import java.util.regex.Pattern; import static java.util.Optional.ofNullable; -import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; +import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_MBOX_SETUP; -class HsDomainEMailMailboxSetupHostingAssetValidator extends HostingAssetEntityValidator { +class HsDomainMboxSetupHostingAssetValidator extends HostingAssetEntityValidator { public static final String IDENTIFIER_SUFFIX = "|MBOX"; - HsDomainEMailMailboxSetupHostingAssetValidator() { + HsDomainMboxSetupHostingAssetValidator() { super( - DOMAIN_SMTP_SETUP, + DOMAIN_MBOX_SETUP, AlarmContact.isOptional(), NO_EXTRA_PROPERTIES); @@ -21,7 +21,7 @@ class HsDomainEMailMailboxSetupHostingAssetValidator extends HostingAssetEntityV @Override protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { - return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$"); + return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override diff --git a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidator.java similarity index 76% rename from src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java rename to src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidator.java index 7c1bbecb..e92eba10 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainEMailSubmissionSetupHostingAssetValidator.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainSmtpSetupHostingAssetValidator.java @@ -7,11 +7,11 @@ import java.util.regex.Pattern; import static java.util.Optional.ofNullable; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SMTP_SETUP; -class HsDomainEMailSubmissionSetupHostingAssetValidator extends HostingAssetEntityValidator { +class HsDomainSmtpSetupHostingAssetValidator extends HostingAssetEntityValidator { public static final String IDENTIFIER_SUFFIX = "|SMTP"; - HsDomainEMailSubmissionSetupHostingAssetValidator() { + HsDomainSmtpSetupHostingAssetValidator() { super( DOMAIN_SMTP_SETUP, AlarmContact.isOptional(), @@ -21,7 +21,7 @@ class HsDomainEMailSubmissionSetupHostingAssetValidator extends HostingAssetEnti @Override protected Pattern identifierPattern(final HsHostingAssetEntity assetEntity) { - return Pattern.compile("^" + assetEntity.getParentAsset().getIdentifier() + Pattern.quote(IDENTIFIER_SUFFIX) + "$"); + return Pattern.compile("^" + Pattern.quote(assetEntity.getParentAsset().getIdentifier() + IDENTIFIER_SUFFIX) + "$"); } @Override diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java index 22ed60a1..7f66379c 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainDnsSetupHostingAssetValidatorUnitTest.java @@ -97,7 +97,7 @@ class HsDomainDnsSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactly( - "'identifier' expected to match '^example.org\\Q|DNS\\E$', but is 'example.org'" + "'identifier' expected to match '^\\Qexample.org|DNS\\E$', but is 'example.org'" ); } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java index fa75cded..29b4c05b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/hosting/asset/validators/HsDomainHttpSetupHostingAssetValidatorUnitTest.java @@ -14,12 +14,6 @@ import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMA import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.DOMAIN_SETUP; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.MANAGED_WEBSPACE; import static net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetType.UNIX_USER; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_COMMENT; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_DATA; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_RECORD_TYPE; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_IN; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_NAME; -import static net.hostsharing.hsadminng.hs.hosting.asset.validators.HsDomainDnsSetupHostingAssetValidator.RR_REGEX_TTL; import static org.assertj.core.api.Assertions.assertThat; class HsDomainHttpSetupHostingAssetValidatorUnitTest { @@ -93,7 +87,7 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest { // then assertThat(result).containsExactly( - "'identifier' expected to match '^example.org\\Q|HTTP\\E$', but is 'example.org'" + "'identifier' expected to match '^\\Qexample.org|HTTP\\E$', but is 'example.org'" ); } @@ -166,32 +160,4 @@ class HsDomainHttpSetupHostingAssetValidatorUnitTest { "'DOMAIN_HTTP_SETUP:example.org|HTTP.config.subdomains' is expected to match any of [(?!-)[A-Za-z0-9-]{1,63}(?