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);
}
}