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");
|
||||
}
|
||||
|
||||
@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) {
|
||||
@ -384,11 +398,9 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
class DomainSetupBuilder {
|
||||
|
||||
private final HsHostingAssetRbacEntity domainAsset;
|
||||
private final String expectedHash;
|
||||
|
||||
public DomainSetupBuilder(final String domainName) {
|
||||
domainAsset = validEntityBuilder(domainName).build();
|
||||
expectedHash = domainAsset.getBookingItem().getDirectValue("verificationCode", String.class);
|
||||
}
|
||||
|
||||
public DomainSetupBuilder(final HsHostingAssetRealEntity parentAsset, final String domainName) {
|
||||
@ -396,7 +408,6 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
.bookingItem(null)
|
||||
.parentAsset(parentAsset)
|
||||
.build();
|
||||
expectedHash = null;
|
||||
}
|
||||
|
||||
DomainSetupBuilder notRegistered() {
|
||||
@ -423,20 +434,33 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
return this;
|
||||
}
|
||||
|
||||
DomainSetupBuilder withVerificationIn(final String domainName) {
|
||||
assertThat(expectedHash).as("no expectedHash available").isNotNull();
|
||||
DomainSetupBuilder withUserDefinedVerificationCode(final String verificationCode) {
|
||||
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(
|
||||
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;
|
||||
}
|
||||
|
||||
void isRejectedWithCauseMissingVerificationIn(final String domainName) {
|
||||
assertThat(expectedHash).as("no expectedHash available").isNotNull();
|
||||
assertThat(expectedVerificationCode()).as("no expectedHash available").isNotNull();
|
||||
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)",
|
||||
"[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 + "'");
|
||||
}
|
||||
|
||||
@ -450,6 +474,10 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
|
||||
assertThat(validate()).isEmpty();
|
||||
}
|
||||
|
||||
private String expectedVerificationCode() {
|
||||
return domainAsset.getBookingItem().getDirectValue("verificationCode", String.class);
|
||||
}
|
||||
|
||||
private List<String> validate() {
|
||||
if ( domainAsset.getBookingItem() != null ) {
|
||||
final var biValidation = HsBookingItemEntityValidatorRegistry.forType(HsBookingItemType.DOMAIN_SETUP)
|
||||
|
Loading…
Reference in New Issue
Block a user