mirror of
https://github.com/google/nomulus.git
synced 2025-05-09 00:08:21 +02:00
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
This commit is contained in:
parent
416a39b003
commit
d1e3194fce
5 changed files with 44 additions and 3 deletions
|
@ -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 =
|
||||
|
|
|
@ -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<HistoryEntry> redemptionHistoryEntry) {
|
||||
checkArgument(
|
||||
TokenType.SINGLE_USE.equals(token.getTokenType()),
|
||||
"Only SINGLE_USE tokens can be marked as redeemed");
|
||||
return token.asBuilder().setRedemptionHistoryEntry(redemptionHistoryEntry).build();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<AllocationToken> 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) {
|
||||
|
|
|
@ -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<DomainCreateFlow,
|
|||
.isEqualTo(Key.create(historyEntry));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_validAllocationToken_multiUse() throws Exception {
|
||||
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "example.tld"));
|
||||
persistContactsAndHosts();
|
||||
persistResource(
|
||||
new AllocationToken.Builder().setTokenType(UNLIMITED_USE).setToken("abc123").build());
|
||||
clock.advanceOneMilli();
|
||||
doSuccessfulTest();
|
||||
clock.advanceOneMilli();
|
||||
setEppInput("domain_create_allocationtoken.xml", ImmutableMap.of("DOMAIN", "otherexample.tld"));
|
||||
runFlowAssertResponse(
|
||||
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "otherexample.tld")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_multipartTld() throws Exception {
|
||||
createTld("foo.tld");
|
||||
|
|
|
@ -23,6 +23,7 @@ import static google.registry.testing.JUnitBackports.assertThrows;
|
|||
import com.beust.jcommander.ParameterException;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.domain.token.AllocationToken;
|
||||
import google.registry.model.domain.token.AllocationToken.TokenType;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import java.util.Collection;
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -109,6 +110,18 @@ public class DeleteAllocationTokensCommandTest
|
|||
.containsExactly(preRed1, preRed2, preDom2, othrRed, othrNot);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipUnlimitedUseTokens() throws Exception {
|
||||
AllocationToken unlimitedUseToken =
|
||||
persistResource(
|
||||
new AllocationToken.Builder()
|
||||
.setToken("prefixasdfg897as")
|
||||
.setTokenType(TokenType.UNLIMITED_USE)
|
||||
.build());
|
||||
runCommandForced("--prefix", "prefix");
|
||||
assertThat(reloadTokens(unlimitedUseToken)).containsExactly(unlimitedUseToken);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_batching() throws Exception {
|
||||
for (int i = 0; i < 50; i++) {
|
||||
|
|
Loading…
Add table
Reference in a new issue