mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Make EAP fee description check more flexible
Currently we determine fee type from the fee extension description by checking if the format string of the FeeType contains the description we received. The formatting string for EAP is "Early Access Period, fee expires: %s", so the fee description generated by a domain check command, like "Early Access Period, fee expires: 2022-03-01T00:00:00.000Z", is not recognized as EAP. This CL adds the ability to add arbitrary extra description strings to the FeeType for a description to match against. It also changes the match to "the given description contains any of the strings from the list of format string plus extra description strings". For EAP, we added an extra description string "Early Access Period", so any fee description that contains "Early Access Period" will be matched to EAP FeeType, including the specific description (that contains the expiry time) that we send in a domain check. Also improved error message on multiple fee type matching. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=194149162
This commit is contained in:
parent
4d3065c7ab
commit
82ded21b9e
3 changed files with 50 additions and 9 deletions
|
@ -120,6 +120,7 @@ import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import org.joda.money.CurrencyUnit;
|
import org.joda.money.CurrencyUnit;
|
||||||
import org.joda.money.Money;
|
import org.joda.money.Money;
|
||||||
|
@ -724,7 +725,7 @@ public class DomainFlowUtils {
|
||||||
if (types.size() == 0) {
|
if (types.size() == 0) {
|
||||||
throw new FeeDescriptionParseException(fee.getDescription());
|
throw new FeeDescriptionParseException(fee.getDescription());
|
||||||
} else if (types.size() > 1) {
|
} else if (types.size() > 1) {
|
||||||
throw new FeeDescriptionMultipleMatchesException(fee.getDescription());
|
throw new FeeDescriptionMultipleMatchesException(fee.getDescription(), types);
|
||||||
} else {
|
} else {
|
||||||
return types.get(0);
|
return types.get(0);
|
||||||
}
|
}
|
||||||
|
@ -1354,11 +1355,13 @@ public class DomainFlowUtils {
|
||||||
/** The fee description passed in the transform command matches multiple fee types. */
|
/** The fee description passed in the transform command matches multiple fee types. */
|
||||||
public static class FeeDescriptionMultipleMatchesException
|
public static class FeeDescriptionMultipleMatchesException
|
||||||
extends ParameterValuePolicyErrorException {
|
extends ParameterValuePolicyErrorException {
|
||||||
public FeeDescriptionMultipleMatchesException(String description) {
|
public FeeDescriptionMultipleMatchesException(
|
||||||
|
String description, ImmutableList<FeeType> types) {
|
||||||
super(
|
super(
|
||||||
String.format(
|
String.format(
|
||||||
"The fee description \"%s\" passed in the transform matches multiple fee types",
|
"The fee description \"%s\" passed in the transform matches multiple fee types: %s",
|
||||||
description));
|
description,
|
||||||
|
types.stream().map(FeeType::toString).collect(Collectors.joining(", "))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ public abstract class BaseFee extends ImmutableObject {
|
||||||
/** Enum for the type of the fee. */
|
/** Enum for the type of the fee. */
|
||||||
public enum FeeType {
|
public enum FeeType {
|
||||||
CREATE("create"),
|
CREATE("create"),
|
||||||
EAP("Early Access Period, fee expires: %s"),
|
EAP("Early Access Period, fee expires: %s", "Early Access Period"),
|
||||||
RENEW("renew"),
|
RENEW("renew"),
|
||||||
RESTORE("restore"),
|
RESTORE("restore"),
|
||||||
/**
|
/**
|
||||||
|
@ -65,8 +65,11 @@ public abstract class BaseFee extends ImmutableObject {
|
||||||
|
|
||||||
private final String formatString;
|
private final String formatString;
|
||||||
|
|
||||||
FeeType(String formatString) {
|
private final ImmutableList<String> extraAcceptableDescriptions;
|
||||||
|
|
||||||
|
FeeType(String formatString, String... extraAcceptableDescriptions) {
|
||||||
this.formatString = formatString;
|
this.formatString = formatString;
|
||||||
|
this.extraAcceptableDescriptions = ImmutableList.copyOf(extraAcceptableDescriptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
String renderDescription(Object... args) {
|
String renderDescription(Object... args) {
|
||||||
|
@ -74,7 +77,14 @@ public abstract class BaseFee extends ImmutableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean matchFormatString(String description) {
|
boolean matchFormatString(String description) {
|
||||||
return Ascii.toLowerCase(formatString).contains(Ascii.toLowerCase(description));
|
return new ImmutableList.Builder<String>()
|
||||||
|
.add(formatString)
|
||||||
|
.addAll(extraAcceptableDescriptions)
|
||||||
|
.build()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(
|
||||||
|
expectedDescription ->
|
||||||
|
Ascii.toLowerCase(description).contains(Ascii.toLowerCase(expectedDescription)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2277,12 +2277,40 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSuccess_eapFee_fullDescription_includingArbitraryExpiryTime() throws Exception {
|
||||||
|
setEppInput(
|
||||||
|
"domain_create_eap_fee.xml",
|
||||||
|
ImmutableMap.of(
|
||||||
|
"FEE_VERSION",
|
||||||
|
"0.6",
|
||||||
|
"DESCRIPTION_1",
|
||||||
|
"create",
|
||||||
|
"DESCRIPTION_2",
|
||||||
|
"Early Access Period, fee expires: 2022-03-01T00:00:00.000Z"));
|
||||||
|
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());
|
||||||
|
doSuccessfulTest(
|
||||||
|
"tld", "domain_create_response_eap_fee.xml", ImmutableMap.of("FEE_VERSION", "0.6"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFailure_eapFee_description_multipleMatch() throws Exception {
|
public void testFailure_eapFee_description_multipleMatch() throws Exception {
|
||||||
setEppInput(
|
setEppInput(
|
||||||
"domain_create_eap_fee.xml",
|
"domain_create_eap_fee.xml",
|
||||||
ImmutableMap.of(
|
ImmutableMap.of(
|
||||||
"FEE_VERSION", "0.6", "DESCRIPTION_1", "Early Access Period", "DESCRIPTION_2", "ea"));
|
"FEE_VERSION", "0.6", "DESCRIPTION_1", "create", "DESCRIPTION_2", "renew transfer"));
|
||||||
persistContactsAndHosts();
|
persistContactsAndHosts();
|
||||||
persistResource(
|
persistResource(
|
||||||
Registry.get("tld")
|
Registry.get("tld")
|
||||||
|
@ -2297,7 +2325,7 @@ public class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow,
|
||||||
Money.of(USD, 0)))
|
Money.of(USD, 0)))
|
||||||
.build());
|
.build());
|
||||||
EppException thrown = assertThrows(FeeDescriptionMultipleMatchesException.class, this::runFlow);
|
EppException thrown = assertThrows(FeeDescriptionMultipleMatchesException.class, this::runFlow);
|
||||||
assertThat(thrown).hasMessageThat().contains("ea");
|
assertThat(thrown).hasMessageThat().contains("RENEW, TRANSFER");
|
||||||
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
assertAboutEppExceptions().that(thrown).marshalsToXml();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue