user-definable verificationCode and more business-level-validation-tests #100
@ -3,6 +3,7 @@ package net.hostsharing.hsadminng.hs.hosting.asset.validators;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.HsBookingItemType;
|
||||
import net.hostsharing.hsadminng.hs.booking.item.validators.HsBookingItemEntityValidatorRegistry;
|
||||
import net.hostsharing.hsadminng.hs.booking.project.HsBookingProjectRealEntity;
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRbacEntity;
|
||||
import net.hostsharing.hsadminng.hs.hosting.asset.HsHostingAssetRealEntity;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@ -35,8 +36,10 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
static HsHostingAssetRbacEntity.HsHostingAssetRbacEntityBuilder<?, ?> validEntityBuilder(
|
||||
final String domainName,
|
||||
final Function<HsBookingItemRealEntity.HsBookingItemRealEntityBuilder<?, ?>, HsBookingItemRealEntity> buildBookingItem) {
|
||||
final HsBookingItemRealEntity bookingItem = buildBookingItem.apply(
|
||||
final var project = HsBookingProjectRealEntity.builder().build();
|
||||
final var bookingItem = buildBookingItem.apply(
|
||||
HsBookingItemRealEntity.builder()
|
||||
.project(project)
|
||||
.type(HsBookingItemType.DOMAIN_SETUP)
|
||||
.resources(new HashMap<>(ofEntries(
|
||||
entry("domainName", domainName)
|
||||
@ -90,7 +93,8 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
// then
|
||||
assertThat(result).contains(
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.org', but is '" + testCase.domainName + "'"
|
||||
"'identifier' expected to match '(\\*|(?!-)[A-Za-z0-9-]{1,63}(?<!-))\\.example\\.org', but is '"
|
||||
+ testCase.domainName + "'"
|
||||
);
|
||||
}
|
||||
|
||||
@ -141,7 +145,8 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
@Test
|
||||
void validatesReferencedEntities() {
|
||||
// given
|
||||
final var domainSetupHostingAssetEntity = validEntityBuilder("example.org",
|
||||
final var domainSetupHostingAssetEntity = validEntityBuilder(
|
||||
"example.org",
|
||||
bib -> bib.type(HsBookingItemType.CLOUD_SERVER).build())
|
||||
.parentAsset(HsHostingAssetRealEntity.builder().type(CLOUD_SERVER).build())
|
||||
.assignedToAsset(HsHostingAssetRealEntity.builder().type(MANAGED_SERVER).build())
|
||||
@ -161,7 +166,8 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
@Test
|
||||
void rejectsDomainNameNotMatchingBookingItemDomainName() {
|
||||
// given
|
||||
final var domainSetupHostingAssetEntity = validEntityBuilder("not-matching-booking-item-domain-name.org",
|
||||
final var domainSetupHostingAssetEntity = validEntityBuilder(
|
||||
"not-matching-booking-item-domain-name.org",
|
||||
bib -> bib.resources(new HashMap<>(ofEntries(
|
||||
entry("domainName", "example.org")
|
||||
))).build()
|
||||
@ -262,6 +268,24 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
//=====================================================================================================================
|
||||
|
||||
@Test
|
||||
void rejectsSetupOfRegistrar1stLevelDomain() {
|
||||
domainSetupFor("org").notRegistered()
|
||||
.isRejectedWithCauseForbidden("registrar-level domain name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsSetupOfRegistrar2ndLevelDomain() {
|
||||
domainSetupFor("co.uk").notRegistered()
|
||||
.isRejectedWithCauseForbidden("registrar-level domain name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsSetupOfHostsharingDmain() {
|
||||
domainSetupFor("hostsharing.net").notRegistered()
|
||||
.isRejectedWithCauseForbidden("Hostsharing domain name");
|
||||
}
|
||||
|
||||
@Test
|
||||
void allowSetupOfAvailableRegistrableDomain() {
|
||||
domainSetupFor("example.com").notRegistered()
|
||||
@ -416,13 +440,27 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
+ "' found for domain name '" + domainName + "'");
|
||||
}
|
||||
|
||||
void isRejectedWithCauseForbidden(final String type) {
|
||||
assertThat(validate()).contains(
|
||||
"'D-???????:null:null.resources.domainName' = '" + domainAsset.getIdentifier() + "' is a forbidden " + type
|
||||
);
|
||||
}
|
||||
|
||||
void isAccepted() {
|
||||
assertThat(validate()).isEmpty();
|
||||
}
|
||||
|
||||
private List<String> validate() {
|
||||
final var validator = HostingAssetEntityValidatorRegistry.forType(DOMAIN_SETUP);
|
||||
return validator.validateEntity(domainAsset);
|
||||
if ( domainAsset.getBookingItem() != null ) {
|
||||
final var biValidation = HsBookingItemEntityValidatorRegistry.forType(HsBookingItemType.DOMAIN_SETUP)
|
||||
.validateEntity(domainAsset.getBookingItem());
|
||||
if (!biValidation.isEmpty()) {
|
||||
return biValidation;
|
||||
}
|
||||
}
|
||||
|
||||
return HostingAssetEntityValidatorRegistry.forType(DOMAIN_SETUP)
|
||||
.validateEntity(domainAsset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,7 +470,10 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
|
||||
private DomainSetupBuilder domainSetupWithParentAssetFor(final String domainName) {
|
||||
return new DomainSetupBuilder(
|
||||
HsHostingAssetRealEntity.builder().type(DOMAIN_SETUP).identifier(Dns.superDomain(domainName).orElseThrow()).build(),
|
||||
HsHostingAssetRealEntity.builder()
|
||||
.type(DOMAIN_SETUP)
|
||||
.identifier(Dns.superDomain(domainName).orElseThrow())
|
||||
.build(),
|
||||
domainName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user