From 8b02f76ae951d9929546df664dafa124e4ca6aa5 Mon Sep 17 00:00:00 2001 From: sarahcaseybot Date: Tue, 23 Aug 2022 14:47:41 -0400 Subject: [PATCH] Add currentPackageToken on create flow (#1751) * Add currentPackageToken on create flow * Change to Truth8 assertion * Add check for specified renewal behavior --- .../flows/domain/DomainCreateFlow.java | 5 ++++ .../model/domain/token/AllocationToken.java | 5 ++++ .../flows/domain/DomainCreateFlowTest.java | 23 +++++++++++++++++++ .../domain/token/AllocationTokenTest.java | 14 +++++++++++ .../GenerateAllocationTokensCommandTest.java | 3 ++- .../google/registry/model/schema.txt | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) 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 edd5b307a..30b5ed03f 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainCreateFlow.java @@ -390,6 +390,11 @@ public final class DomainCreateFlow implements TransactionalFlow { .addGracePeriod( GracePeriod.forBillingEvent(GracePeriodStatus.ADD, repoId, createBillingEvent)) .build(); + if (allocationToken.isPresent() + && allocationToken.get().getTokenType().equals(TokenType.PACKAGE)) { + domain = + domain.asBuilder().setCurrentPackageToken(allocationToken.get().createVKey()).build(); + } DomainHistory domainHistory = buildDomainHistory(domain, registry, now, period, registry.getAddGracePeriodLength()); if (reservationTypes.contains(NAME_COLLISION)) { diff --git a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java index 857c64810..618d15b9b 100644 --- a/core/src/main/java/google/registry/model/domain/token/AllocationToken.java +++ b/core/src/main/java/google/registry/model/domain/token/AllocationToken.java @@ -105,6 +105,7 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { /** Single-use tokens are invalid after use. Infinite-use tokens, predictably, are not. */ public enum TokenType { + PACKAGE, SINGLE_USE, UNLIMITED_USE } @@ -274,6 +275,10 @@ public class AllocationToken extends BackupGroupRoot implements Buildable { public AllocationToken build() { checkArgumentNotNull(getInstance().tokenType, "Token type must be specified"); checkArgument(!Strings.isNullOrEmpty(getInstance().token), "Token must not be null or empty"); + checkArgument( + !getInstance().tokenType.equals(TokenType.PACKAGE) + || getInstance().renewalPriceBehavior.equals(RenewalPriceBehavior.SPECIFIED), + "Package tokens must have renewalPriceBehavior set to SPECIFIED"); checkArgument( getInstance().domainName == null || TokenType.SINGLE_USE.equals(getInstance().tokenType), "Domain name can only be specified for SINGLE_USE tokens"); 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 935e3100b..4eebf1c0d 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainCreateFlowTest.java @@ -25,6 +25,7 @@ import static google.registry.model.billing.BillingEvent.RenewalPriceBehavior.DE import static google.registry.model.billing.BillingEvent.RenewalPriceBehavior.NONPREMIUM; import static google.registry.model.billing.BillingEvent.RenewalPriceBehavior.SPECIFIED; import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS; +import static google.registry.model.domain.token.AllocationToken.TokenType.PACKAGE; import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE; import static google.registry.model.domain.token.AllocationToken.TokenType.UNLIMITED_USE; import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE; @@ -70,6 +71,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSortedMap; import com.google.common.collect.Iterables; import com.google.common.collect.Ordering; +import com.google.common.truth.Truth8; import com.googlecode.objectify.Key; import google.registry.config.RegistryConfig; import google.registry.flows.EppException; @@ -3126,4 +3128,25 @@ class DomainCreateFlowTest extends ResourceFlowTestCase builder.build()); + assertThat(thrown) + .hasMessageThat() + .isEqualTo("Package tokens must have renewalPriceBehavior set to SPECIFIED"); + } + @Test void testBuild_DomainNameWithLessThanTwoParts() { IllegalArgumentException thrown = diff --git a/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java b/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java index eaea3da08..3f351a2b3 100644 --- a/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java +++ b/core/src/test/java/google/registry/tools/GenerateAllocationTokensCommandTest.java @@ -402,7 +402,8 @@ class GenerateAllocationTokensCommandTest extends CommandTestCase runCommand("--number", "999", "--type", "INVALID_TYPE")); assertThat(thrown) .hasMessageThat() - .isEqualTo("Invalid value for -t parameter. Allowed values:[SINGLE_USE, UNLIMITED_USE]"); + .isEqualTo( + "Invalid value for -t parameter. Allowed values:[PACKAGE, SINGLE_USE, UNLIMITED_USE]"); } @Test diff --git a/core/src/test/resources/google/registry/model/schema.txt b/core/src/test/resources/google/registry/model/schema.txt index 5d7ca744c..5458a4bb3 100644 --- a/core/src/test/resources/google/registry/model/schema.txt +++ b/core/src/test/resources/google/registry/model/schema.txt @@ -258,6 +258,7 @@ enum google.registry.model.domain.token.AllocationToken$TokenStatus { VALID; } enum google.registry.model.domain.token.AllocationToken$TokenType { + PACKAGE; SINGLE_USE; UNLIMITED_USE; }