test for setup of subdomain of non-existing superdomain and improved error message for this case

This commit is contained in:
Michael Hoennig 2024-09-12 07:31:31 +02:00
parent 8d69f2ed39
commit 4f49793817
2 changed files with 23 additions and 3 deletions

View File

@ -57,9 +57,16 @@ class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator {
if (isDnsVerificationRequiredForUnregisteredDomain(assetEntity)) {
final var superDomain = superDomain(domainName);
final var expectedTxtRecordValue = "Hostsharing-domain-setup-verification-code=" + getCode.get();
final var verificationFoundInSuperDomain = superDomain.flatMap(superDomainName -> findTxtRecord(
new Dns(superDomainName).fetchRecordsOfType("TXT"),
expectedTxtRecordValue));
final var verificationFoundInSuperDomain = superDomain.map(superDomainName ->
{
final Dns.Result superDomainDnsResult = new Dns(superDomainName).fetchRecordsOfType("TXT");
if (superDomainDnsResult.status() != Dns.Status.SUCCESS) {
violations.add("[DNS] lookup failed for domain name '" + superDomainName + "': " + dnsResult.exception());
}
return superDomainDnsResult;
}
)
.flatMap(records -> findTxtRecord(records, expectedTxtRecordValue));
if (verificationFoundInSuperDomain.isEmpty()) {
violations.add(
"[DNS] no TXT record '" + expectedTxtRecordValue +
@ -71,6 +78,7 @@ class HsDomainSetupHostingAssetValidator extends HostingAssetEntityValidator {
}
case Dns.Status.INVALID_NAME:
// should not happen because we validate the domain name at booking item level
violations.add("[DNS] invalid domain name '" + assetEntity.getIdentifier() + "'");
break;

View File

@ -358,6 +358,12 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
.isRejectedWithCauseMissingVerificationIn("example.org");
}
@Test
void rejectSetupOfUnregisteredSubdomainOfUnregisteredSuperDomain() {
domainSetupFor("sub.sub.example.org").notRegistered()
.isRejectedWithCauseDomainNameNotFound("sub.example.org");
}
@Test
void acceptSetupOfUnregisteredSubdomainWithParentAssetEvenWithoutDnsVerificationInSuperDomain() {
domainSetupWithParentAssetFor("sub.example.org").notRegistered()
@ -488,6 +494,12 @@ class HsDomainSetupHostingAssetValidatorUnitTest {
);
}
void isRejectedWithCauseDomainNameNotFound(final String domainName) {
assertThat(validate()).contains(
"[DNS] lookup failed for domain name '" + domainName + "': javax.naming.NameNotFoundException: domain not registered"
);
}
void isAccepted() {
assertThat(validate()).isEmpty();
}