add tests with user defined verification cod
This commit is contained in:
parent
ca10f7a998
commit
ca63d957e4
@ -365,6 +365,20 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
|||||||
.isRejectedWithCauseMissingVerificationIn("sub.example.org");
|
.isRejectedWithCauseMissingVerificationIn("sub.example.org");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void allowSetupOfRegistrableDomainWithUserDefinedVerificationCode() {
|
||||||
|
domainSetupFor("example.edu.it").notRegistered().withUserDefinedVerificationCode("ABCD-EFGH-IJKL-MNOP")
|
||||||
|
.withVerificationIn("example.edu.it")
|
||||||
|
.isAccepted();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void rejectSetupOfRegistrableDomainWithInvalidUserDefinedVerificationCode() {
|
||||||
|
domainSetupFor("example.edu.it").notRegistered().withUserDefinedVerificationCode("ABCD-EFGH-IJKL-MNOP")
|
||||||
|
.withVerificationIn("example.edu.it", "SOME-OTHER-CODE")
|
||||||
|
.isRejectedWithCauseMissingVerificationIn("example.edu.it");
|
||||||
|
}
|
||||||
|
|
||||||
//====================================================================================================================
|
//====================================================================================================================
|
||||||
|
|
||||||
private static HsHostingAssetRealEntity createValidParentDomainSetupAsset(final String parentDomainName) {
|
private static HsHostingAssetRealEntity createValidParentDomainSetupAsset(final String parentDomainName) {
|
||||||
@ -384,11 +398,9 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
|||||||
class DomainSetupBuilder {
|
class DomainSetupBuilder {
|
||||||
|
|
||||||
private final HsHostingAssetRbacEntity domainAsset;
|
private final HsHostingAssetRbacEntity domainAsset;
|
||||||
private final String expectedHash;
|
|
||||||
|
|
||||||
public DomainSetupBuilder(final String domainName) {
|
public DomainSetupBuilder(final String domainName) {
|
||||||
domainAsset = validEntityBuilder(domainName).build();
|
domainAsset = validEntityBuilder(domainName).build();
|
||||||
expectedHash = domainAsset.getBookingItem().getDirectValue("verificationCode", String.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DomainSetupBuilder(final HsHostingAssetRealEntity parentAsset, final String domainName) {
|
public DomainSetupBuilder(final HsHostingAssetRealEntity parentAsset, final String domainName) {
|
||||||
@ -396,7 +408,6 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
|||||||
.bookingItem(null)
|
.bookingItem(null)
|
||||||
.parentAsset(parentAsset)
|
.parentAsset(parentAsset)
|
||||||
.build();
|
.build();
|
||||||
expectedHash = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DomainSetupBuilder notRegistered() {
|
DomainSetupBuilder notRegistered() {
|
||||||
@ -423,20 +434,33 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
DomainSetupBuilder withVerificationIn(final String domainName) {
|
DomainSetupBuilder withUserDefinedVerificationCode(final String verificationCode) {
|
||||||
assertThat(expectedHash).as("no expectedHash available").isNotNull();
|
domainAsset.getBookingItem().getResources().put("verificationCode", verificationCode);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
DomainSetupBuilder withVerificationIn(final String domainName, final String verificationCode) {
|
||||||
|
assertThat(verificationCode).as("explicit verificationCode must not be null").isNotNull();
|
||||||
Dns.fakeResultForDomain(
|
Dns.fakeResultForDomain(
|
||||||
domainName,
|
domainName,
|
||||||
Dns.Result.fromRecords("Hostsharing-domain-setup-verification-code=" + expectedHash));
|
Dns.Result.fromRecords("Hostsharing-domain-setup-verification-code=" + verificationCode));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
DomainSetupBuilder withVerificationIn(final String domainName) {
|
||||||
|
assertThat(expectedVerificationCode()).as("no expectedHash available").isNotNull();
|
||||||
|
Dns.fakeResultForDomain(
|
||||||
|
domainName,
|
||||||
|
Dns.Result.fromRecords("Hostsharing-domain-setup-verification-code=" + expectedVerificationCode()));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void isRejectedWithCauseMissingVerificationIn(final String domainName) {
|
void isRejectedWithCauseMissingVerificationIn(final String domainName) {
|
||||||
assertThat(expectedHash).as("no expectedHash available").isNotNull();
|
assertThat(expectedVerificationCode()).as("no expectedHash available").isNotNull();
|
||||||
assertThat(validate()).containsAnyOf(
|
assertThat(validate()).containsAnyOf(
|
||||||
"[DNS] no TXT record 'Hostsharing-domain-setup-verification-code=" + expectedHash
|
"[DNS] no TXT record 'Hostsharing-domain-setup-verification-code=" + expectedVerificationCode()
|
||||||
+ "' found for domain name '" + domainName + "' (nor in its super-domain)",
|
+ "' found for domain name '" + domainName + "' (nor in its super-domain)",
|
||||||
"[DNS] no TXT record 'Hostsharing-domain-setup-verification-code=" + expectedHash
|
"[DNS] no TXT record 'Hostsharing-domain-setup-verification-code=" + expectedVerificationCode()
|
||||||
+ "' found for domain name '" + domainName + "'");
|
+ "' found for domain name '" + domainName + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,6 +474,10 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
|||||||
assertThat(validate()).isEmpty();
|
assertThat(validate()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String expectedVerificationCode() {
|
||||||
|
return domainAsset.getBookingItem().getDirectValue("verificationCode", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> validate() {
|
private List<String> validate() {
|
||||||
if ( domainAsset.getBookingItem() != null ) {
|
if ( domainAsset.getBookingItem() != null ) {
|
||||||
final var biValidation = HsBookingItemEntityValidatorRegistry.forType(HsBookingItemType.DOMAIN_SETUP)
|
final var biValidation = HsBookingItemEntityValidatorRegistry.forType(HsBookingItemType.DOMAIN_SETUP)
|
||||||
|
Loading…
Reference in New Issue
Block a user