mirror of
https://github.com/google/nomulus.git
synced 2025-06-27 14:54:51 +02:00
Add validation to ROID suffixes
I could've sworn we were already doing this, but apparently not? Anyway, ROID suffixes have a number of requirements on them that weren't being enforced, so this enforces them. All existing production data is compliant with these requirements; the only existing bad data we have is in alpha and sandbox. ROID suffixes are now required to match the regex ^[A-Z0-9_]{1,8}$ See also https://tools.ietf.org/html/rfc5730 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=173400001
This commit is contained in:
parent
2f539d6008
commit
7951799595
4 changed files with 39 additions and 8 deletions
|
@ -68,6 +68,7 @@ import java.util.Collection;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
|
@ -852,7 +853,13 @@ public class Registry extends ImmutableObject implements Buildable {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Pattern ROID_SUFFIX_PATTERN = Pattern.compile("^[A-Z0-9_]{1,8}$");
|
||||||
|
|
||||||
public Builder setRoidSuffix(String roidSuffix) {
|
public Builder setRoidSuffix(String roidSuffix) {
|
||||||
|
checkArgument(
|
||||||
|
ROID_SUFFIX_PATTERN.matcher(roidSuffix).matches(),
|
||||||
|
"ROID suffix must be in format %s",
|
||||||
|
ROID_SUFFIX_PATTERN.pattern());
|
||||||
getInstance().roidSuffix = roidSuffix;
|
getInstance().roidSuffix = roidSuffix;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ package google.registry.model.registry;
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth.assertWithMessage;
|
import static com.google.common.truth.Truth.assertWithMessage;
|
||||||
import static com.google.common.truth.Truth8.assertThat;
|
|
||||||
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
import static google.registry.model.common.EntityGroupRoot.getCrossTldKey;
|
||||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||||
import static google.registry.model.registry.label.ReservedListTest.GET_NAME_FUNCTION;
|
import static google.registry.model.registry.label.ReservedListTest.GET_NAME_FUNCTION;
|
||||||
|
@ -29,6 +28,8 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||||
import static org.joda.money.CurrencyUnit.EUR;
|
import static org.joda.money.CurrencyUnit.EUR;
|
||||||
import static org.joda.money.CurrencyUnit.USD;
|
import static org.joda.money.CurrencyUnit.USD;
|
||||||
|
import static org.junit.Assert.assertThrows;
|
||||||
|
import static org.junit.Assert.expectThrows;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.ImmutableSortedMap;
|
import com.google.common.collect.ImmutableSortedMap;
|
||||||
|
@ -488,4 +489,27 @@ public class RegistryTest extends EntityTestCase {
|
||||||
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
.setEapFeeSchedule(ImmutableSortedMap.of(START_OF_TIME, Money.zero(EUR)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_roidSuffixTooLong() {
|
||||||
|
IllegalArgumentException e =
|
||||||
|
expectThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Registry.get("tld").asBuilder().setRoidSuffix("123456789"));
|
||||||
|
assertThat(e).hasMessageThat().isEqualTo("ROID suffix must be in format ^[A-Z0-9_]{1,8}$");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_roidSuffixNotUppercased() {
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Registry.get("tld").asBuilder().setRoidSuffix("abcd"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFailure_roidSuffixContainsInvalidCharacters() {
|
||||||
|
assertThrows(
|
||||||
|
IllegalArgumentException.class,
|
||||||
|
() -> Registry.get("tld").asBuilder().setRoidSuffix("ABC-DEF"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,10 +418,11 @@ public class DatastoreHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createTld(String tld, ImmutableSortedMap<DateTime, TldState> tldStates) {
|
public static void createTld(String tld, ImmutableSortedMap<DateTime, TldState> tldStates) {
|
||||||
createTld(
|
// Coerce the TLD string into a valid ROID suffix.
|
||||||
tld,
|
String roidSuffix =
|
||||||
Ascii.toUpperCase(tld.replaceFirst(ACE_PREFIX_REGEX, "").replace('.', '_')),
|
Ascii.toUpperCase(tld.replaceFirst(ACE_PREFIX_REGEX, "").replace('.', '_'))
|
||||||
tldStates);
|
.replace('-', '_');
|
||||||
|
createTld(tld, roidSuffix.length() > 8 ? roidSuffix.substring(0, 8) : roidSuffix, tldStates);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createTld(
|
public static void createTld(
|
||||||
|
|
|
@ -16,7 +16,6 @@ package google.registry.tools;
|
||||||
|
|
||||||
import static com.google.common.collect.Iterables.transform;
|
import static com.google.common.collect.Iterables.transform;
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static com.google.common.truth.Truth8.assertThat;
|
|
||||||
import static google.registry.model.registry.label.ReservedListTest.GET_NAME_FUNCTION;
|
import static google.registry.model.registry.label.ReservedListTest.GET_NAME_FUNCTION;
|
||||||
import static google.registry.testing.DatastoreHelper.createTld;
|
import static google.registry.testing.DatastoreHelper.createTld;
|
||||||
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
import static google.registry.testing.DatastoreHelper.persistPremiumList;
|
||||||
|
@ -78,13 +77,13 @@ public class CreateTldCommandTest extends CommandTestCase<CreateTldCommand> {
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_multipleArguments() throws Exception {
|
public void testFailure_multipleArguments() throws Exception {
|
||||||
thrown.expect(IllegalArgumentException.class, "Can't create more than one TLD at a time");
|
thrown.expect(IllegalArgumentException.class, "Can't create more than one TLD at a time");
|
||||||
runCommandForced("--roid_suffix=blah", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c", "test");
|
runCommandForced("--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "xn--q9jyb4c", "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_multipleDuplicateArguments() throws Exception {
|
public void testFailure_multipleDuplicateArguments() throws Exception {
|
||||||
thrown.expect(IllegalArgumentException.class, "Can't create more than one TLD at a time");
|
thrown.expect(IllegalArgumentException.class, "Can't create more than one TLD at a time");
|
||||||
runCommandForced("--roid_suffix=blah", "--dns_writers=VoidDnsWriter", "test", "test");
|
runCommandForced("--roid_suffix=BLAH", "--dns_writers=VoidDnsWriter", "test", "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue