From d1e3194fcecaed78102928d06ea802d4a260ab4c Mon Sep 17 00:00:00 2001 From: gbrodman Date: Fri, 12 Apr 2019 13:05:06 -0700 Subject: [PATCH] Don't delete or "redeem" unlimited use AllocationTokens We haven't started dealing with timing or discounts yet, but unlimited use tokens should actually be unlimited use ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=243318266 --- .../registry/flows/domain/DomainCreateFlow.java | 8 ++++++-- .../domain/token/AllocationTokenFlowUtils.java | 9 ++++++++- .../tools/DeleteAllocationTokensCommand.java | 2 ++ .../flows/domain/DomainCreateFlowTest.java | 15 +++++++++++++++ .../tools/DeleteAllocationTokensCommandTest.java | 13 +++++++++++++ 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/java/google/registry/flows/domain/DomainCreateFlow.java b/java/google/registry/flows/domain/DomainCreateFlow.java index 2f61fc98e..54e1d6fb8 100644 --- a/java/google/registry/flows/domain/DomainCreateFlow.java +++ b/java/google/registry/flows/domain/DomainCreateFlow.java @@ -88,6 +88,7 @@ import google.registry.model.domain.metadata.MetadataExtension; import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.secdns.SecDnsCreateExtension; import google.registry.model.domain.token.AllocationToken; +import google.registry.model.domain.token.AllocationToken.TokenType; import google.registry.model.domain.token.AllocationTokenExtension; import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppinput.EppInput; @@ -354,8 +355,11 @@ public class DomainCreateFlow implements TransactionalFlow { newDomain, ForeignKeyIndex.create(newDomain, newDomain.getDeletionTime()), EppResourceIndex.create(Key.create(newDomain))); - allocationToken.ifPresent( - t -> entitiesToSave.add(allocationTokenFlowUtils.redeemToken(t, Key.create(historyEntry)))); + if (allocationToken.isPresent() + && TokenType.SINGLE_USE.equals(allocationToken.get().getTokenType())) { + entitiesToSave.add( + allocationTokenFlowUtils.redeemToken(allocationToken.get(), Key.create(historyEntry))); + } enqueueTasks(newDomain, hasSignedMarks, hasClaimsNotice); EntityChanges entityChanges = diff --git a/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java b/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java index db0f19edf..75cf84d62 100644 --- a/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java +++ b/java/google/registry/flows/domain/token/AllocationTokenFlowUtils.java @@ -14,6 +14,7 @@ package google.registry.flows.domain.token; +import static com.google.common.base.Preconditions.checkArgument; import static google.registry.model.ofy.ObjectifyService.ofy; import com.google.common.collect.ImmutableMap; @@ -24,6 +25,7 @@ import google.registry.flows.EppException.AssociationProhibitsOperationException import google.registry.flows.EppException.ParameterValueSyntaxErrorException; import google.registry.model.domain.DomainCommand; import google.registry.model.domain.token.AllocationToken; +import google.registry.model.domain.token.AllocationToken.TokenType; import google.registry.model.registry.Registry; import google.registry.model.reporting.HistoryEntry; import java.util.List; @@ -89,9 +91,14 @@ public class AllocationTokenFlowUtils { : checkResults; } - /** Redeems an {@link AllocationToken}, returning the redeemed copy. */ + /** + * Redeems a SINGLE_USE {@link AllocationToken}, returning the redeemed copy. + */ public AllocationToken redeemToken( AllocationToken token, Key redemptionHistoryEntry) { + checkArgument( + TokenType.SINGLE_USE.equals(token.getTokenType()), + "Only SINGLE_USE tokens can be marked as redeemed"); return token.asBuilder().setRedemptionHistoryEntry(redemptionHistoryEntry).build(); } diff --git a/java/google/registry/tools/DeleteAllocationTokensCommand.java b/java/google/registry/tools/DeleteAllocationTokensCommand.java index f252616f6..88719a5dc 100644 --- a/java/google/registry/tools/DeleteAllocationTokensCommand.java +++ b/java/google/registry/tools/DeleteAllocationTokensCommand.java @@ -17,6 +17,7 @@ package google.registry.tools; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.Iterables.partition; import static com.google.common.collect.Streams.stream; +import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE; import static google.registry.model.ofy.ObjectifyService.ofy; import com.beust.jcommander.Parameter; @@ -93,6 +94,7 @@ final class DeleteAllocationTokensCommand extends ConfirmingCommand ImmutableSet tokensToDelete = ofy().load().keys(batch).values().stream() .filter(t -> withDomains || !t.getDomainName().isPresent()) + .filter(t -> SINGLE_USE.equals(t.getTokenType())) .filter(t -> !t.isRedeemed()) .collect(toImmutableSet()); if (!dryRun) { diff --git a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java index f16beb1dd..f326b3766 100644 --- a/javatests/google/registry/flows/domain/DomainCreateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainCreateFlowTest.java @@ -22,6 +22,7 @@ import static google.registry.model.billing.BillingEvent.Flag.ANCHOR_TENANT; import static google.registry.model.billing.BillingEvent.Flag.SUNRISE; import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS; 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.OK; import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE; import static google.registry.model.eppcommon.StatusValue.SERVER_HOLD; @@ -452,6 +453,20 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase