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
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue