Handle missing expected fee type in domain create

Also added a couple of more tests to make sure that we cover all edge cases.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=195872013
This commit is contained in:
jianglai 2018-05-08 14:01:13 -07:00
parent 297b8df6a1
commit e5538cfe35
3 changed files with 146 additions and 8 deletions

View file

@ -42,6 +42,7 @@ import static google.registry.util.DomainNameUtils.ACE_PREFIX;
import com.google.common.base.CharMatcher;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
@ -698,9 +699,6 @@ public class DomainFlowUtils {
if (!feeTotal.getCurrencyUnit().equals(feesAndCredits.getCurrency())) {
throw new CurrencyUnitMismatchException();
}
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());
@ -708,13 +706,20 @@ public class DomainFlowUtils {
ImmutableMap<FeeType, Money> providedFeeMap =
buildFeeMap(feeCommand.get().getFees(), feeCommand.get().getCurrency());
for (FeeType type : expectedFeeMap.keySet()) {
Money providedCost = providedFeeMap.get(type);
if (!providedFeeMap.containsKey(type)) {
throw new FeesMismatchException(type);
}
Money expectedCost = expectedFeeMap.get(type);
if (!providedCost.isEqual(expectedCost)) {
if (!providedFeeMap.get(type).isEqual(expectedCost)) {
throw new FeesMismatchException(type, expectedCost);
}
}
}
// Checking if total amount is expected. Extra fees that we are not expecting may be passed in.
// Or if there is only a single fee type expected.
if (!feeTotal.equals(feesAndCredits.getTotalCost())) {
throw new FeesMismatchException(feesAndCredits.getTotalCost());
}
}
private static FeeType getOrParseType(Fee fee) throws ParameterValuePolicyErrorException {
@ -1333,6 +1338,13 @@ public class DomainFlowUtils {
correctFee));
}
public FeesMismatchException(FeeType type) {
super(
String.format(
"The fees passed in the transform command do not contain expected fee type \"%s\"",
type));
}
public FeesMismatchException(FeeType type, Money correctFee) {
super(
String.format(
@ -1346,9 +1358,12 @@ public class DomainFlowUtils {
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));
(Strings.isNullOrEmpty(description)
? "No fee description is present in the command, "
: "The fee description \""
+ description
+ "\" passed in the command cannot be parsed, ")
+ "please perform a domain check to obtain expected fee descriptions.");
}
}