mirror of
https://github.com/google/nomulus.git
synced 2025-08-12 04:29:39 +02:00
Add default tokens to TLD using nomulus tool (#1888)
* Add defualt tokens to TLD using nomulus tool * add test
This commit is contained in:
parent
de9dee4623
commit
34288a8a81
6 changed files with 214 additions and 12 deletions
|
@ -16,11 +16,13 @@ package google.registry.tools;
|
|||
|
||||
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.DEFAULT_PROMO;
|
||||
import static google.registry.model.tld.Registry.TldState.GENERAL_AVAILABILITY;
|
||||
import static google.registry.model.tld.Registry.TldState.PREDELEGATION;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistPremiumList;
|
||||
import static google.registry.testing.DatabaseHelper.persistReservedList;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static java.math.BigDecimal.ROUND_UNNECESSARY;
|
||||
import static org.joda.money.CurrencyUnit.JPY;
|
||||
|
@ -32,6 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||
import com.beust.jcommander.ParameterException;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Range;
|
||||
import google.registry.model.domain.token.AllocationToken;
|
||||
import google.registry.model.tld.Registry;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.money.Money;
|
||||
|
@ -568,6 +571,68 @@ class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
|||
.contains("Invalid DNS writer name(s) specified: [Deadbeef, Invalid]");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_defaultToken() throws Exception {
|
||||
AllocationToken token =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
runCommandForced(
|
||||
"--default_tokens=abc123",
|
||||
"--roid_suffix=Q9JYB4C",
|
||||
"--dns_writers=FooDnsWriter",
|
||||
"xn--q9jyb4c");
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens())
|
||||
.containsExactly(token.createVKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_multipleDefaultTokens() throws Exception {
|
||||
AllocationToken token =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
AllocationToken token2 =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("token")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
runCommandForced(
|
||||
"--default_tokens=abc123,token",
|
||||
"--roid_suffix=Q9JYB4C",
|
||||
"--dns_writers=FooDnsWriter",
|
||||
"xn--q9jyb4c");
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens())
|
||||
.containsExactly(token.createVKey(), token2.createVKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_specifiedDefaultToken_doesntExist() {
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() ->
|
||||
runCommandForced(
|
||||
"xn--q9jyb4c",
|
||||
"--default_tokens=InvalidToken",
|
||||
"--roid_suffix=Q9JYB4C",
|
||||
"--dns_writers=FooDnsWriter"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Tokens with keys [VKey<AllocationToken>(sql:InvalidToken)] did not exist");
|
||||
}
|
||||
|
||||
private void runSuccessfulReservedListsTest(String reservedLists) throws Exception {
|
||||
runCommandForced(
|
||||
"--reserved_lists",
|
||||
|
|
|
@ -16,6 +16,7 @@ package google.registry.tools;
|
|||
|
||||
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.DEFAULT_PROMO;
|
||||
import static google.registry.model.tld.Registry.TldState.GENERAL_AVAILABILITY;
|
||||
import static google.registry.model.tld.Registry.TldState.PREDELEGATION;
|
||||
import static google.registry.model.tld.Registry.TldState.QUIET_PERIOD;
|
||||
|
@ -33,8 +34,10 @@ import static org.joda.time.Duration.standardMinutes;
|
|||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.beust.jcommander.ParameterException;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import google.registry.model.domain.token.AllocationToken;
|
||||
import google.registry.model.tld.Registry;
|
||||
import java.util.Optional;
|
||||
import org.joda.money.Money;
|
||||
|
@ -174,6 +177,118 @@ class UpdateTldCommandTest extends CommandTestCase<UpdateTldCommand> {
|
|||
.containsExactly("FooDnsWriter", "VoidDnsWriter");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_defaultToken() throws Exception {
|
||||
AllocationToken token =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens()).isEmpty();
|
||||
runCommandForced("--default_tokens=abc123", "xn--q9jyb4c");
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens())
|
||||
.containsExactly(token.createVKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_multipleDefaultTokens() throws Exception {
|
||||
AllocationToken token =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
AllocationToken token2 =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("token")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens()).isEmpty();
|
||||
runCommandForced("--default_tokens=abc123,token", "xn--q9jyb4c");
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens())
|
||||
.containsExactly(token.createVKey(), token2.createVKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_emptyTokenList() throws Exception {
|
||||
AllocationToken token =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens()).isEmpty();
|
||||
persistResource(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
.asBuilder()
|
||||
.setDefaultPromoTokens(ImmutableList.of(token.createVKey()))
|
||||
.build());
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens())
|
||||
.containsExactly(token.createVKey());
|
||||
runCommandForced("--default_tokens=", "xn--q9jyb4c");
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_replaceExistingDefaultTokensListOrder() throws Exception {
|
||||
AllocationToken token =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("abc123")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
AllocationToken token2 =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("token")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
AllocationToken token3 =
|
||||
persistResource(
|
||||
new AllocationToken()
|
||||
.asBuilder()
|
||||
.setToken("othertoken")
|
||||
.setTokenType(DEFAULT_PROMO)
|
||||
.setAllowedTlds(ImmutableSet.of("xn--q9jyb4c"))
|
||||
.build());
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens()).isEmpty();
|
||||
persistResource(
|
||||
Registry.get("xn--q9jyb4c")
|
||||
.asBuilder()
|
||||
.setDefaultPromoTokens(ImmutableList.of(token.createVKey(), token2.createVKey()))
|
||||
.build());
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens())
|
||||
.containsExactly(token.createVKey(), token2.createVKey());
|
||||
runCommandForced("--default_tokens=token,othertoken", "xn--q9jyb4c");
|
||||
assertThat(Registry.get("xn--q9jyb4c").getDefaultPromoTokens())
|
||||
.containsExactly(token2.createVKey(), token3.createVKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_specifiedDefaultToken_doesntExist() {
|
||||
IllegalStateException thrown =
|
||||
assertThrows(
|
||||
IllegalStateException.class,
|
||||
() -> runCommandForced("xn--q9jyb4c", "--default_tokens=InvalidToken"));
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.contains("Tokens with keys [VKey<AllocationToken>(sql:InvalidToken)] did not exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_escrow() throws Exception {
|
||||
runCommandForced("--escrow=true", "xn--q9jyb4c");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue