From b8f1b2fc4f7f38bf8dedae7e164d01f3e535aaf8 Mon Sep 17 00:00:00 2001 From: sarahcaseybot Date: Wed, 14 Sep 2022 14:49:56 -0400 Subject: [PATCH] Prevent creation of package domains for more than 1 year (#1786) * Prevent creation of package domains for more than 1 year * Fix docs test --- .../flows/domain/DomainCreateFlow.java | 14 ++++++++ .../flows/domain/DomainCreateFlowTest.java | 34 +++++++++++++++++-- docs/flows.md | 1 + 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java b/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java index d617b72f7..1ddc34ae0 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java @@ -153,6 +153,7 @@ import org.joda.time.Duration; * @error {@link DomainCreateFlow.MustHaveSignedMarksInCurrentPhaseException} * @error {@link DomainCreateFlow.NoGeneralRegistrationsInCurrentPhaseException} * @error {@link DomainCreateFlow.NoTrademarkedRegistrationsBeforeSunriseException} + * @error {@link DomainCreateFlow.PackageDomainRegisteredForTooManyYearsException} * @error {@link DomainCreateFlow.SignedMarksOnlyDuringSunriseException} * @error {@link DomainFlowTmchUtils.NoMarksFoundMatchingDomainException} * @error {@link DomainFlowTmchUtils.FoundMarkNotYetValidException} @@ -391,6 +392,9 @@ public final class DomainCreateFlow implements TransactionalFlow { .build(); if (allocationToken.isPresent() && allocationToken.get().getTokenType().equals(TokenType.PACKAGE)) { + if (years > 1) { + throw new PackageDomainRegisteredForTooManyYearsException(allocationToken.get().getToken()); + } domain = domain.asBuilder().setCurrentPackageToken(allocationToken.get().createVKey()).build(); } @@ -755,4 +759,14 @@ public final class DomainCreateFlow implements TransactionalFlow { ANCHOR_TENANT_CREATE_VALID_YEARS, invalidYears)); } } + + /** Package domain registered for too many years. */ + static class PackageDomainRegisteredForTooManyYearsException extends CommandUseErrorException { + public PackageDomainRegisteredForTooManyYearsException(String token) { + super( + String.format( + "The package token %s cannot be used to register names for longer than 1 year.", + token)); + } + } } diff --git a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java index 9a5ca7d50..d468fb96b 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -85,6 +85,7 @@ import google.registry.flows.domain.DomainCreateFlow.AnchorTenantCreatePeriodExc import google.registry.flows.domain.DomainCreateFlow.MustHaveSignedMarksInCurrentPhaseException; import google.registry.flows.domain.DomainCreateFlow.NoGeneralRegistrationsInCurrentPhaseException; import google.registry.flows.domain.DomainCreateFlow.NoTrademarkedRegistrationsBeforeSunriseException; +import google.registry.flows.domain.DomainCreateFlow.PackageDomainRegisteredForTooManyYearsException; import google.registry.flows.domain.DomainCreateFlow.RenewalPriceInfo; import google.registry.flows.domain.DomainCreateFlow.SignedMarksOnlyDuringSunriseException; import google.registry.flows.domain.DomainFlowTmchUtils.FoundMarkExpiredException; @@ -3142,11 +3143,40 @@ class DomainCreateFlowTest extends ResourceFlowTestCase() + .put("DOMAIN", "example.tld") + .put("CRDATE", "1999-04-03T22:00:00.0Z") + .put("EXDATE", "2000-04-03T22:00:00.0Z") + .build())); Domain domain = reloadResourceByForeignKey(); assertThat(domain.getCurrentPackageToken()).isPresent(); Truth8.assertThat(domain.getCurrentPackageToken()).hasValue(token.createVKey()); } + + @Test + void testFailure_packageToken_registrationTooLong() throws Exception { + AllocationToken token = + persistResource( + new AllocationToken.Builder() + .setToken("abc123") + .setTokenType(PACKAGE) + .setAllowedRegistrarIds(ImmutableSet.of("TheRegistrar")) + .setAllowedTlds(ImmutableSet.of("tld")) + .setRenewalPriceBehavior(SPECIFIED) + .build()); + persistContactsAndHosts(); + setEppInput( + "domain_create_allocationtoken.xml", + ImmutableMap.of("DOMAIN", "example.tld", "YEARS", "2")); + EppException thrown = + assertThrows(PackageDomainRegisteredForTooManyYearsException.class, this::runFlow); + assertThat(thrown) + .hasMessageThat() + .isEqualTo( + "The package token abc123 cannot be used to register names for longer than 1 year."); + } } diff --git a/docs/flows.md b/docs/flows.md index e8addf278..b2a9378a5 100644 --- a/docs/flows.md +++ b/docs/flows.md @@ -311,6 +311,7 @@ An EPP flow that creates a new domain resource. * Registrar is not logged in. * The current registry phase allows registrations only with signed marks. * The current registry phase does not allow for general registrations. + * Package domain registered for too many years. * Signed marks are only allowed during sunrise. * An allocation token was provided that is invalid for premium domains. * 2003