mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Validate individual fee types
Currently we validate the fee extension by summing up all fees present in the extension and comparing it against the total fee to be charged. While this works in most cases, we'd like the ability to individually validate each fee. This is especially useful during EAP when two fees are charged, a regular "create" fee that would also be amount we charge during renewal, and a one time "EAP" fee. Because we can only distinguish fees by their descriptions, we try to match the description to the format string of the fee type enums. We also only require individual fee matches when we are charging more than one type of fees, which makes the change compatible with most existing use cases where only one fees is charged and the description field is ignored in the extension. We expect the workflow to be that a registrar sends a domain check, and we reply with exactly what fees we are expecting, and then it will use the descriptions in the response to send us a domain create with the correct fees. Note that we aggregate fees within the same FeeType together. Normally there will only be one fee per type, but in case of custom logic there could be more than one fee for the same type. There is no way to distinguish them as they both use the same description. So it is simpler to just aggregate them. This CL also includes some reformatting that conforms to google-java-format output. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=186530316
This commit is contained in:
parent
1965c0a0aa
commit
ff221fba96
13 changed files with 355 additions and 106 deletions
|
@ -588,6 +588,9 @@ An EPP flow that creates a new domain resource.
|
|||
* Domain labels cannot be longer than 63 characters.
|
||||
* More than one contact for a given role is not allowed.
|
||||
* No part of a domain name can be empty.
|
||||
* The fee description passed in the transform command matches multiple fee
|
||||
types.
|
||||
* The fee description passed in the transform command cannot be parsed.
|
||||
* Domain name starts with xn-- but is not a valid IDN.
|
||||
* The specified trademark validator is not supported.
|
||||
* Domain labels cannot begin with a dash.
|
||||
|
|
|
@ -141,6 +141,8 @@ import org.joda.time.Duration;
|
|||
* @error {@link DomainFlowUtils.EmptyDomainNamePartException}
|
||||
* @error {@link DomainFlowUtils.ExceedsMaxRegistrationYearsException}
|
||||
* @error {@link DomainFlowUtils.ExpiredClaimException}
|
||||
* @error {@link DomainFlowUtils.FeeDescriptionMultipleMatchesException}
|
||||
* @error {@link DomainFlowUtils.FeeDescriptionParseException}
|
||||
* @error {@link DomainFlowUtils.FeesMismatchException}
|
||||
* @error {@link DomainFlowUtils.FeesRequiredDuringEarlyAccessProgramException}
|
||||
* @error {@link DomainFlowUtils.FeesRequiredForPremiumNameException}
|
||||
|
|
|
@ -17,6 +17,7 @@ package google.registry.flows.domain;
|
|||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.base.Predicates.equalTo;
|
||||
import static com.google.common.collect.ImmutableMap.toImmutableMap;
|
||||
import static com.google.common.collect.Iterables.any;
|
||||
import static com.google.common.collect.Sets.difference;
|
||||
import static com.google.common.collect.Sets.intersection;
|
||||
|
@ -43,6 +44,7 @@ import com.google.common.base.Joiner;
|
|||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.Streams;
|
||||
|
@ -78,6 +80,7 @@ import google.registry.model.domain.DomainResource;
|
|||
import google.registry.model.domain.ForeignKeyedDesignatedContact;
|
||||
import google.registry.model.domain.LrpTokenEntity;
|
||||
import google.registry.model.domain.Period;
|
||||
import google.registry.model.domain.fee.BaseFee.FeeType;
|
||||
import google.registry.model.domain.fee.Credit;
|
||||
import google.registry.model.domain.fee.Fee;
|
||||
import google.registry.model.domain.fee.FeeQueryCommandExtensionItem;
|
||||
|
@ -111,8 +114,10 @@ import google.registry.model.reporting.HistoryEntry;
|
|||
import google.registry.model.tmch.ClaimsListShard;
|
||||
import google.registry.util.Idn;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
@ -172,8 +177,7 @@ public class DomainFlowUtils {
|
|||
*
|
||||
* @see #validateDomainNameWithIdnTables(InternetDomainName)
|
||||
*/
|
||||
public static InternetDomainName validateDomainName(String name)
|
||||
throws EppException {
|
||||
public static InternetDomainName validateDomainName(String name) throws EppException {
|
||||
if (!ALLOWED_CHARS.matchesAllOf(name)) {
|
||||
throw new BadDomainNameCharacterException();
|
||||
}
|
||||
|
@ -237,8 +241,7 @@ public class DomainFlowUtils {
|
|||
}
|
||||
|
||||
/** Check if the registrar running the flow has access to the TLD in question. */
|
||||
public static void checkAllowedAccessToTld(String clientId, String tld)
|
||||
throws EppException {
|
||||
public static void checkAllowedAccessToTld(String clientId, String tld) throws EppException {
|
||||
if (!Registrar.loadByClientIdCached(clientId).get().getAllowedTlds().contains(tld)) {
|
||||
throw new DomainFlowUtils.NotAuthorizedForTldException(tld);
|
||||
}
|
||||
|
@ -247,8 +250,9 @@ public class DomainFlowUtils {
|
|||
/** Check that the DS data that will be set on a domain is valid. */
|
||||
static void validateDsData(Set<DelegationSignerData> dsData) throws EppException {
|
||||
if (dsData != null && dsData.size() > MAX_DS_RECORDS_PER_DOMAIN) {
|
||||
throw new TooManyDsRecordsException(String.format(
|
||||
"A maximum of %s DS records are allowed per domain.", MAX_DS_RECORDS_PER_DOMAIN));
|
||||
throw new TooManyDsRecordsException(
|
||||
String.format(
|
||||
"A maximum of %s DS records are allowed per domain.", MAX_DS_RECORDS_PER_DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,7 +268,8 @@ public class DomainFlowUtils {
|
|||
static void verifyNotInPendingDelete(
|
||||
Set<DesignatedContact> contacts,
|
||||
Key<ContactResource> registrant,
|
||||
Set<Key<HostResource>> nameservers) throws EppException {
|
||||
Set<Key<HostResource>> nameservers)
|
||||
throws EppException {
|
||||
for (DesignatedContact contact : nullToEmpty(contacts)) {
|
||||
verifyNotInPendingDelete(contact.getContactKey());
|
||||
}
|
||||
|
@ -276,8 +281,8 @@ public class DomainFlowUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static void verifyNotInPendingDelete(
|
||||
Key<? extends EppResource> resourceKey) throws EppException {
|
||||
private static void verifyNotInPendingDelete(Key<? extends EppResource> resourceKey)
|
||||
throws EppException {
|
||||
EppResource resource = ofy().load().key(resourceKey).now();
|
||||
if (resource.getStatusValues().contains(StatusValue.PENDING_DELETE)) {
|
||||
throw new LinkedResourceInPendingDeleteProhibitsOperationException(resource.getForeignKey());
|
||||
|
@ -309,8 +314,8 @@ public class DomainFlowUtils {
|
|||
domainName.toString());
|
||||
}
|
||||
if (count > MAX_NAMESERVERS_PER_DOMAIN) {
|
||||
throw new TooManyNameserversException(String.format(
|
||||
"Only %d nameservers are allowed per domain", MAX_NAMESERVERS_PER_DOMAIN));
|
||||
throw new TooManyNameserversException(
|
||||
String.format("Only %d nameservers are allowed per domain", MAX_NAMESERVERS_PER_DOMAIN));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +331,7 @@ public class DomainFlowUtils {
|
|||
|
||||
static void validateRequiredContactsPresent(
|
||||
Key<ContactResource> registrant, Set<DesignatedContact> contacts)
|
||||
throws RequiredParameterMissingException {
|
||||
throws RequiredParameterMissingException {
|
||||
if (registrant == null) {
|
||||
throw new MissingRegistrantException();
|
||||
}
|
||||
|
@ -347,7 +352,8 @@ public class DomainFlowUtils {
|
|||
throws RegistrantNotAllowedException {
|
||||
ImmutableSet<String> whitelist = Registry.get(tld).getAllowedRegistrantContactIds();
|
||||
// Empty whitelist or null registrantContactId are ignored.
|
||||
if (registrantContactId != null && !whitelist.isEmpty()
|
||||
if (registrantContactId != null
|
||||
&& !whitelist.isEmpty()
|
||||
&& !whitelist.contains(registrantContactId)) {
|
||||
throw new RegistrantNotAllowedException(registrantContactId);
|
||||
}
|
||||
|
@ -418,16 +424,15 @@ public class DomainFlowUtils {
|
|||
static void verifyLaunchPhaseMatchesRegistryPhase(
|
||||
Registry registry, LaunchExtension launchExtension, DateTime now) throws EppException {
|
||||
if (!Objects.equals(
|
||||
registry.getTldState(now),
|
||||
LAUNCH_PHASE_TO_TLD_STATE.get(launchExtension.getPhase()))) {
|
||||
registry.getTldState(now), LAUNCH_PHASE_TO_TLD_STATE.get(launchExtension.getPhase()))) {
|
||||
// No launch operations are allowed during the quiet period or predelegation.
|
||||
throw new LaunchPhaseMismatchException();
|
||||
}
|
||||
}
|
||||
|
||||
/** Verifies that an application's domain name matches the target id (from a command). */
|
||||
static void verifyApplicationDomainMatchesTargetId(
|
||||
DomainApplication application, String targetId) throws EppException {
|
||||
static void verifyApplicationDomainMatchesTargetId(DomainApplication application, String targetId)
|
||||
throws EppException {
|
||||
if (!application.getFullyQualifiedDomainName().equals(targetId)) {
|
||||
throw new ApplicationDomainNameMismatchException();
|
||||
}
|
||||
|
@ -438,8 +443,8 @@ public class DomainFlowUtils {
|
|||
* where it would not be allowed is if domain name is premium, and premium names are blocked by
|
||||
* this registrar.
|
||||
*/
|
||||
static void verifyPremiumNameIsNotBlocked(
|
||||
String domainName, DateTime priceTime, String clientId) throws EppException {
|
||||
static void verifyPremiumNameIsNotBlocked(String domainName, DateTime priceTime, String clientId)
|
||||
throws EppException {
|
||||
if (isDomainPremium(domainName, priceTime)) {
|
||||
if (Registrar.loadByClientIdCached(clientId).get().getBlockPremiumNames()) {
|
||||
throw new PremiumNameBlockedException();
|
||||
|
@ -501,13 +506,14 @@ public class DomainFlowUtils {
|
|||
// message to be deleted), and then subsequently the transfer was canceled, rejected, or deleted
|
||||
// (which would cause the poll message to be recreated here).
|
||||
Key<PollMessage.Autorenew> existingAutorenewKey = domain.getAutorenewPollMessage();
|
||||
PollMessage.Autorenew updatedAutorenewPollMessage = autorenewPollMessage.isPresent()
|
||||
? autorenewPollMessage.get().asBuilder().setAutorenewEndTime(newEndTime).build()
|
||||
: newAutorenewPollMessage(domain)
|
||||
.setId(existingAutorenewKey.getId())
|
||||
.setAutorenewEndTime(newEndTime)
|
||||
.setParentKey(existingAutorenewKey.getParent())
|
||||
.build();
|
||||
PollMessage.Autorenew updatedAutorenewPollMessage =
|
||||
autorenewPollMessage.isPresent()
|
||||
? autorenewPollMessage.get().asBuilder().setAutorenewEndTime(newEndTime).build()
|
||||
: newAutorenewPollMessage(domain)
|
||||
.setId(existingAutorenewKey.getId())
|
||||
.setAutorenewEndTime(newEndTime)
|
||||
.setParentKey(existingAutorenewKey.getParent())
|
||||
.build();
|
||||
|
||||
// If the resultant autorenew poll message would have no poll messages to deliver, then just
|
||||
// delete it. Otherwise save it with the new end time.
|
||||
|
@ -697,6 +703,49 @@ public class DomainFlowUtils {
|
|||
if (!feeTotal.equals(feesAndCredits.getTotalCost())) {
|
||||
throw new FeesMismatchException(feesAndCredits.getTotalCost());
|
||||
}
|
||||
// If more than one fees are required, always validate individual fees.
|
||||
ImmutableMap<FeeType, Money> expectedFeeMap =
|
||||
buildFeeMap(feesAndCredits.getFees(), feesAndCredits.getCurrency());
|
||||
if (expectedFeeMap.size() > 1) {
|
||||
ImmutableMap<FeeType, Money> providedFeeMap =
|
||||
buildFeeMap(feeCommand.get().getFees(), feeCommand.get().getCurrency());
|
||||
for (FeeType type : expectedFeeMap.keySet()) {
|
||||
Money providedCost = providedFeeMap.get(type);
|
||||
Money expectedCost = expectedFeeMap.get(type);
|
||||
if (!providedCost.isEqual(expectedCost)) {
|
||||
throw new FeesMismatchException(type, expectedCost);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static FeeType getOrParseType(Fee fee) throws ParameterValuePolicyErrorException {
|
||||
if (fee.getType() != null) {
|
||||
return fee.getType();
|
||||
}
|
||||
ImmutableList<FeeType> types = fee.parseDescriptionForTypes();
|
||||
if (types.size() == 0) {
|
||||
throw new FeeDescriptionParseException(fee.getDescription());
|
||||
} else if (types.size() > 1) {
|
||||
throw new FeeDescriptionMultipleMatchesException(fee.getDescription());
|
||||
} else {
|
||||
return types.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static ImmutableMap<FeeType, Money> buildFeeMap(List<Fee> fees, CurrencyUnit currency)
|
||||
throws ParameterValuePolicyErrorException {
|
||||
ImmutableMultimap.Builder<FeeType, Money> mapBuilder =
|
||||
new ImmutableMultimap.Builder<FeeType, Money>().orderKeysBy(Comparator.naturalOrder());
|
||||
for (Fee fee : fees) {
|
||||
mapBuilder.put(getOrParseType(fee), Money.of(currency, fee.getCost()));
|
||||
}
|
||||
return mapBuilder
|
||||
.build()
|
||||
.asMap()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(toImmutableMap(Entry::getKey, entry -> Money.total(entry.getValue())));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -714,8 +763,8 @@ public class DomainFlowUtils {
|
|||
|
||||
/**
|
||||
* Check whether a new registration period (via a create, allocate, or application create) does
|
||||
* not extend beyond a maximum number of years (e.g.
|
||||
* {@link DomainResource#MAX_REGISTRATION_YEARS}).
|
||||
* not extend beyond a maximum number of years (e.g. {@link
|
||||
* DomainResource#MAX_REGISTRATION_YEARS}).
|
||||
*
|
||||
* @throws ExceedsMaxRegistrationYearsException if the new registration period is too long
|
||||
*/
|
||||
|
@ -743,9 +792,9 @@ public class DomainFlowUtils {
|
|||
/** Update {@link DelegationSignerData} based on an update extension command. */
|
||||
static ImmutableSet<DelegationSignerData> updateDsData(
|
||||
ImmutableSet<DelegationSignerData> oldDsData, SecDnsUpdateExtension secDnsUpdate)
|
||||
throws EppException {
|
||||
throws EppException {
|
||||
// We don't support 'urgent' because we do everything as fast as we can anyways.
|
||||
if (Boolean.TRUE.equals(secDnsUpdate.getUrgent())) { // We allow both false and null.
|
||||
if (Boolean.TRUE.equals(secDnsUpdate.getUrgent())) { // We allow both false and null.
|
||||
throw new UrgentAttributeNotSupportedException();
|
||||
}
|
||||
// There must be at least one of add/rem/chg, and chg isn't actually supported.
|
||||
|
@ -759,14 +808,13 @@ public class DomainFlowUtils {
|
|||
throw new EmptySecDnsUpdateException();
|
||||
}
|
||||
if (remove != null && Boolean.FALSE.equals(remove.getAll())) {
|
||||
throw new SecDnsAllUsageException(); // Explicit all=false is meaningless.
|
||||
throw new SecDnsAllUsageException(); // Explicit all=false is meaningless.
|
||||
}
|
||||
Set<DelegationSignerData> toAdd = (add == null)
|
||||
? ImmutableSet.of()
|
||||
: add.getDsData();
|
||||
Set<DelegationSignerData> toRemove = (remove == null)
|
||||
? ImmutableSet.of()
|
||||
: (remove.getAll() == null) ? remove.getDsData() : oldDsData;
|
||||
Set<DelegationSignerData> toAdd = (add == null) ? ImmutableSet.of() : add.getDsData();
|
||||
Set<DelegationSignerData> toRemove =
|
||||
(remove == null)
|
||||
? ImmutableSet.of()
|
||||
: (remove.getAll() == null) ? remove.getDsData() : oldDsData;
|
||||
// RFC 5910 specifies that removes are processed before adds.
|
||||
return ImmutableSet.copyOf(union(difference(oldDsData, toRemove), toAdd));
|
||||
}
|
||||
|
@ -775,7 +823,9 @@ public class DomainFlowUtils {
|
|||
static void verifyClientUpdateNotProhibited(Update command, DomainBase existingResource)
|
||||
throws ResourceHasClientUpdateProhibitedException {
|
||||
if (existingResource.getStatusValues().contains(StatusValue.CLIENT_UPDATE_PROHIBITED)
|
||||
&& !command.getInnerRemove().getStatusValues()
|
||||
&& !command
|
||||
.getInnerRemove()
|
||||
.getStatusValues()
|
||||
.contains(StatusValue.CLIENT_UPDATE_PROHIBITED)) {
|
||||
throw new ResourceHasClientUpdateProhibitedException();
|
||||
}
|
||||
|
@ -845,10 +895,8 @@ public class DomainFlowUtils {
|
|||
|
||||
/** Validate the notice from a launch create extension, allowing null as a valid notice. */
|
||||
static void validateLaunchCreateNotice(
|
||||
@Nullable LaunchNotice notice,
|
||||
String domainLabel,
|
||||
boolean isSuperuser,
|
||||
DateTime now) throws EppException {
|
||||
@Nullable LaunchNotice notice, String domainLabel, boolean isSuperuser, DateTime now)
|
||||
throws EppException {
|
||||
if (notice == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -887,9 +935,8 @@ public class DomainFlowUtils {
|
|||
* not on the claims list and is a sunrise application.
|
||||
*/
|
||||
static void verifyClaimsNoticeIfAndOnlyIfNeeded(
|
||||
InternetDomainName domainName,
|
||||
boolean hasSignedMarks,
|
||||
boolean hasClaimsNotice) throws EppException {
|
||||
InternetDomainName domainName, boolean hasSignedMarks, boolean hasClaimsNotice)
|
||||
throws EppException {
|
||||
boolean isInClaimsList = ClaimsListShard.get().getClaimKey(domainName.parts().get(0)) != null;
|
||||
if (hasClaimsNotice && !isInClaimsList) {
|
||||
throw new UnexpectedClaimsNoticeException(domainName.toString());
|
||||
|
@ -902,14 +949,12 @@ public class DomainFlowUtils {
|
|||
/** Create a {@link LrpTokenEntity} object that records this LRP registration. */
|
||||
static LrpTokenEntity prepareMarkedLrpTokenEntity(
|
||||
String lrpTokenString, InternetDomainName domainName, HistoryEntry historyEntry)
|
||||
throws InvalidLrpTokenException {
|
||||
throws InvalidLrpTokenException {
|
||||
Optional<LrpTokenEntity> lrpToken = getMatchingLrpToken(lrpTokenString, domainName);
|
||||
if (!lrpToken.isPresent()) {
|
||||
throw new InvalidLrpTokenException();
|
||||
}
|
||||
return lrpToken.get().asBuilder()
|
||||
.setRedemptionHistoryEntry(Key.create(historyEntry))
|
||||
.build();
|
||||
return lrpToken.get().asBuilder().setRedemptionHistoryEntry(Key.create(historyEntry)).build();
|
||||
}
|
||||
|
||||
/** Check that there are no code marks, which is a type of mark we don't support. */
|
||||
|
@ -935,9 +980,9 @@ public class DomainFlowUtils {
|
|||
ImmutableSet<DesignatedContact> contacts) {
|
||||
ImmutableSet.Builder<ForeignKeyedDesignatedContact> builder = new ImmutableSet.Builder<>();
|
||||
for (DesignatedContact contact : contacts) {
|
||||
builder.add(ForeignKeyedDesignatedContact.create(
|
||||
contact.getType(),
|
||||
ofy().load().key(contact.getContactKey()).now().getContactId()));
|
||||
builder.add(
|
||||
ForeignKeyedDesignatedContact.create(
|
||||
contact.getType(), ofy().load().key(contact.getContactKey()).now().getContactId()));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
@ -960,12 +1005,14 @@ public class DomainFlowUtils {
|
|||
Duration maxSearchPeriod,
|
||||
final ImmutableSet<TransactionReportField> cancelableFields) {
|
||||
|
||||
List<HistoryEntry> recentHistoryEntries = ofy().load()
|
||||
.type(HistoryEntry.class)
|
||||
.ancestor(domainResource)
|
||||
.filter("modificationTime >=", now.minus(maxSearchPeriod))
|
||||
.order("modificationTime")
|
||||
.list();
|
||||
List<HistoryEntry> recentHistoryEntries =
|
||||
ofy()
|
||||
.load()
|
||||
.type(HistoryEntry.class)
|
||||
.ancestor(domainResource)
|
||||
.filter("modificationTime >=", now.minus(maxSearchPeriod))
|
||||
.order("modificationTime")
|
||||
.list();
|
||||
Optional<HistoryEntry> entryToCancel =
|
||||
Streams.findLast(
|
||||
recentHistoryEntries
|
||||
|
@ -1006,9 +1053,7 @@ public class DomainFlowUtils {
|
|||
static class LinkedResourceInPendingDeleteProhibitsOperationException
|
||||
extends StatusProhibitsOperationException {
|
||||
public LinkedResourceInPendingDeleteProhibitsOperationException(String resourceId) {
|
||||
super(String.format(
|
||||
"Linked resource in pending delete prohibits operation: %s",
|
||||
resourceId));
|
||||
super(String.format("Linked resource in pending delete prohibits operation: %s", resourceId));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1190,8 +1235,9 @@ public class DomainFlowUtils {
|
|||
/** Fees must be explicitly acknowledged when performing any operations on a premium name. */
|
||||
static class FeesRequiredForPremiumNameException extends RequiredParameterMissingException {
|
||||
FeesRequiredForPremiumNameException() {
|
||||
super("Fees must be explicitly acknowledged when performing any operations on a premium"
|
||||
+ " name");
|
||||
super(
|
||||
"Fees must be explicitly acknowledged when performing any operations on a premium"
|
||||
+ " name");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1221,8 +1267,9 @@ public class DomainFlowUtils {
|
|||
/** The 'grace-period', 'applied' and 'refundable' fields are disallowed by server policy. */
|
||||
static class UnsupportedFeeAttributeException extends UnimplementedOptionException {
|
||||
UnsupportedFeeAttributeException() {
|
||||
super("The 'grace-period', 'refundable' and 'applied' attributes are disallowed by server "
|
||||
+ "policy");
|
||||
super(
|
||||
"The 'grace-period', 'refundable' and 'applied' attributes are disallowed by server "
|
||||
+ "policy");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1268,8 +1315,9 @@ public class DomainFlowUtils {
|
|||
*/
|
||||
static class PremiumNameBlockedException extends StatusProhibitsOperationException {
|
||||
public PremiumNameBlockedException() {
|
||||
super("The requested domain name is on the premium price list, "
|
||||
+ "and this registrar has blocked premium registrations");
|
||||
super(
|
||||
"The requested domain name is on the premium price list, "
|
||||
+ "and this registrar has blocked premium registrations");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1280,9 +1328,39 @@ public class DomainFlowUtils {
|
|||
}
|
||||
|
||||
public FeesMismatchException(Money correctFee) {
|
||||
super(String.format(
|
||||
"The fees passed in the transform command do not match the expected total of %s",
|
||||
correctFee));
|
||||
super(
|
||||
String.format(
|
||||
"The fees passed in the transform command do not match the expected total of %s",
|
||||
correctFee));
|
||||
}
|
||||
|
||||
public FeesMismatchException(FeeType type, Money correctFee) {
|
||||
super(
|
||||
String.format(
|
||||
"The fees passed in the transform command for type \"%s\" do not match the expected "
|
||||
+ "fee of %s",
|
||||
type, correctFee));
|
||||
}
|
||||
}
|
||||
|
||||
/** The fee description passed in the transform command cannot be parsed. */
|
||||
public static class FeeDescriptionParseException extends ParameterValuePolicyErrorException {
|
||||
public FeeDescriptionParseException(String description) {
|
||||
super(
|
||||
String.format(
|
||||
"The fee description \"%s\" passed in the transform command cannot be parsed",
|
||||
description == null ? "" : description));
|
||||
}
|
||||
}
|
||||
|
||||
/** The fee description passed in the transform command matches multiple fee types. */
|
||||
public static class FeeDescriptionMultipleMatchesException
|
||||
extends ParameterValuePolicyErrorException {
|
||||
public FeeDescriptionMultipleMatchesException(String description) {
|
||||
super(
|
||||
String.format(
|
||||
"The fee description \"%s\" passed in the transform matches multiple fee types",
|
||||
description));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1304,9 +1382,10 @@ public class DomainFlowUtils {
|
|||
public static class NameserversNotAllowedForTldException
|
||||
extends StatusProhibitsOperationException {
|
||||
public NameserversNotAllowedForTldException(Set<String> fullyQualifiedHostNames) {
|
||||
super(String.format(
|
||||
"Nameservers '%s' are not whitelisted for this TLD",
|
||||
Joiner.on(',').join(fullyQualifiedHostNames)));
|
||||
super(
|
||||
String.format(
|
||||
"Nameservers '%s' are not whitelisted for this TLD",
|
||||
Joiner.on(',').join(fullyQualifiedHostNames)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1451,8 +1530,7 @@ public class DomainFlowUtils {
|
|||
}
|
||||
|
||||
/** Invalid limited registration period token. */
|
||||
static class InvalidLrpTokenException
|
||||
extends InvalidAuthorizationInformationErrorException {
|
||||
static class InvalidLrpTokenException extends InvalidAuthorizationInformationErrorException {
|
||||
public InvalidLrpTokenException() {
|
||||
super("Invalid limited registration period token");
|
||||
}
|
||||
|
@ -1468,9 +1546,10 @@ public class DomainFlowUtils {
|
|||
/** New registration period exceeds maximum number of years. */
|
||||
static class ExceedsMaxRegistrationYearsException extends ParameterValueRangeErrorException {
|
||||
public ExceedsMaxRegistrationYearsException() {
|
||||
super(String.format(
|
||||
"New registration period exceeds maximum number of years (%d)",
|
||||
MAX_REGISTRATION_YEARS));
|
||||
super(
|
||||
String.format(
|
||||
"New registration period exceeds maximum number of years (%d)",
|
||||
MAX_REGISTRATION_YEARS));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1480,5 +1559,4 @@ public class DomainFlowUtils {
|
|||
super("Registrar must be active in order to create domains or applications");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,15 @@ package google.registry.model.domain.fee;
|
|||
|
||||
import static com.google.common.base.MoreObjects.firstNonNull;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static com.google.common.collect.ImmutableList.toImmutableList;
|
||||
|
||||
import com.google.common.base.Ascii;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Range;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.xml.PeriodAdapter;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.stream.Stream;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
@ -68,29 +72,27 @@ public abstract class BaseFee extends ImmutableObject {
|
|||
String renderDescription(Object... args) {
|
||||
return String.format(formatString, args);
|
||||
}
|
||||
|
||||
boolean matchFormatString(String description) {
|
||||
return Ascii.toLowerCase(formatString).contains(Ascii.toLowerCase(description));
|
||||
}
|
||||
}
|
||||
|
||||
@XmlAttribute
|
||||
String description;
|
||||
@XmlAttribute String description;
|
||||
|
||||
@XmlAttribute
|
||||
AppliedType applied;
|
||||
@XmlAttribute AppliedType applied;
|
||||
|
||||
@XmlAttribute(name = "grace-period")
|
||||
@XmlJavaTypeAdapter(PeriodAdapter.class)
|
||||
Period gracePeriod;
|
||||
|
||||
@XmlAttribute
|
||||
Boolean refundable;
|
||||
@XmlAttribute Boolean refundable;
|
||||
|
||||
@XmlValue
|
||||
BigDecimal cost;
|
||||
@XmlValue BigDecimal cost;
|
||||
|
||||
@XmlTransient
|
||||
FeeType type;
|
||||
@XmlTransient FeeType type;
|
||||
|
||||
@XmlTransient
|
||||
Range<DateTime> validDateRange;
|
||||
@XmlTransient Range<DateTime> validDateRange;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
|
@ -113,8 +115,8 @@ public abstract class BaseFee extends ImmutableObject {
|
|||
* must always be negative. Essentially, they are the same thing, just with different sign.
|
||||
* However, we need them to be separate classes for proper JAXB handling.
|
||||
*
|
||||
* @see <a href="https://tools.ietf.org/html/draft-brown-epp-fees-03#section-2.4">
|
||||
* Registry Fee Extension for EPP - Fees and Credits</a>
|
||||
* @see <a href="https://tools.ietf.org/html/draft-brown-epp-fees-03#section-2.4">Registry Fee
|
||||
* Extension for EPP - Fees and Credits</a>
|
||||
*/
|
||||
public BigDecimal getCost() {
|
||||
return cost;
|
||||
|
@ -142,4 +144,19 @@ public abstract class BaseFee extends ImmutableObject {
|
|||
&& getApplied().equals(AppliedType.IMMEDIATE)
|
||||
&& getRefundable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the description field and returns {@link FeeType}s that match the description.
|
||||
*
|
||||
* <p>A {@link FeeType} is a match when its {@code formatString} contains the description, case
|
||||
* insensitively.
|
||||
*/
|
||||
public ImmutableList<FeeType> parseDescriptionForTypes() {
|
||||
if (description == null) {
|
||||
return ImmutableList.of();
|
||||
}
|
||||
return Stream.of(FeeType.values())
|
||||
.filter(feeType -> feeType.matchFormatString(description))
|
||||
.collect(toImmutableList());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@ import google.registry.flows.domain.DomainFlowUtils.DuplicateContactForRoleExcep
|
|||
import google.registry.flows.domain.DomainFlowUtils.EmptyDomainNamePartException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.ExceedsMaxRegistrationYearsException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.ExpiredClaimException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeeDescriptionMultipleMatchesException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeeDescriptionParseException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeesMismatchException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeesRequiredDuringEarlyAccessProgramException;
|
||||
import google.registry.flows.domain.DomainFlowUtils.FeesRequiredForPremiumNameException;
|
||||
|
@ -1774,8 +1776,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
clock.setTo(DateTime.parse("2014-09-09T09:09:09Z"));
|
||||
setEppInput("domain_create_registration_start_date_sunrise_wrong_encoded_signed_mark.xml");
|
||||
persistContactsAndHosts();
|
||||
EppException thrown =
|
||||
expectThrows(NoMarksFoundMatchingDomainException.class, this::runFlow);
|
||||
EppException thrown = expectThrows(NoMarksFoundMatchingDomainException.class, this::runFlow);
|
||||
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
||||
}
|
||||
|
||||
|
@ -2153,9 +2154,90 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
assertThat(reloadResourceByForeignKey().getStatusValues()).containsExactly(OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_eapFee_combined() throws Exception {
|
||||
setEppInput("domain_create_eap_combined_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
|
||||
persistContactsAndHosts();
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setEapFeeSchedule(
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME,
|
||||
Money.of(USD, 0),
|
||||
clock.nowUtc().minusDays(1),
|
||||
Money.of(USD, 100),
|
||||
clock.nowUtc().plusDays(1),
|
||||
Money.of(USD, 0)))
|
||||
.build());
|
||||
EppException thrown = expectThrows(FeeDescriptionParseException.class, this::runFlow);
|
||||
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_eapFee_description_swapped() throws Exception {
|
||||
setEppInput(
|
||||
"domain_create_eap_fee.xml",
|
||||
ImmutableMap.of(
|
||||
"FEE_VERSION",
|
||||
"0.6",
|
||||
"DESCRIPTION_1",
|
||||
"Early Access Period",
|
||||
"DESCRIPTION_2",
|
||||
"create"));
|
||||
persistContactsAndHosts();
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setEapFeeSchedule(
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME,
|
||||
Money.of(USD, 0),
|
||||
clock.nowUtc().minusDays(1),
|
||||
Money.of(USD, 100),
|
||||
clock.nowUtc().plusDays(1),
|
||||
Money.of(USD, 0)))
|
||||
.build());
|
||||
EppException thrown = expectThrows(FeesMismatchException.class, this::runFlow);
|
||||
assertThat(thrown).hasMessageThat().contains("CREATE");
|
||||
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailure_eapFee_description_multipleMatch() throws Exception {
|
||||
setEppInput(
|
||||
"domain_create_eap_fee.xml",
|
||||
ImmutableMap.of(
|
||||
"FEE_VERSION", "0.6", "DESCRIPTION_1", "Early Access Period", "DESCRIPTION_2", "ea"));
|
||||
persistContactsAndHosts();
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
.asBuilder()
|
||||
.setEapFeeSchedule(
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME,
|
||||
Money.of(USD, 0),
|
||||
clock.nowUtc().minusDays(1),
|
||||
Money.of(USD, 100),
|
||||
clock.nowUtc().plusDays(1),
|
||||
Money.of(USD, 0)))
|
||||
.build());
|
||||
EppException thrown = expectThrows(FeeDescriptionMultipleMatchesException.class, this::runFlow);
|
||||
assertThat(thrown).hasMessageThat().contains("ea");
|
||||
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuccess_eapFeeApplied_v06() throws Exception {
|
||||
setEppInput("domain_create_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
|
||||
setEppInput(
|
||||
"domain_create_eap_fee.xml",
|
||||
ImmutableMap.of(
|
||||
"FEE_VERSION",
|
||||
"0.6",
|
||||
"DESCRIPTION_1",
|
||||
"create",
|
||||
"DESCRIPTION_2",
|
||||
"Early Access Period"));
|
||||
persistContactsAndHosts();
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
|
@ -2175,7 +2257,15 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
|
||||
@Test
|
||||
public void testSuccess_eapFeeApplied_v11() throws Exception {
|
||||
setEppInput("domain_create_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.11"));
|
||||
setEppInput(
|
||||
"domain_create_eap_fee.xml",
|
||||
ImmutableMap.of(
|
||||
"FEE_VERSION",
|
||||
"0.11",
|
||||
"DESCRIPTION_1",
|
||||
"create",
|
||||
"DESCRIPTION_2",
|
||||
"Early Access Period"));
|
||||
persistContactsAndHosts();
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
|
@ -2195,7 +2285,15 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
|||
|
||||
@Test
|
||||
public void testSuccess_eapFeeApplied_v12() throws Exception {
|
||||
setEppInput("domain_create_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.12"));
|
||||
setEppInput(
|
||||
"domain_create_eap_fee.xml",
|
||||
ImmutableMap.of(
|
||||
"FEE_VERSION",
|
||||
"0.12",
|
||||
"DESCRIPTION_1",
|
||||
"create",
|
||||
"DESCRIPTION_2",
|
||||
"Early Access Period"));
|
||||
persistContactsAndHosts();
|
||||
persistResource(
|
||||
Registry.get("tld")
|
||||
|
|
|
@ -935,7 +935,7 @@ public class DomainTransferRequestFlowTest
|
|||
setupDomain("expensive-domain", "foo");
|
||||
clock.advanceOneMilli();
|
||||
doSuccessfulTest(
|
||||
"domain_transfer_request_fee.xml",
|
||||
"domain_transfer_request_separate_fees.xml",
|
||||
"domain_transfer_request_response_fees.xml",
|
||||
domain.getRegistrationExpirationTime().plusYears(1),
|
||||
new ImmutableMap.Builder<String, String>()
|
||||
|
|
23
javatests/google/registry/flows/domain/testdata/domain_create_eap_combined_fee.xml
vendored
Normal file
23
javatests/google/registry/flows/domain/testdata/domain_create_eap_combined_fee.xml
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<create>
|
||||
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.tld</domain:name>
|
||||
<domain:period unit="y">2</domain:period>
|
||||
<domain:registrant>jd1234</domain:registrant>
|
||||
<domain:contact type="admin">sh8013</domain:contact>
|
||||
<domain:contact type="tech">sh8013</domain:contact>
|
||||
<domain:authInfo>
|
||||
<domain:pw>2fooBAR</domain:pw>
|
||||
</domain:authInfo>
|
||||
</domain:create>
|
||||
</create>
|
||||
<extension>
|
||||
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee>126.00</fee:fee>
|
||||
</fee:create>
|
||||
</extension>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -20,8 +20,8 @@
|
|||
<extension>
|
||||
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee>26.00</fee:fee>
|
||||
<fee:fee description="Early Access Period">100.00</fee:fee>
|
||||
<fee:fee description="%DESCRIPTION_1%">26.00</fee:fee>
|
||||
<fee:fee description="%DESCRIPTION_2%">100.00</fee:fee>
|
||||
</fee:create>
|
||||
</extension>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<extension>
|
||||
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee>200.00</fee:fee>
|
||||
<fee:fee description="create">200.00</fee:fee>
|
||||
<fee:fee description="Early Access Period">100.00</fee:fee>
|
||||
</fee:create>
|
||||
</extension>
|
||||
|
|
22
javatests/google/registry/flows/domain/testdata/domain_transfer_request_separate_fees.xml
vendored
Normal file
22
javatests/google/registry/flows/domain/testdata/domain_transfer_request_separate_fees.xml
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
|
||||
<command>
|
||||
<transfer op="request">
|
||||
<domain:transfer
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>%DOMAIN%</domain:name>
|
||||
<domain:period unit="y">%YEARS%</domain:period>
|
||||
<domain:authInfo>
|
||||
<domain:pw roid="JD1234-REP">2fooBAR</domain:pw>
|
||||
</domain:authInfo>
|
||||
</domain:transfer>
|
||||
</transfer>
|
||||
<extension>
|
||||
<fee:transfer xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee description="renew">11.00</fee:fee>
|
||||
<fee:fee description="transfer">100.00</fee:fee>
|
||||
</fee:transfer>
|
||||
</extension>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
</command>
|
||||
</epp>
|
|
@ -13,7 +13,8 @@
|
|||
</rgp:update>
|
||||
<fee:update xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee>28.00</fee:fee>
|
||||
<fee:fee description="restore">17.00</fee:fee>
|
||||
<fee:fee description="renew">11.00</fee:fee>
|
||||
</fee:update>
|
||||
</extension>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<command>
|
||||
<update>
|
||||
<domain:update
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
|
||||
<domain:name>example.tld</domain:name>
|
||||
<domain:chg/>
|
||||
</domain:update>
|
||||
|
@ -13,7 +13,12 @@
|
|||
</rgp:update>
|
||||
<fee:update xmlns:fee="urn:ietf:params:xml:ns:fee-%FEE_VERSION%">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee refundable="true" grace-period="P0D" applied="immediate">28.00</fee:fee>
|
||||
<fee:fee description="renew" refundable="true" grace-period="P0D" applied="immediate">
|
||||
11.00
|
||||
</fee:fee>
|
||||
<fee:fee description="restore" refundable="true" grace-period="P0D" applied="immediate">
|
||||
17.00
|
||||
</fee:fee>
|
||||
</fee:update>
|
||||
</extension>
|
||||
<clTRID>ABC-12345</clTRID>
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<extension>
|
||||
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
|
||||
<fee:currency>USD</fee:currency>
|
||||
<fee:fee>26.00</fee:fee>
|
||||
<fee:fee description="create">26.00</fee:fee>
|
||||
<fee:fee description="Early Access Period">100.00</fee:fee>
|
||||
</fee:create>
|
||||
</extension>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue