mirror of
https://github.com/google/nomulus.git
synced 2025-07-23 19:20:44 +02:00
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:
parent
314daff8a1
commit
cfee7e7fd5
11 changed files with 356 additions and 31 deletions
|
@ -16,13 +16,21 @@ package google.registry.model.domain.token;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.common.truth.Truth8.assertThat;
|
||||
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.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.JUnitBackports.assertThrows;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.EntityTestCase;
|
||||
import google.registry.model.domain.token.AllocationToken.TokenStatus;
|
||||
import google.registry.model.domain.token.AllocationToken.TokenType;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.util.DateTimeUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -31,15 +39,34 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
|
||||
@Test
|
||||
public void testPersistence() {
|
||||
AllocationToken token =
|
||||
AllocationToken unlimitedUseToken =
|
||||
persistResource(
|
||||
new AllocationToken.Builder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(UNLIMITED_USE)
|
||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||
.setAllowedTlds(ImmutableSet.of("dev", "app"))
|
||||
.setAllowedClientIds(ImmutableSet.of("TheRegistrar, NewRegistrar"))
|
||||
.setDiscountFraction(0.5)
|
||||
.setTokenStatusTransitions(
|
||||
ImmutableSortedMap.<DateTime, TokenStatus>naturalOrder()
|
||||
.put(DateTimeUtils.START_OF_TIME, TokenStatus.NOT_STARTED)
|
||||
.put(DateTime.now(UTC), TokenStatus.VALID)
|
||||
.put(DateTime.now(UTC).plusWeeks(8), TokenStatus.ENDED)
|
||||
.build())
|
||||
.build());
|
||||
assertThat(ofy().load().entity(unlimitedUseToken).now()).isEqualTo(unlimitedUseToken);
|
||||
|
||||
AllocationToken singleUseToken =
|
||||
persistResource(
|
||||
new AllocationToken.Builder()
|
||||
.setToken("abc123")
|
||||
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 1L))
|
||||
.setDomainName("foo.example")
|
||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||
.setTokenType(SINGLE_USE)
|
||||
.build());
|
||||
assertThat(ofy().load().entity(token).now()).isEqualTo(token);
|
||||
assertThat(ofy().load().entity(singleUseToken).now()).isEqualTo(singleUseToken);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -48,6 +75,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
persistResource(
|
||||
new AllocationToken.Builder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(SINGLE_USE)
|
||||
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, 1L))
|
||||
.setDomainName("blahdomain.fake")
|
||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"))
|
||||
|
@ -60,7 +88,7 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
@Test
|
||||
public void testCreationTime_autoPopulates() {
|
||||
AllocationToken tokenBeforePersisting =
|
||||
new AllocationToken.Builder().setToken("abc123").build();
|
||||
new AllocationToken.Builder().setToken("abc123").setTokenType(SINGLE_USE).build();
|
||||
assertThat(tokenBeforePersisting.getCreationTime()).isEmpty();
|
||||
AllocationToken tokenAfterPersisting = persistResource(tokenBeforePersisting);
|
||||
assertThat(tokenAfterPersisting.getCreationTime()).hasValue(clock.nowUtc());
|
||||
|
@ -71,12 +99,13 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
AllocationToken.Builder builder =
|
||||
new AllocationToken.Builder()
|
||||
.setToken("foobar")
|
||||
.setTokenType(SINGLE_USE)
|
||||
.setCreationTimeForTest(DateTime.parse("2010-11-12T05:00:00Z"));
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> builder.setCreationTimeForTest(DateTime.parse("2010-11-13T05:00:00Z")));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("creationTime can only be set once");
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Creation time can only be set once");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -84,6 +113,68 @@ public class AllocationTokenTest extends EntityTestCase {
|
|||
AllocationToken.Builder builder = new AllocationToken.Builder().setToken("foobar");
|
||||
IllegalStateException thrown =
|
||||
assertThrows(IllegalStateException.class, () -> builder.setToken("barfoo"));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("token can only be set once");
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Token can only be set once");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetTokenType_cantCallMoreThanOnce() {
|
||||
AllocationToken.Builder builder =
|
||||
new AllocationToken.Builder().setTokenType(TokenType.UNLIMITED_USE);
|
||||
IllegalStateException thrown =
|
||||
assertThrows(IllegalStateException.class, () -> builder.setTokenType(SINGLE_USE));
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Token type can only be set once");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild_domainNameOnlyOnSingleUse() {
|
||||
AllocationToken.Builder builder =
|
||||
new AllocationToken.Builder()
|
||||
.setToken("foobar")
|
||||
.setTokenType(TokenType.UNLIMITED_USE)
|
||||
.setDomainName("foo.example");
|
||||
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Domain name can only be specified for SINGLE_USE tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild_redemptionHistoryEntryOnlyInSingleUse() {
|
||||
AllocationToken.Builder builder =
|
||||
new AllocationToken.Builder()
|
||||
.setToken("foobar")
|
||||
.setTokenType(TokenType.UNLIMITED_USE)
|
||||
.setRedemptionHistoryEntry(Key.create(HistoryEntry.class, "hi"));
|
||||
IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Redemption history entry can only be specified for SINGLE_USE tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild_noTokenType() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new AllocationToken.Builder().setToken("foobar").build());
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Token type must be specified");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild_noToken() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new AllocationToken.Builder().setTokenType(SINGLE_USE).build());
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Token must not be null or empty");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuild_emptyToken() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new AllocationToken.Builder().setToken("").setTokenType(SINGLE_USE).build());
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Token must not be blank");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -231,9 +231,28 @@ class google.registry.model.domain.secdns.DelegationSignerData {
|
|||
class google.registry.model.domain.token.AllocationToken {
|
||||
@Id java.lang.String token;
|
||||
com.googlecode.objectify.Key<google.registry.model.reporting.HistoryEntry> redemptionHistoryEntry;
|
||||
double discountFraction;
|
||||
google.registry.model.CreateAutoTimestamp creationTime;
|
||||
google.registry.model.UpdateAutoTimestamp updateTimestamp;
|
||||
google.registry.model.common.TimedTransitionProperty<google.registry.model.domain.token.AllocationToken$TokenStatus, google.registry.model.domain.token.AllocationToken$TokenStatusTransition> tokenStatusTransitions;
|
||||
google.registry.model.domain.token.AllocationToken$TokenType tokenType;
|
||||
java.lang.String domainName;
|
||||
java.util.Set<java.lang.String> allowedClientIds;
|
||||
java.util.Set<java.lang.String> allowedTlds;
|
||||
}
|
||||
enum google.registry.model.domain.token.AllocationToken$TokenStatus {
|
||||
CANCELLED;
|
||||
ENDED;
|
||||
NOT_STARTED;
|
||||
VALID;
|
||||
}
|
||||
class google.registry.model.domain.token.AllocationToken$TokenStatusTransition {
|
||||
google.registry.model.domain.token.AllocationToken$TokenStatus tokenStatus;
|
||||
org.joda.time.DateTime transitionTime;
|
||||
}
|
||||
enum google.registry.model.domain.token.AllocationToken$TokenType {
|
||||
SINGLE_USE;
|
||||
UNLIMITED_USE;
|
||||
}
|
||||
class google.registry.model.eppcommon.AuthInfo$PasswordAuth {
|
||||
java.lang.String repoId;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue