Add necessary fields to the AllocationToken schema

See https://docs.google.com/document/d/1SSWrILRpx0Mtr4sdvlYwz9I8wJp5Gu_o4qlml3iJDKI

This is just the base for now--we don't actually do anything with it.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=243265164
This commit is contained in:
gbrodman 2019-04-12 08:05:56 -07:00 committed by Ben McIlwain
parent 314daff8a1
commit cfee7e7fd5
11 changed files with 356 additions and 31 deletions

View file

@ -15,6 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
@ -129,7 +130,10 @@ public class DeleteAllocationTokensCommandTest
private static AllocationToken persistToken(
String token, @Nullable String domainName, boolean redeemed) {
AllocationToken.Builder builder =
new AllocationToken.Builder().setToken(token).setDomainName(domainName);
new AllocationToken.Builder()
.setToken(token)
.setTokenType(SINGLE_USE)
.setDomainName(domainName);
if (redeemed) {
builder.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 1051L));
}

View file

@ -15,6 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.JUnitBackports.assertThrows;
@ -94,7 +95,11 @@ public class GenerateAllocationTokensCommandTest
@Test
public void testSuccess_tokenCollision() throws Exception {
AllocationToken existingToken =
persistResource(new AllocationToken.Builder().setToken("DEADBEEF123456789ABC").build());
persistResource(
new AllocationToken.Builder()
.setToken("DEADBEEF123456789ABC")
.setTokenType(SINGLE_USE)
.build());
runCommand("--number", "1", "--prefix", "DEADBEEF", "--length", "12");
assertAllocationTokens(existingToken, createToken("DEADBEEFDEFGHJKLMNPQ", null, null));
assertInStdout("DEADBEEFDEFGHJKLMNPQ");
@ -177,7 +182,8 @@ public class GenerateAllocationTokensCommandTest
String token,
@Nullable Key<HistoryEntry> redemptionHistoryEntry,
@Nullable String domainName) {
AllocationToken.Builder builder = new AllocationToken.Builder().setToken(token);
AllocationToken.Builder builder =
new AllocationToken.Builder().setToken(token).setTokenType(SINGLE_USE);
if (redemptionHistoryEntry != null) {
builder.setRedemptionHistoryEntry(redemptionHistoryEntry);
}

View file

@ -14,6 +14,7 @@
package google.registry.tools;
import static google.registry.model.domain.token.AllocationToken.TokenType.SINGLE_USE;
import static google.registry.testing.DatastoreHelper.createHistoryEntryForEppResource;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistActiveDomain;
@ -36,7 +37,11 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
public void testSuccess_oneToken() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder().setToken("foo").setDomainName("foo.bar").build());
new AllocationToken.Builder()
.setToken("foo")
.setTokenType(SINGLE_USE)
.setDomainName("foo.bar")
.build());
runCommand("foo");
assertInStdout(token.toString(), "Token foo was not redeemed.");
}
@ -48,9 +53,14 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
ImmutableList.of(
new AllocationToken.Builder()
.setToken("fee")
.setTokenType(SINGLE_USE)
.setCreationTimeForTest(DateTime.parse("2015-04-07T22:19:17.044Z"))
.build(),
new AllocationToken.Builder().setToken("fii").setDomainName("bar.baz").build()));
new AllocationToken.Builder()
.setToken("fii")
.setTokenType(SINGLE_USE)
.setDomainName("bar.baz")
.build()));
runCommand("fee", "fii");
assertInStdout(
tokens.get(0).toString(),
@ -68,6 +78,7 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
persistResource(
new AllocationToken.Builder()
.setToken("foo")
.setTokenType(SINGLE_USE)
.setDomainName("fqqdn.tld")
.setRedemptionHistoryEntry(Key.create(createHistoryEntryForEppResource(domain)))
.build());
@ -81,12 +92,14 @@ public class GetAllocationTokenCommandTest extends CommandTestCase<GetAllocation
public void testSuccess_oneTokenDoesNotExist() throws Exception {
AllocationToken token =
persistResource(
new AllocationToken.Builder().setToken("foo").setDomainName("foo.bar").build());
new AllocationToken.Builder()
.setToken("foo")
.setTokenType(SINGLE_USE)
.setDomainName("foo.bar")
.build());
runCommand("foo", "bar");
assertInStdout(
token.toString(),
"Token foo was not redeemed.",
"ERROR: Token bar does not exist.");
token.toString(), "Token foo was not redeemed.", "ERROR: Token bar does not exist.");
}
@Test