Make name and address fields required on Registrar

The absence of these fields causes RDE failures, so they are in effect
required on any functioning registry system. We are currently
experiencing problems in sandbox caused by null values on these fields.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=155474895
This commit is contained in:
mcilwain 2017-05-09 00:27:41 -07:00 committed by Ben McIlwain
parent 5313ca58d6
commit ef1487cb57
18 changed files with 460 additions and 272 deletions

View file

@ -32,6 +32,7 @@ import static google.registry.model.ofy.Ofy.RECOMMENDED_MEMCACHE_EXPIRATION;
import static google.registry.model.registry.Registries.assertTldsExist;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableSortedCopy;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static google.registry.util.X509Utils.getCertificateHash;
import static google.registry.util.X509Utils.loadCertificate;
import static java.nio.charset.StandardCharsets.UTF_8;
@ -849,7 +850,11 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
/** Build the registrar, nullifying empty fields. */
@Override
public Registrar build() {
checkNotNull(getInstance().type, "Registrar type cannot be null");
checkArgumentNotNull(getInstance().type, "Registrar type cannot be null");
checkArgumentNotNull(getInstance().registrarName, "Registrar name cannot be null");
checkArgument(
getInstance().localizedAddress != null || getInstance().internationalizedAddress != null,
"Must specify at least one of localized or internationalized address");
checkArgument(getInstance().type.isValidIanaId(getInstance().ianaIdentifier),
String.format("Supplied IANA ID is not valid for %s registrar type: %s",
getInstance().type, getInstance().ianaIdentifier));
@ -860,6 +865,7 @@ public class Registrar extends ImmutableObject implements Buildable, Jsonifiable
/** Load a registrar entity by its client id outside of a transaction. */
@Nullable
public static Registrar loadByClientId(final String clientId) {
checkNotNull(clientId, "Client ID cannot be null");
return ofy().doTransactionless(new Work<Registrar>() {
@Override
public Registrar run() {

View file

@ -15,7 +15,6 @@
package google.registry.tools;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Strings.emptyToNull;
import static com.google.common.collect.Iterables.filter;
@ -25,11 +24,11 @@ import static google.registry.model.registrar.Registrar.State.ACTIVE;
import static google.registry.tools.RegistryToolEnvironment.PRODUCTION;
import static google.registry.tools.RegistryToolEnvironment.SANDBOX;
import static google.registry.tools.RegistryToolEnvironment.UNITTEST;
import static google.registry.util.PreconditionsUtils.checkArgumentNotNull;
import static google.registry.util.RegistrarUtils.normalizeClientId;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet;
@ -45,10 +44,6 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
private static final ImmutableSet<RegistryToolEnvironment> ENVIRONMENTS_ALLOWING_GROUP_CREATION =
ImmutableSet.of(PRODUCTION, SANDBOX, UNITTEST);
// Allows test cases to be cleaner.
@VisibleForTesting
static boolean requireAddress = true;
@Parameter(
names = "--create_groups",
description = "Whether the Google Groups for this registrar should be created",
@ -65,12 +60,10 @@ final class CreateRegistrarCommand extends CreateOrUpdateRegistrarCommand
@Override
protected void initRegistrarCommand() throws Exception {
checkArgument(mainParameters.size() == 1, "Must specify exactly one client identifier.");
checkNotNull(emptyToNull(password), "--password is a required field");
checkNotNull(registrarName, "--name is a required field");
checkNotNull(icannReferralEmail, "--icann_referral_email is a required field");
if (requireAddress) {
checkNotNull(street, "Address fields are required when creating a registrar");
}
checkArgumentNotNull(emptyToNull(password), "--password is a required field");
checkArgumentNotNull(registrarName, "--name is a required field");
checkArgumentNotNull(icannReferralEmail, "--icann_referral_email is a required field");
checkArgumentNotNull(street, "Address fields are required when creating a registrar");
// Default new registrars to active.
registrarState = Optional.fromNullable(registrarState).or(ACTIVE);
}

View file

@ -66,7 +66,11 @@ final class DomainWhoisResponse extends WhoisResponseImpl {
@Override
public WhoisResponseResults getResponse(final boolean preferUnicode, String disclaimer) {
Registrar registrar = getRegistrar(domain.getCurrentSponsorClientId());
Registrar registrar =
checkNotNull(
Registrar.loadByClientId(domain.getCurrentSponsorClientId()),
"Could not load registrar %s",
domain.getCurrentSponsorClientId());
Optional<RegistrarContact> abuseContact =
Iterables.tryFind(
registrar.getContacts(),

View file

@ -53,7 +53,8 @@ final class NameserverWhoisResponse extends WhoisResponseImpl {
.cloneProjectedAtTime(getTimestamp())
.getCurrentSponsorClientId()
: host.getPersistedCurrentSponsorClientId();
Registrar registrar = getRegistrar(clientId);
Registrar registrar =
checkNotNull(Registrar.loadByClientId(clientId), "Could not load registrar %s", clientId);
emitter
.emitField(
"Server Name", maybeFormatHostname(host.getFullyQualifiedHostName(), preferUnicode))

View file

@ -21,12 +21,10 @@ import static com.google.common.html.HtmlEscapers.htmlEscaper;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Optional;
import com.google.common.base.Supplier;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
import google.registry.model.eppcommon.Address;
import google.registry.model.registrar.Registrar;
import google.registry.util.Idn;
import google.registry.xml.UtcDateTimeAdapter;
import java.util.Arrays;
@ -45,13 +43,6 @@ abstract class WhoisResponseImpl implements WhoisResponse {
/** ICANN problem reporting URL appended to all WHOIS responses. */
private static final String ICANN_REPORTING_URL = "https://www.icann.org/wicf/";
private static final Registrar EMPTY_REGISTRAR = new Supplier<Registrar>() {
@Override
public Registrar get() {
// Use Type.TEST here to avoid requiring an IANA ID (the type does not appear in WHOIS).
return new Registrar.Builder().setType(Registrar.Type.TEST).build();
}}.get();
/** The time at which this response was created. */
private final DateTime timestamp;
@ -196,11 +187,4 @@ abstract class WhoisResponseImpl implements WhoisResponse {
/** An emitter that needs no special logic. */
static class BasicEmitter extends Emitter<BasicEmitter> {}
/** Returns the registrar for this client id, or an empty registrar with null values. */
static Registrar getRegistrar(@Nullable String clientId) {
return Optional
.fromNullable(clientId == null ? null : Registrar.loadByClientId(clientId))
.or(EMPTY_REGISTRAR);
}
}

View file

@ -22,6 +22,7 @@ import static google.registry.model.common.Cursor.CursorType.SYNC_REGISTRAR_SHEE
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
import static org.joda.time.DateTimeZone.UTC;
@ -94,13 +95,7 @@ public class SyncRegistrarsSheetTest {
@Test
public void test_wereRegistrarsModified_atDifferentCursorTimes() throws Exception {
persistResource(new Registrar.Builder()
.setClientId("SomeRegistrar")
.setRegistrarName("Some Registrar Inc.")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(8L)
.setState(Registrar.State.ACTIVE)
.build());
persistNewRegistrar("SomeRegistrar", "Some Registrar Inc.", Registrar.Type.REAL, 8L);
persistResource(Cursor.createGlobal(SYNC_REGISTRAR_SHEET, clock.nowUtc().minusHours(1)));
assertThat(newSyncRegistrarsSheet().wereRegistrarsModified()).isTrue();
persistResource(Cursor.createGlobal(SYNC_REGISTRAR_SHEET, clock.nowUtc().plusHours(1)));
@ -327,18 +322,14 @@ public class SyncRegistrarsSheetTest {
@Test
public void testRun_missingValues_stillWorks() throws Exception {
persistResource(new Registrar.Builder()
.setClientId("SomeRegistrar")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(8L)
.build());
persistNewRegistrar("SomeRegistrar", "Some Registrar", Registrar.Type.REAL, 8L);
newSyncRegistrarsSheet().run("foobar");
verify(sheetSynchronizer).synchronize(eq("foobar"), rowsCaptor.capture());
ImmutableMap<String, String> row = getOnlyElement(getOnlyElement(rowsCaptor.getAllValues()));
assertThat(row).containsEntry("clientIdentifier", "SomeRegistrar");
assertThat(row).containsEntry("registrarName", "");
assertThat(row).containsEntry("registrarName", "Some Registrar");
assertThat(row).containsEntry("state", "");
assertThat(row).containsEntry("ianaIdentifier", "8");
assertThat(row).containsEntry("billingIdentifier", "");
@ -352,8 +343,8 @@ public class SyncRegistrarsSheetTest {
assertThat(row).containsEntry("contactsMarkedAsWhoisAdmin", "");
assertThat(row).containsEntry("contactsMarkedAsWhoisTech", "");
assertThat(row).containsEntry("emailAddress", "");
assertThat(row).containsEntry("address.street", "UNKNOWN");
assertThat(row).containsEntry("address.city", "UNKNOWN");
assertThat(row).containsEntry("address.street", "123 Fake St");
assertThat(row).containsEntry("address.city", "Fakington");
assertThat(row).containsEntry("address.state", "");
assertThat(row).containsEntry("address.zip", "");
assertThat(row).containsEntry("address.countryCode", "US");

View file

@ -16,6 +16,7 @@ package google.registry.model.ofy;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.initOfy;
import static google.registry.testing.DatastoreHelper.newContactResource;
import static org.junit.Assert.fail;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
@ -26,8 +27,7 @@ import com.googlecode.objectify.ObjectifyFilter;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.Registrar.Type;
import google.registry.model.contact.ContactResource;
import google.registry.testing.ExceptionRule;
import org.junit.After;
import org.junit.Before;
@ -93,9 +93,8 @@ public class OfyFilterTest {
@Test
public void testKeyCreateAfterFilter() throws Exception {
new OfyFilter().init(null);
Registrar registrar =
new Registrar.Builder().setType(Type.TEST).setClientId("clientId").build();
Key.create(registrar);
ContactResource contact = newContactResource("contact1234");
Key.create(contact);
}
@Entity

View file

@ -314,8 +314,26 @@ public class RegistrarTest extends EntityTestCase {
@Test
public void testFailure_missingRegistrarType() throws Exception {
thrown.expect(NullPointerException.class);
new Registrar.Builder().build();
thrown.expect(IllegalArgumentException.class, "Registrar type cannot be null");
new Registrar.Builder().setRegistrarName("blah").build();
}
@Test
public void testFailure_missingRegistrarName() throws Exception {
thrown.expect(IllegalArgumentException.class, "Registrar name cannot be null");
new Registrar.Builder().setClientId("blahid").setType(Registrar.Type.TEST).build();
}
@Test
public void testFailure_missingAddress() throws Exception {
thrown.expect(
IllegalArgumentException.class,
"Must specify at least one of localized or internationalized address");
new Registrar.Builder()
.setClientId("blahid")
.setType(Registrar.Type.TEST)
.setRegistrarName("Blah Co")
.build();
}
@Test

View file

@ -20,8 +20,6 @@ import google.registry.model.registrar.Registrar;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ShardableTestCase;
import google.registry.xml.XmlTestUtils;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -82,46 +80,10 @@ public class RdeMarshallerTest extends ShardableTestCase {
"registrar.upDate");
}
@Test
public void testMarshalRegistrar_breaksRdeXmlSchema_producesErrorMessage() throws Exception {
Registrar reg = Registrar.loadByClientId("TheRegistrar").asBuilder()
.setLocalizedAddress(null)
.setInternationalizedAddress(null)
.build();
DepositFragment fragment = new RdeMarshaller().marshalRegistrar(reg);
assertThat(fragment.type()).isEqualTo(RdeResourceType.REGISTRAR);
assertThat(fragment.xml()).isEmpty();
assertThat(fragment.error()).isEqualTo(""
+ "RDE XML schema validation failed: "
+ "Key<?>(EntityGroupRoot(\"cross-tld\")/Registrar(\"TheRegistrar\"))\n"
+ "org.xml.sax.SAXParseException; lineNumber: 0; columnNumber: 0; cvc-complex-type.2.4.a: "
+ "Invalid content was found starting with element 'rdeRegistrar:voice'. "
+ "One of '{\"urn:ietf:params:xml:ns:rdeRegistrar-1.0\":postalInfo}' is expected.\n"
+ "<rdeRegistrar:registrar>\n"
+ " <rdeRegistrar:id>TheRegistrar</rdeRegistrar:id>\n"
+ " <rdeRegistrar:name>The Registrar</rdeRegistrar:name>\n"
+ " <rdeRegistrar:gurid>1</rdeRegistrar:gurid>\n"
+ " <rdeRegistrar:status>ok</rdeRegistrar:status>\n"
+ " <rdeRegistrar:voice>+1.2223334444</rdeRegistrar:voice>\n"
+ " <rdeRegistrar:email>new.registrar@example.com</rdeRegistrar:email>\n"
+ " <rdeRegistrar:whoisInfo>\n"
+ " <rdeRegistrar:name>whois.nic.fakewhois.example</rdeRegistrar:name>\n"
+ " </rdeRegistrar:whoisInfo>\n"
+ " <rdeRegistrar:crDate>" + ft(reg.getCreationTime()) + "</rdeRegistrar:crDate>\n"
+ " <rdeRegistrar:upDate>" + ft(reg.getLastUpdateTime()) + "</rdeRegistrar:upDate>\n"
+ "</rdeRegistrar:registrar>\n"
+ "\n");
}
@Test
public void testMarshalRegistrar_unicodeCharacters_dontGetMangled() throws Exception {
DepositFragment fragment =
new RdeMarshaller().marshalRegistrar(Registrar.loadByClientId("TheRegistrar"));
assertThat(fragment.xml()).contains("123 Example Bőulevard");
}
/** Formats {@code timestamp} without milliseconds. */
private static String ft(DateTime timestamp) {
return ISODateTimeFormat.dateTimeNoMillis().withZoneUTC().print(timestamp);
}
}

View file

@ -47,6 +47,7 @@ import google.registry.model.host.HostResource;
import google.registry.model.index.EppResourceIndex;
import google.registry.model.index.EppResourceIndexBucket;
import google.registry.model.index.ForeignKeyIndex;
import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry.TldState;
import google.registry.testing.AppEngineRule;
import google.registry.testing.ExceptionRule;
@ -96,7 +97,7 @@ public class RdeImportUtilsTest extends ShardableTestCase {
rdeImportUtils = new RdeImportUtils(ofy(), clock, "import-bucket", gcsUtils);
createTld("test", TldState.PREDELEGATION);
createTld("getld", TldState.GENERAL_AVAILABILITY);
persistNewRegistrar("RegistrarX", 1L);
persistNewRegistrar("RegistrarX", "RegistrarX", Registrar.Type.REAL, 1L);
}
@After
@ -287,8 +288,8 @@ public class RdeImportUtilsTest extends ShardableTestCase {
.setContacts(ImmutableSet.of(
DesignatedContact.create(Type.ADMIN, Key.create(admin)),
DesignatedContact.create(Type.TECH, Key.create(admin))))
.setPersistedCurrentSponsorClientId("RegistrarX")
.setCreationClientId("RegistrarX")
.setPersistedCurrentSponsorClientId("registrarx")
.setCreationClientId("registrarx")
.setCreationTime(DateTime.parse("1999-04-03T22:00:00.0Z"))
.setRegistrationExpirationTime(DateTime.parse("2015-04-03T22:00:00.0Z"))
.build();

View file

@ -83,6 +83,7 @@ import google.registry.model.ofy.ObjectifyService;
import google.registry.model.poll.PollMessage;
import google.registry.model.pricing.StaticPremiumListPricingEngine;
import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarAddress;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.Registry.TldType;
@ -611,13 +612,21 @@ public class DatastoreHelper {
.build());
}
/** Creates a stripped-down {@link Registrar} with the specified clientId and ianaIdentifier */
public static Registrar persistNewRegistrar(String clientId, long ianaIdentifier) {
/** Persists and returns a {@link Registrar} with the specified attributes. */
public static Registrar persistNewRegistrar(
String clientId, String registrarName, Registrar.Type type, long ianaIdentifier) {
return persistSimpleResource(
new Registrar.Builder()
.setClientId(clientId)
.setType(Registrar.Type.REAL)
.setRegistrarName(registrarName)
.setType(type)
.setIanaIdentifier(ianaIdentifier)
.setLocalizedAddress(
new RegistrarAddress.Builder()
.setStreet(ImmutableList.of("123 Fake St"))
.setCity("Fakington")
.setCountryCode("US")
.build())
.build());
}

View file

@ -130,7 +130,8 @@ public final class FullFieldsTestEntityHelper {
HostResource.Builder builder = new HostResource.Builder()
.setRepoId(generateNewContactHostRoid())
.setFullyQualifiedHostName(Idn.toASCII(fqhn))
.setCreationTimeForTest(DateTime.parse("2000-10-08T00:45:00Z"));
.setCreationTimeForTest(DateTime.parse("2000-10-08T00:45:00Z"))
.setPersistedCurrentSponsorClientId("TheRegistrar");
if ((ip1 != null) || (ip2 != null)) {
ImmutableSet.Builder<InetAddress> ipBuilder = new ImmutableSet.Builder<>();
if (ip1 != null) {

View file

@ -23,6 +23,7 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import com.google.common.collect.ImmutableMap;
import com.google.common.net.MediaType;
import google.registry.model.registrar.Registrar;
import google.registry.tools.ServerSideCommand.Connection;
import org.junit.Before;
import org.junit.Test;
@ -37,7 +38,7 @@ public class LoadTestCommandTest extends CommandTestCase<LoadTestCommand> {
public void setUp() throws Exception {
command.setConnection(connection);
createTld("example");
persistNewRegistrar("acme", 99);
persistNewRegistrar("acme", "ACME", Registrar.Type.REAL, 99L);
}
@Test

View file

@ -20,6 +20,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.persistActiveHost;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static org.joda.time.DateTimeZone.UTC;
@ -58,16 +59,8 @@ public class MutatingCommandTest {
@Before
public void init() {
registrar1 = persistResource(new Registrar.Builder()
.setType(Registrar.Type.REAL)
.setClientId("Registrar1")
.setIanaIdentifier(1L)
.build());
registrar2 = persistResource(new Registrar.Builder()
.setType(Registrar.Type.REAL)
.setClientId("Registrar2")
.setIanaIdentifier(2L)
.build());
registrar1 = persistNewRegistrar("Registrar1", "Registrar1", Registrar.Type.REAL, 1L);
registrar2 = persistNewRegistrar("Registrar2", "Registrar2", Registrar.Type.REAL, 2L);
newRegistrar1 = registrar1.asBuilder().setBillingIdentifier(42L).build();
newRegistrar2 = registrar2.asBuilder().setBlockPremiumNames(true).build();

View file

@ -16,7 +16,7 @@ package google.registry.whois;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.whois.WhoisHelper.loadWhoisTestFile;
import com.google.common.collect.ImmutableList;
@ -50,13 +50,7 @@ public class NameserverWhoisResponseTest {
@Before
public void setUp() {
persistResource(new Registrar.Builder()
.setClientId("example")
.setRegistrarName("Example Registrar, Inc.")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(8L)
.build());
persistNewRegistrar("example", "Example Registrar, Inc.", Registrar.Type.REAL, 8L);
createTld("tld");
hostResource1 = new HostResource.Builder()

View file

@ -15,6 +15,7 @@
package google.registry.whois;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.testing.DatastoreHelper.persistNewRegistrar;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DatastoreHelper.persistSimpleResources;
import static google.registry.whois.WhoisHelper.loadWhoisTestFile;
@ -120,12 +121,8 @@ public class RegistrarWhoisResponseTest {
@Test
public void testSetOfFields() {
Registrar registrar = new Registrar.Builder()
.setClientId("exregistrar")
.setType(Registrar.Type.REAL)
.setIanaIdentifier(8L)
.setState(Registrar.State.ACTIVE)
.build();
Registrar registrar =
persistNewRegistrar("exregistrar", "Ex-Registrar", Registrar.Type.REAL, 8L);
RegistrarWhoisResponse registrarWhoisResponse =
new RegistrarWhoisResponse(registrar, clock.nowUtc());

View file

@ -1,6 +1,6 @@
Server Name: ns1.cat.lol
IP Address: 1.2.3.4
Registrar:
Registrar: The Registrar
Registrar WHOIS Server: whois.nic.fakewhois.example
Registrar URL: http://www.referral.example/path
>>> Last update of WHOIS database: 2009-06-29T20:13:00Z <<<