user-definable verificationCode and more business-level-validation-tests #100

Merged
hsh-michaelhoennig merged 8 commits from user-definable-verificationCode-and-bi-validation-tests into master 2024-09-12 10:52:45 +02:00
2 changed files with 23 additions and 3 deletions
Showing only changes of commit 4f49793817 - Show all commits

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();
}