Handle sunrise reservations properly during sunrise TLDs

We figure out the TLD state so that we properly check whether or not we can provision sunrise domains in that TLD. We also change the message slightly so that it's a bit more clear when we aren't in sunrise.

Note: it is deliberate that NAME_COLLISION reservations are provisionable in sunrise.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=232742813
This commit is contained in:
gbrodman 2019-02-06 14:08:00 -08:00 committed by jianglai
parent abe8a0ca0f
commit 93ff541006
15 changed files with 57 additions and 52 deletions

View file

@ -20,15 +20,18 @@ import static google.registry.flows.ResourceFlowUtils.verifyTargetIdCount;
import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToTld; import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToTld;
import static google.registry.flows.domain.DomainFlowUtils.getReservationTypes; import static google.registry.flows.domain.DomainFlowUtils.getReservationTypes;
import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest; import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import static google.registry.flows.domain.DomainFlowUtils.isReserved;
import static google.registry.flows.domain.DomainFlowUtils.validateDomainName; import static google.registry.flows.domain.DomainFlowUtils.validateDomainName;
import static google.registry.flows.domain.DomainFlowUtils.validateDomainNameWithIdnTables; import static google.registry.flows.domain.DomainFlowUtils.validateDomainNameWithIdnTables;
import static google.registry.flows.domain.DomainFlowUtils.verifyNotInPredelegation; import static google.registry.flows.domain.DomainFlowUtils.verifyNotInPredelegation;
import static google.registry.model.EppResourceUtils.checkResourcesExist; import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.registry.Registry.TldState.START_DATE_SUNRISE;
import static google.registry.model.registry.label.ReservationType.getTypeOfHighestSeverity; import static google.registry.model.registry.label.ReservationType.getTypeOfHighestSeverity;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import google.registry.config.RegistryConfig.Config; import google.registry.config.RegistryConfig.Config;
import google.registry.flows.EppException; import google.registry.flows.EppException;
@ -56,11 +59,13 @@ import google.registry.model.eppoutput.CheckData.DomainCheckData;
import google.registry.model.eppoutput.EppResponse; import google.registry.model.eppoutput.EppResponse;
import google.registry.model.eppoutput.EppResponse.ResponseExtension; import google.registry.model.eppoutput.EppResponse.ResponseExtension;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.registry.label.ReservationType; import google.registry.model.registry.label.ReservationType;
import google.registry.model.reporting.IcannReportingTypes.ActivityReportField; import google.registry.model.reporting.IcannReportingTypes.ActivityReportField;
import google.registry.util.Clock; import google.registry.util.Clock;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
@ -153,9 +158,11 @@ public final class DomainCheckFlow implements Flow {
now) now)
: ImmutableMap.of(); : ImmutableMap.of();
ImmutableList.Builder<DomainCheck> checks = new ImmutableList.Builder<>(); ImmutableList.Builder<DomainCheck> checks = new ImmutableList.Builder<>();
ImmutableMap<String, TldState> tldStates =
Maps.toMap(seenTlds, tld -> Registry.get(tld).getTldState(now));
for (String targetId : targetIds) { for (String targetId : targetIds) {
Optional<String> message = Optional<String> message =
getMessageForCheck(domainNames.get(targetId), existingIds, tokenCheckResults); getMessageForCheck(domainNames.get(targetId), existingIds, tokenCheckResults, tldStates);
checks.add(DomainCheck.create(!message.isPresent(), targetId, message.orElse(null))); checks.add(DomainCheck.create(!message.isPresent(), targetId, message.orElse(null)));
} }
BeforeResponseReturnData responseData = BeforeResponseReturnData responseData =
@ -174,14 +181,18 @@ public final class DomainCheckFlow implements Flow {
private Optional<String> getMessageForCheck( private Optional<String> getMessageForCheck(
InternetDomainName domainName, InternetDomainName domainName,
Set<String> existingIds, Set<String> existingIds,
ImmutableMap<InternetDomainName, String> tokenCheckResults) { ImmutableMap<InternetDomainName, String> tokenCheckResults,
Map<String, TldState> tldStates) {
if (existingIds.contains(domainName.toString())) { if (existingIds.contains(domainName.toString())) {
return Optional.of("In use"); return Optional.of("In use");
} }
TldState tldState = tldStates.get(domainName.parent().toString());
if (isReserved(domainName, START_DATE_SUNRISE.equals(tldState))) {
ImmutableSet<ReservationType> reservationTypes = getReservationTypes(domainName); ImmutableSet<ReservationType> reservationTypes = getReservationTypes(domainName);
if (!reservationTypes.isEmpty()) { if (!reservationTypes.isEmpty()) {
return Optional.of(getTypeOfHighestSeverity(reservationTypes).getMessageForCheck()); return Optional.of(getTypeOfHighestSeverity(reservationTypes).getMessageForCheck());
} }
}
return Optional.ofNullable(emptyToNull(tokenCheckResults.get(domainName))); return Optional.ofNullable(emptyToNull(tokenCheckResults.get(domainName)));
} }

View file

@ -38,7 +38,7 @@ public enum ReservationType {
NAMESERVER_RESTRICTED("Nameserver restricted", 0), NAMESERVER_RESTRICTED("Nameserver restricted", 0),
/** The domain can only be registered during sunrise, and is reserved thereafter. */ /** The domain can only be registered during sunrise, and is reserved thereafter. */
ALLOWED_IN_SUNRISE("Reserved for non-sunrise", 1), ALLOWED_IN_SUNRISE("Reserved", 1),
/** The domain can only be registered by providing a specific token. */ /** The domain can only be registered by providing a specific token. */
RESERVED_FOR_SPECIFIC_USE("Reserved", 2), RESERVED_FOR_SPECIFIC_USE("Reserved", 2),

View file

@ -170,16 +170,28 @@ public class DomainCheckFlowTest
create(false, "collision.tld", "Cannot be delegated"), create(false, "collision.tld", "Cannot be delegated"),
create(false, "reserved.tld", "Reserved"), create(false, "reserved.tld", "Reserved"),
create(false, "anchor.tld", "Reserved"), create(false, "anchor.tld", "Reserved"),
create(false, "allowedinsunrise.tld", "Reserved for non-sunrise"), create(false, "allowedinsunrise.tld", "Reserved"),
create(false, "premiumcollision.tld", "Cannot be delegated")); create(false, "premiumcollision.tld", "Cannot be delegated"));
} }
@Test @Test
public void testSuccess_oneReserved() throws Exception { public void testSuccess_oneReservedInSunrise() throws Exception {
createTld("tld", START_DATE_SUNRISE);
persistResource(Registry.get("tld").asBuilder().setReservedLists(createReservedList()).build());
setEppInput("domain_check_one_tld_reserved.xml"); setEppInput("domain_check_one_tld_reserved.xml");
doCheckTest( doCheckTest(
create(false, "reserved.tld", "Reserved"), create(false, "reserved.tld", "Reserved"),
create(false, "allowedinsunrise.tld", "Reserved for non-sunrise"), create(true, "allowedinsunrise.tld", null),
create(true, "example2.tld", null),
create(true, "example3.tld", null));
}
@Test
public void testSuccess_twoReservedOutsideSunrise() throws Exception {
setEppInput("domain_check_one_tld_reserved.xml");
doCheckTest(
create(false, "reserved.tld", "Reserved"),
create(false, "allowedinsunrise.tld", "Reserved"),
create(true, "example2.tld", null), create(true, "example2.tld", null),
create(true, "example3.tld", null)); create(true, "example3.tld", null));
} }
@ -221,7 +233,7 @@ public class DomainCheckFlowTest
setEppInput("domain_check_one_multipart_tld_reserved.xml"); setEppInput("domain_check_one_multipart_tld_reserved.xml");
doCheckTest( doCheckTest(
create(false, "reserved.tld.foo", "Reserved"), create(false, "reserved.tld.foo", "Reserved"),
create(false, "allowedinsunrise.tld.foo", "Reserved for non-sunrise"), create(false, "allowedinsunrise.tld.foo", "Reserved"),
create(true, "example2.tld.foo", null), create(true, "example2.tld.foo", null),
create(true, "example3.tld.foo", null)); create(true, "example3.tld.foo", null));
} }

View file

@ -11,7 +11,7 @@
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="0">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="0">collision.tld</domain:name>

View file

@ -11,7 +11,7 @@
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="0">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="0">collision.tld</domain:name>

View file

@ -11,7 +11,7 @@
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="0">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="0">collision.tld</domain:name>

View file

@ -11,7 +11,7 @@
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="0">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="0">collision.tld</domain:name>

View file

@ -11,7 +11,7 @@
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="0">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="0">collision.tld</domain:name>

View file

@ -11,7 +11,7 @@
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="0">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="0">collision.tld</domain:name>

View file

@ -10,16 +10,13 @@
<domain:reason>Reserved</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="1">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="1">collision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">premiumcollision.tld</domain:name> <domain:name avail="1">premiumcollision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
</domain:chkData> </domain:chkData>
</resData> </resData>

View file

@ -10,16 +10,13 @@
<domain:reason>Reserved</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="1">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="1">collision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">premiumcollision.tld</domain:name> <domain:name avail="1">premiumcollision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
</domain:chkData> </domain:chkData>
</resData> </resData>

View file

@ -10,16 +10,13 @@
<domain:reason>Reserved</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="1">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="1">collision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">premiumcollision.tld</domain:name> <domain:name avail="1">premiumcollision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
</domain:chkData> </domain:chkData>
</resData> </resData>

View file

@ -10,16 +10,13 @@
<domain:reason>Reserved</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="1">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="1">collision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">premiumcollision.tld</domain:name> <domain:name avail="1">premiumcollision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
</domain:chkData> </domain:chkData>
</resData> </resData>

View file

@ -10,16 +10,13 @@
<domain:reason>Reserved</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="1">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="1">collision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">premiumcollision.tld</domain:name> <domain:name avail="1">premiumcollision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
</domain:chkData> </domain:chkData>
</resData> </resData>

View file

@ -10,16 +10,13 @@
<domain:reason>Reserved</domain:reason> <domain:reason>Reserved</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">allowedinsunrise.tld</domain:name> <domain:name avail="1">allowedinsunrise.tld</domain:name>
<domain:reason>Reserved for non-sunrise</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">collision.tld</domain:name> <domain:name avail="1">collision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
<domain:cd> <domain:cd>
<domain:name avail="0">premiumcollision.tld</domain:name> <domain:name avail="1">premiumcollision.tld</domain:name>
<domain:reason>Cannot be delegated</domain:reason>
</domain:cd> </domain:cd>
</domain:chkData> </domain:chkData>
</resData> </resData>