Flatten the domain check flows

Also pull out a small bit of common functionality across contact and host checks.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133977324
This commit is contained in:
cgoldfeder 2016-09-22 11:24:57 -07:00 committed by Ben McIlwain
parent b5e421cee3
commit 025a4ae012
7 changed files with 161 additions and 101 deletions

View file

@ -39,6 +39,7 @@ import google.registry.flows.exceptions.ResourceStatusProhibitsOperationExceptio
import google.registry.flows.exceptions.ResourceToDeleteIsReferencedException; import google.registry.flows.exceptions.ResourceToDeleteIsReferencedException;
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException; import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
import google.registry.flows.exceptions.ResourceToQueryDoesNotExistException; import google.registry.flows.exceptions.ResourceToQueryDoesNotExistException;
import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.EppResource; import google.registry.model.EppResource;
import google.registry.model.EppResource.Builder; import google.registry.model.EppResource.Builder;
import google.registry.model.EppResource.ForeignKeyedEppResource; import google.registry.model.EppResource.ForeignKeyedEppResource;
@ -316,13 +317,6 @@ public class ResourceFlowUtils {
} }
} }
/** The specified resource belongs to another client. */
public static class ResourceNotOwnedException extends AuthorizationErrorException {
public ResourceNotOwnedException() {
super("The specified resource belongs to another client");
}
}
/** Check that the given AuthInfo is either missing or else is valid for the given resource. */ /** Check that the given AuthInfo is either missing or else is valid for the given resource. */
public static void verifyOptionalAuthInfoForResource( public static void verifyOptionalAuthInfoForResource(
Optional<AuthInfo> authInfo, EppResource resource) throws EppException { Optional<AuthInfo> authInfo, EppResource resource) throws EppException {
@ -359,6 +353,21 @@ public class ResourceFlowUtils {
} }
} }
/** Get the list of target ids from a check command. */
public static void verifyTargetIdCount(List<String> targetIds, int maxChecks)
throws TooManyResourceChecksException {
if (targetIds.size() > maxChecks) {
throw new TooManyResourceChecksException(maxChecks);
}
}
/** The specified resource belongs to another client. */
public static class ResourceNotOwnedException extends AuthorizationErrorException {
public ResourceNotOwnedException() {
super("The specified resource belongs to another client");
}
}
/** Authorization information for accessing resource is invalid. */ /** Authorization information for accessing resource is invalid. */
public static class BadAuthInfoForResourceException public static class BadAuthInfoForResourceException
extends InvalidAuthorizationInformationErrorException { extends InvalidAuthorizationInformationErrorException {

View file

@ -14,6 +14,7 @@
package google.registry.flows.contact; package google.registry.flows.contact;
import static google.registry.flows.ResourceFlowUtils.verifyTargetIdCount;
import static google.registry.model.EppResourceUtils.checkResourcesExist; import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.eppoutput.Result.Code.SUCCESS; import static google.registry.model.eppoutput.Result.Code.SUCCESS;
@ -21,7 +22,6 @@ import com.google.common.collect.ImmutableList;
import google.registry.config.ConfigModule.Config; import google.registry.config.ConfigModule.Config;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.LoggedInFlow; import google.registry.flows.LoggedInFlow;
import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.contact.ContactCommand.Check; import google.registry.model.contact.ContactCommand.Check;
import google.registry.model.contact.ContactResource; import google.registry.model.contact.ContactResource;
import google.registry.model.eppinput.ResourceCommand; import google.registry.model.eppinput.ResourceCommand;
@ -48,9 +48,7 @@ public final class ContactCheckFlow extends LoggedInFlow {
@Override @Override
public final EppOutput run() throws EppException { public final EppOutput run() throws EppException {
List<String> targetIds = ((Check) resourceCommand).getTargetIds(); List<String> targetIds = ((Check) resourceCommand).getTargetIds();
if (targetIds.size() > maxChecks) { verifyTargetIdCount(targetIds, maxChecks);
throw new TooManyResourceChecksException(maxChecks);
}
Set<String> existingIds = checkResourcesExist(ContactResource.class, targetIds, now); Set<String> existingIds = checkResourcesExist(ContactResource.class, targetIds, now);
ImmutableList.Builder<ContactCheck> checks = new ImmutableList.Builder<>(); ImmutableList.Builder<ContactCheck> checks = new ImmutableList.Builder<>();
for (String id : targetIds) { for (String id : targetIds) {

View file

@ -14,69 +14,86 @@
package google.registry.flows.domain; package google.registry.flows.domain;
import static google.registry.flows.ResourceFlowUtils.verifyTargetIdCount;
import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToTld;
import static google.registry.flows.domain.DomainFlowUtils.validateDomainName;
import static google.registry.flows.domain.DomainFlowUtils.validateDomainNameWithIdnTables;
import static google.registry.model.domain.launch.LaunchPhase.CLAIMS; import static google.registry.model.domain.launch.LaunchPhase.CLAIMS;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.util.DateTimeUtils.isAtOrAfter; import static google.registry.util.DateTimeUtils.isAtOrAfter;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import google.registry.config.ConfigModule.Config;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.LoggedInFlow;
import google.registry.flows.exceptions.BadCommandForRegistryPhaseException;
import google.registry.model.domain.DomainCommand.Check;
import google.registry.model.domain.launch.LaunchCheckExtension; import google.registry.model.domain.launch.LaunchCheckExtension;
import google.registry.model.domain.launch.LaunchCheckResponseExtension; import google.registry.model.domain.launch.LaunchCheckResponseExtension;
import google.registry.model.domain.launch.LaunchCheckResponseExtension.LaunchCheck; import google.registry.model.domain.launch.LaunchCheckResponseExtension.LaunchCheck;
import google.registry.model.domain.launch.LaunchCheckResponseExtension.LaunchCheckName; import google.registry.model.domain.launch.LaunchCheckResponseExtension.LaunchCheckName;
import google.registry.model.eppoutput.CheckData; import google.registry.model.eppinput.ResourceCommand;
import google.registry.model.eppoutput.EppResponse.ResponseExtension; import google.registry.model.eppoutput.EppOutput;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState; import google.registry.model.registry.Registry.TldState;
import google.registry.model.tmch.ClaimsListShard; import google.registry.model.tmch.ClaimsListShard;
import java.util.Map.Entry; import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
/** /**
* An EPP flow that checks whether strings are trademarked. * An EPP flow that checks whether strings are trademarked.
* *
* @error {@link google.registry.flows.ResourceCheckFlow.TooManyResourceChecksException}
* @error {@link google.registry.flows.ResourceFlow.BadCommandForRegistryPhaseException}
* @error {@link google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException} * @error {@link google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException}
* @error {@link google.registry.flows.exceptions.BadCommandForRegistryPhaseException}
* @error {@link google.registry.flows.exceptions.TooManyResourceChecksException}
* @error {@link DomainFlowUtils.TldDoesNotExistException} * @error {@link DomainFlowUtils.TldDoesNotExistException}
*/ */
public class ClaimsCheckFlow extends BaseDomainCheckFlow { public final class ClaimsCheckFlow extends LoggedInFlow {
public static final ImmutableSet<TldState> DISALLOWED_TLD_STATES = Sets.immutableEnumSet( public static final ImmutableSet<TldState> DISALLOWED_TLD_STATES =
TldState.PREDELEGATION, TldState.SUNRISE); Sets.immutableEnumSet(TldState.PREDELEGATION, TldState.SUNRISE);
@Inject ResourceCommand resourceCommand;
@Inject @Config("maxChecks") int maxChecks;
@Inject ClaimsCheckFlow() {} @Inject ClaimsCheckFlow() {}
@Override @Override
protected void initDomainCheckFlow() throws EppException { protected final void initLoggedInFlow() throws EppException {
registerExtensions(LaunchCheckExtension.class); registerExtensions(LaunchCheckExtension.class);
} }
@Override @Override
protected CheckData getCheckData() { public EppOutput run() throws EppException {
return null; List<String> targetIds = ((Check) resourceCommand).getTargetIds();
} verifyTargetIdCount(targetIds, maxChecks);
Set<String> seenTlds = new HashSet<>();
@Override
protected ImmutableList<? extends ResponseExtension> getResponseExtensions() throws EppException {
ImmutableList.Builder<LaunchCheck> launchChecksBuilder = new ImmutableList.Builder<>(); ImmutableList.Builder<LaunchCheck> launchChecksBuilder = new ImmutableList.Builder<>();
for (Entry<String, InternetDomainName> entry : domainNames.entrySet()) { for (String targetId : ImmutableSet.copyOf(targetIds)) {
InternetDomainName domainName = entry.getValue(); InternetDomainName domainName = validateDomainName(targetId);
if (isAtOrAfter(now, Registry.get(domainName.parent().toString()).getClaimsPeriodEnd())) { validateDomainNameWithIdnTables(domainName);
throw new BadCommandForRegistryPhaseException(); String tld = domainName.parent().toString();
// Only validate access to a TLD the first time it is encountered.
if (seenTlds.add(tld)) {
checkAllowedAccessToTld(getAllowedTlds(), tld);
Registry registry = Registry.get(tld);
if ((!isSuperuser && DISALLOWED_TLD_STATES.contains(registry.getTldState(now)))
|| isAtOrAfter(now, registry.getClaimsPeriodEnd())) {
throw new BadCommandForRegistryPhaseException();
}
} }
String claimKey = ClaimsListShard.get().getClaimKey(domainName.parts().get(0)); String claimKey = ClaimsListShard.get().getClaimKey(domainName.parts().get(0));
launchChecksBuilder.add(LaunchCheck.create( launchChecksBuilder.add(
LaunchCheckName.create(claimKey != null, entry.getKey()), claimKey)); LaunchCheck.create(
LaunchCheckName.create(claimKey != null, targetId), claimKey));
} }
return ImmutableList.of( return createOutput(
LaunchCheckResponseExtension.create(CLAIMS, launchChecksBuilder.build())); SUCCESS,
} null,
ImmutableList.of(LaunchCheckResponseExtension.create(CLAIMS, launchChecksBuilder.build())));
@Override
protected final ImmutableSet<TldState> getDisallowedTldStates() {
return DISALLOWED_TLD_STATES;
} }
} }

View file

@ -14,11 +14,16 @@
package google.registry.flows.domain; package google.registry.flows.domain;
import static google.registry.flows.ResourceFlowUtils.verifyTargetIdCount;
import static google.registry.flows.domain.DomainFlowUtils.checkAllowedAccessToTld;
import static google.registry.flows.domain.DomainFlowUtils.getReservationType; import static google.registry.flows.domain.DomainFlowUtils.getReservationType;
import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest; import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import static google.registry.flows.domain.DomainFlowUtils.validateDomainName;
import static google.registry.flows.domain.DomainFlowUtils.validateDomainNameWithIdnTables;
import static google.registry.model.EppResourceUtils.checkResourcesExist; import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.domain.fee.Fee.FEE_CHECK_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER; import static google.registry.model.domain.fee.Fee.FEE_CHECK_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER;
import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS; import static google.registry.model.domain.fee.Fee.FEE_EXTENSION_URIS;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName; import static google.registry.model.index.DomainApplicationIndex.loadActiveApplicationsByDomainName;
import static google.registry.model.registry.label.ReservationType.UNRESERVED; import static google.registry.model.registry.label.ReservationType.UNRESERVED;
import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName; import static google.registry.pricing.PricingEngineProxy.getPricesForDomainName;
@ -27,33 +32,44 @@ import static google.registry.util.CollectionUtils.nullToEmpty;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.net.InternetDomainName; import com.google.common.net.InternetDomainName;
import google.registry.config.ConfigModule.Config;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.EppException.ParameterValuePolicyErrorException; import google.registry.flows.EppException.ParameterValuePolicyErrorException;
import google.registry.flows.FlowModule.ClientId;
import google.registry.flows.LoggedInFlow;
import google.registry.flows.exceptions.BadCommandForRegistryPhaseException;
import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainCommand.Check;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.fee.FeeCheckCommandExtension; import google.registry.model.domain.fee.FeeCheckCommandExtension;
import google.registry.model.domain.fee.FeeCheckCommandExtensionItem; import google.registry.model.domain.fee.FeeCheckCommandExtensionItem;
import google.registry.model.domain.fee.FeeCheckResponseExtension;
import google.registry.model.domain.fee.FeeCheckResponseExtensionItem; import google.registry.model.domain.fee.FeeCheckResponseExtensionItem;
import google.registry.model.domain.launch.LaunchCheckExtension; import google.registry.model.domain.launch.LaunchCheckExtension;
import google.registry.model.eppoutput.CheckData; import google.registry.model.eppinput.ResourceCommand;
import google.registry.model.eppoutput.CheckData.DomainCheck; import google.registry.model.eppoutput.CheckData.DomainCheck;
import google.registry.model.eppoutput.CheckData.DomainCheckData; import google.registry.model.eppoutput.CheckData.DomainCheckData;
import google.registry.model.eppoutput.EppOutput;
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.Registry.TldState;
import google.registry.model.registry.label.ReservationType; import google.registry.model.registry.label.ReservationType;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
/** /**
* An EPP flow that checks whether a domain can be provisioned. * An EPP flow that checks whether a domain can be provisioned.
* *
* @error {@link google.registry.flows.ResourceCheckFlow.TooManyResourceChecksException} * <p>This flow also supports the EPP fee extension and can return pricing information.
*
* @error {@link google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException} * @error {@link google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException}
* @error {@link google.registry.flows.exceptions.TooManyResourceChecksException}
* @error {@link DomainFlowUtils.BadDomainNameCharacterException} * @error {@link DomainFlowUtils.BadDomainNameCharacterException}
* @error {@link DomainFlowUtils.BadDomainNamePartsCountException} * @error {@link DomainFlowUtils.BadDomainNamePartsCountException}
* @error {@link DomainFlowUtils.BadPeriodUnitException} * @error {@link DomainFlowUtils.BadPeriodUnitException}
@ -71,7 +87,7 @@ import javax.inject.Inject;
* @error {@link DomainFlowUtils.UnknownFeeCommandException} * @error {@link DomainFlowUtils.UnknownFeeCommandException}
* @error {@link DomainCheckFlow.OnlyCheckedNamesCanBeFeeCheckedException} * @error {@link DomainCheckFlow.OnlyCheckedNamesCanBeFeeCheckedException}
*/ */
public class DomainCheckFlow extends BaseDomainCheckFlow { public final class DomainCheckFlow extends LoggedInFlow {
/** /**
* The TLD states during which we want to report a domain with pending applications as * The TLD states during which we want to report a domain with pending applications as
@ -80,19 +96,55 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
private static final Set<TldState> PENDING_ALLOCATION_TLD_STATES = private static final Set<TldState> PENDING_ALLOCATION_TLD_STATES =
Sets.immutableEnumSet(TldState.GENERAL_AVAILABILITY, TldState.QUIET_PERIOD); Sets.immutableEnumSet(TldState.GENERAL_AVAILABILITY, TldState.QUIET_PERIOD);
@Inject ResourceCommand resourceCommand;
@Inject @ClientId String clientId;
@Inject @Config("maxChecks") int maxChecks;
@Inject DomainCheckFlow() {} @Inject DomainCheckFlow() {}
@Override @Override
protected void initDomainCheckFlow() throws EppException { protected final void initLoggedInFlow() throws EppException {
registerExtensions(LaunchCheckExtension.class); registerExtensions(LaunchCheckExtension.class);
registerExtensions(FEE_CHECK_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER); registerExtensions(FEE_CHECK_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER);
} }
private String getMessageForCheck(String targetId, Set<String> existingIds) { @Override
if (existingIds.contains(targetId)) { public EppOutput run() throws EppException {
List<String> targetIds = ((Check) resourceCommand).getTargetIds();
verifyTargetIdCount(targetIds, maxChecks);
ImmutableMap.Builder<String, InternetDomainName> domains = new ImmutableMap.Builder<>();
// Only check that the registrar has access to a TLD the first time it is encountered
Set<String> seenTlds = new HashSet<>();
for (String targetId : ImmutableSet.copyOf(targetIds)) {
InternetDomainName domainName = validateDomainName(targetId);
validateDomainNameWithIdnTables(domainName);
// This validation is moderately expensive, so cache the results.
domains.put(targetId, domainName);
String tld = domainName.parent().toString();
if (seenTlds.add(tld)) {
checkAllowedAccessToTld(getAllowedTlds(), tld);
if (!isSuperuser && TldState.PREDELEGATION.equals(Registry.get(tld).getTldState(now))) {
throw new BadCommandForRegistryPhaseException();
}
}
}
ImmutableMap<String, InternetDomainName> domainNames = domains.build();
Set<String> existingIds = checkResourcesExist(DomainResource.class, targetIds, now);
ImmutableList.Builder<DomainCheck> checks = new ImmutableList.Builder<>();
for (String targetId : targetIds) {
String message = getMessageForCheck(domainNames.get(targetId), existingIds);
checks.add(DomainCheck.create(message == null, targetId, message));
}
return createOutput(
SUCCESS,
DomainCheckData.create(checks.build()),
getResponseExtensions(domainNames));
}
private String getMessageForCheck(
InternetDomainName domainName, Set<String> existingIds) {
if (existingIds.contains(domainName.toString())) {
return "In use"; return "In use";
} }
InternetDomainName domainName = domainNames.get(targetId);
Registry registry = Registry.get(domainName.parent().toString()); Registry registry = Registry.get(domainName.parent().toString());
if (PENDING_ALLOCATION_TLD_STATES.contains(registry.getTldState(now)) if (PENDING_ALLOCATION_TLD_STATES.contains(registry.getTldState(now))
&& FluentIterable.from(loadActiveApplicationsByDomainName(domainName.toString(), now)) && FluentIterable.from(loadActiveApplicationsByDomainName(domainName.toString(), now))
@ -115,15 +167,34 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
return reservationType.getMessageForCheck(); return reservationType.getMessageForCheck();
} }
@Override
protected CheckData getCheckData() { /** Handle the fee check extension. */
Set<String> existingIds = checkResourcesExist(resourceClass, targetIds, now); private ImmutableList<? extends ResponseExtension> getResponseExtensions(
ImmutableList.Builder<DomainCheck> checks = new ImmutableList.Builder<>(); ImmutableMap<String, InternetDomainName> domainNames) throws EppException {
for (String id : targetIds) { FeeCheckCommandExtension<?, ?> feeCheck =
String message = getMessageForCheck(id, existingIds); eppInput.getFirstExtensionOfClasses(FEE_CHECK_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER);
checks.add(DomainCheck.create(message == null, id, message)); if (feeCheck == null) {
return null; // No fee checks were requested.
} }
return DomainCheckData.create(checks.build()); ImmutableList.Builder<FeeCheckResponseExtensionItem> responseItems =
new ImmutableList.Builder<>();
for (FeeCheckCommandExtensionItem feeCheckItem : feeCheck.getItems()) {
for (String domainName : getDomainNamesToCheckForFee(feeCheckItem, domainNames.keySet())) {
FeeCheckResponseExtensionItem.Builder builder = feeCheckItem.createResponseBuilder();
handleFeeRequest(
feeCheckItem,
builder,
domainNames.get(domainName),
clientId,
feeCheck.getCurrency(),
feeCheckItem.getEffectiveDate().isPresent()
? feeCheckItem.getEffectiveDate().get()
: now,
eppInput);
responseItems.add(builder.setDomainNameIfSupported(domainName).build());
}
}
return ImmutableList.of(feeCheck.createResponse(responseItems.build()));
} }
/** /**
@ -131,54 +202,21 @@ public class DomainCheckFlow extends BaseDomainCheckFlow {
* extension specify the domain name in the extension item, while others use the list of domain * extension specify the domain name in the extension item, while others use the list of domain
* names from the regular check domain availability list. * names from the regular check domain availability list.
*/ */
private Set<String> getDomainNamesToCheck(FeeCheckCommandExtensionItem feeCheckItem) private Set<String> getDomainNamesToCheckForFee(
FeeCheckCommandExtensionItem feeCheckItem, ImmutableSet<String> availabilityCheckDomains)
throws OnlyCheckedNamesCanBeFeeCheckedException { throws OnlyCheckedNamesCanBeFeeCheckedException {
if (feeCheckItem.isDomainNameSupported()) { if (feeCheckItem.isDomainNameSupported()) {
String domainNameInExtension = feeCheckItem.getDomainName(); String domainNameInExtension = feeCheckItem.getDomainName();
if (!domainNames.containsKey(domainNameInExtension)) { if (!availabilityCheckDomains.contains(domainNameInExtension)) {
// Although the fee extension explicitly says it's ok to fee check a domain name that you // Although the fee extension explicitly says it's ok to fee check a domain name that you
// aren't also availability checking, we forbid it. This makes the experience simpler and // aren't also availability checking, we forbid it. This makes the experience simpler and
// also means we can assume any domain names in the fee checks have been validated. // also means we can assume any domain names in the fee checks have been validated.
throw new OnlyCheckedNamesCanBeFeeCheckedException(); throw new OnlyCheckedNamesCanBeFeeCheckedException();
} }
return ImmutableSet.of(domainNameInExtension); return ImmutableSet.of(domainNameInExtension);
} else {
// If this version of the fee extension is nameless, use the full list of domains.
return domainNames.keySet();
} }
} // If this version of the fee extension is nameless, use the full list of domains.
return availabilityCheckDomains;
/** Handle the fee check extension. */
@Override
protected ImmutableList<ResponseExtension> getResponseExtensions() throws EppException {
FeeCheckCommandExtension<
? extends FeeCheckCommandExtensionItem, ? extends FeeCheckResponseExtension<?>>
feeCheck = eppInput.getFirstExtensionOfClasses(
FEE_CHECK_COMMAND_EXTENSIONS_IN_PREFERENCE_ORDER);
if (feeCheck == null) {
return null; // No fee checks were requested.
}
ImmutableList.Builder<FeeCheckResponseExtensionItem> feeCheckResponseItemsBuilder =
new ImmutableList.Builder<>();
for (FeeCheckCommandExtensionItem feeCheckItem : feeCheck.getItems()) {
for (String domainName : getDomainNamesToCheck(feeCheckItem)) {
FeeCheckResponseExtensionItem.Builder builder = feeCheckItem.createResponseBuilder();
handleFeeRequest(
feeCheckItem,
builder,
domainNames.get(domainName),
getClientId(),
feeCheck.getCurrency(),
feeCheckItem.getEffectiveDate().isPresent()
? feeCheckItem.getEffectiveDate().get()
: now,
eppInput);
feeCheckResponseItemsBuilder
.add(builder.setDomainNameIfSupported(domainName).build());
}
}
return ImmutableList.<ResponseExtension>of(
feeCheck.createResponse(feeCheckResponseItemsBuilder.build()));
} }
/** By server policy, fee check names must be listed in the availability check. */ /** By server policy, fee check names must be listed in the availability check. */

View file

@ -14,6 +14,7 @@
package google.registry.flows.host; package google.registry.flows.host;
import static google.registry.flows.ResourceFlowUtils.verifyTargetIdCount;
import static google.registry.model.EppResourceUtils.checkResourcesExist; import static google.registry.model.EppResourceUtils.checkResourcesExist;
import static google.registry.model.eppoutput.Result.Code.SUCCESS; import static google.registry.model.eppoutput.Result.Code.SUCCESS;
@ -21,7 +22,6 @@ import com.google.common.collect.ImmutableList;
import google.registry.config.ConfigModule.Config; import google.registry.config.ConfigModule.Config;
import google.registry.flows.EppException; import google.registry.flows.EppException;
import google.registry.flows.LoggedInFlow; import google.registry.flows.LoggedInFlow;
import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.eppinput.ResourceCommand; import google.registry.model.eppinput.ResourceCommand;
import google.registry.model.eppoutput.CheckData.HostCheck; import google.registry.model.eppoutput.CheckData.HostCheck;
import google.registry.model.eppoutput.CheckData.HostCheckData; import google.registry.model.eppoutput.CheckData.HostCheckData;
@ -48,9 +48,7 @@ public final class HostCheckFlow extends LoggedInFlow {
@Override @Override
protected final EppOutput run() throws EppException { protected final EppOutput run() throws EppException {
List<String> targetIds = ((Check) resourceCommand).getTargetIds(); List<String> targetIds = ((Check) resourceCommand).getTargetIds();
if (targetIds.size() > maxChecks) { verifyTargetIdCount(targetIds, maxChecks);
throw new TooManyResourceChecksException(maxChecks);
}
Set<String> existingIds = checkResourcesExist(HostResource.class, targetIds, now); Set<String> existingIds = checkResourcesExist(HostResource.class, targetIds, now);
ImmutableList.Builder<HostCheck> checks = new ImmutableList.Builder<>(); ImmutableList.Builder<HostCheck> checks = new ImmutableList.Builder<>();
for (String id : targetIds) { for (String id : targetIds) {

View file

@ -20,11 +20,11 @@ import static google.registry.testing.DatastoreHelper.persistResource;
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 google.registry.flows.ResourceCheckFlow.TooManyResourceChecksException;
import google.registry.flows.ResourceFlow.BadCommandForRegistryPhaseException;
import google.registry.flows.ResourceFlowTestCase; import google.registry.flows.ResourceFlowTestCase;
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException; import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
import google.registry.flows.domain.DomainFlowUtils.TldDoesNotExistException; import google.registry.flows.domain.DomainFlowUtils.TldDoesNotExistException;
import google.registry.flows.exceptions.BadCommandForRegistryPhaseException;
import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.registrar.Registrar; import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;

View file

@ -29,7 +29,6 @@ import com.google.common.base.Strings;
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.ImmutableSortedMap; import com.google.common.collect.ImmutableSortedMap;
import google.registry.flows.ResourceCheckFlow.TooManyResourceChecksException;
import google.registry.flows.ResourceCheckFlowTestCase; import google.registry.flows.ResourceCheckFlowTestCase;
import google.registry.flows.domain.DomainCheckFlow.OnlyCheckedNamesCanBeFeeCheckedException; import google.registry.flows.domain.DomainCheckFlow.OnlyCheckedNamesCanBeFeeCheckedException;
import google.registry.flows.domain.DomainFlowUtils.BadDomainNameCharacterException; import google.registry.flows.domain.DomainFlowUtils.BadDomainNameCharacterException;
@ -48,6 +47,7 @@ import google.registry.flows.domain.DomainFlowUtils.RestoresAreAlwaysForOneYearE
import google.registry.flows.domain.DomainFlowUtils.TldDoesNotExistException; import google.registry.flows.domain.DomainFlowUtils.TldDoesNotExistException;
import google.registry.flows.domain.DomainFlowUtils.TrailingDashException; import google.registry.flows.domain.DomainFlowUtils.TrailingDashException;
import google.registry.flows.domain.DomainFlowUtils.UnknownFeeCommandException; import google.registry.flows.domain.DomainFlowUtils.UnknownFeeCommandException;
import google.registry.flows.exceptions.TooManyResourceChecksException;
import google.registry.model.domain.DomainResource; import google.registry.model.domain.DomainResource;
import google.registry.model.domain.launch.ApplicationStatus; import google.registry.model.domain.launch.ApplicationStatus;
import google.registry.model.domain.launch.LaunchPhase; import google.registry.model.domain.launch.LaunchPhase;