Show price of reserved domains when using matching allocation token (#632)

* Show price of reserved domains when using matching allocation token

When the registrar passes the fee extension, this shows the price of the domain
on a check command for reserved domains if the provided allocation token is a
match. Of course, the price is already always displayed on non-reserved names
(regardless of whether the specific provided token is a match or not).

This affects domain checks only; the price is already always displayed on domain
creates because you already by definition have access to register the domain in
question.
This commit is contained in:
Ben McIlwain 2020-06-18 11:57:22 -04:00 committed by GitHub
parent d43564172f
commit 57113b4746
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 151 additions and 9 deletions

View file

@ -163,7 +163,8 @@ public final class DomainCheckFlow implements Flow {
clientId, clientId,
now)); now));
ImmutableList.Builder<DomainCheck> checks = new ImmutableList.Builder<>(); ImmutableList.Builder<DomainCheck> checksBuilder = new ImmutableList.Builder<>();
ImmutableSet.Builder<String> availableDomains = new ImmutableSet.Builder<>();
ImmutableMap<String, TldState> tldStates = ImmutableMap<String, TldState> tldStates =
Maps.toMap(seenTlds, tld -> Registry.get(tld).getTldState(now)); Maps.toMap(seenTlds, tld -> Registry.get(tld).getTldState(now));
ImmutableMap<InternetDomainName, String> domainCheckResults = ImmutableMap<InternetDomainName, String> domainCheckResults =
@ -180,13 +181,19 @@ public final class DomainCheckFlow implements Flow {
domainCheckResults, domainCheckResults,
tldStates, tldStates,
allocationToken); allocationToken);
checks.add(DomainCheck.create(!message.isPresent(), targetId, message.orElse(null))); boolean isAvailable = !message.isPresent();
checksBuilder.add(DomainCheck.create(isAvailable, targetId, message.orElse(null)));
if (isAvailable) {
availableDomains.add(targetId);
}
} }
BeforeResponseReturnData responseData = BeforeResponseReturnData responseData =
flowCustomLogic.beforeResponse( flowCustomLogic.beforeResponse(
BeforeResponseParameters.newBuilder() BeforeResponseParameters.newBuilder()
.setDomainChecks(checks.build()) .setDomainChecks(checksBuilder.build())
.setResponseExtensions(getResponseExtensions(domainNames, now, allocationToken)) .setResponseExtensions(
getResponseExtensions(
domainNames, availableDomains.build(), now, allocationToken))
.setAsOfDate(now) .setAsOfDate(now)
.build()); .build());
return responseBuilder return responseBuilder
@ -221,6 +228,7 @@ public final class DomainCheckFlow implements Flow {
/** Handle the fee check extension. */ /** Handle the fee check extension. */
private ImmutableList<? extends ResponseExtension> getResponseExtensions( private ImmutableList<? extends ResponseExtension> getResponseExtensions(
ImmutableMap<String, InternetDomainName> domainNames, ImmutableMap<String, InternetDomainName> domainNames,
ImmutableSet<String> availableDomains,
DateTime now, DateTime now,
Optional<AllocationToken> allocationToken) Optional<AllocationToken> allocationToken)
throws EppException { throws EppException {
@ -242,7 +250,8 @@ public final class DomainCheckFlow implements Flow {
feeCheck.getCurrency(), feeCheck.getCurrency(),
now, now,
pricingLogic, pricingLogic,
allocationToken); allocationToken,
availableDomains.contains(domainName));
responseItems.add(builder.setDomainNameIfSupported(domainName).build()); responseItems.add(builder.setDomainNameIfSupported(domainName).build());
} }
} }

View file

@ -555,7 +555,8 @@ public class DomainFlowUtils {
@Nullable CurrencyUnit topLevelCurrency, @Nullable CurrencyUnit topLevelCurrency,
DateTime currentDate, DateTime currentDate,
DomainPricingLogic pricingLogic, DomainPricingLogic pricingLogic,
Optional<AllocationToken> allocationToken) Optional<AllocationToken> allocationToken,
boolean isAvailable)
throws EppException { throws EppException {
DateTime now = currentDate; DateTime now = currentDate;
// Use the custom effective date specified in the fee check request, if there is one. // Use the custom effective date specified in the fee check request, if there is one.
@ -587,7 +588,8 @@ public class DomainFlowUtils {
ImmutableList<Fee> fees = ImmutableList.of(); ImmutableList<Fee> fees = ImmutableList.of();
switch (feeRequest.getCommandName()) { switch (feeRequest.getCommandName()) {
case CREATE: case CREATE:
if (isReserved(domain, isSunrise)) { // Don't return a create price for reserved names. // Don't return a create price for reserved names.
if (isReserved(domain, isSunrise) && !isAvailable) {
builder.setClass("reserved"); // Override whatever class we've set above. builder.setClass("reserved"); // Override whatever class we've set above.
builder.setAvailIfSupported(false); builder.setAvailIfSupported(false);
builder.setReasonIfSupported("reserved"); builder.setReasonIfSupported("reserved");

View file

@ -164,7 +164,8 @@ public final class DomainInfoFlow implements Flow {
null, null,
now, now,
pricingLogic, pricingLogic,
Optional.empty()); Optional.empty(),
false);
extensions.add(builder.build()); extensions.add(builder.build());
} }
return extensions.build(); return extensions.build();

View file

@ -191,6 +191,21 @@ public class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFl
create(true, "specificuse.tld", null)); create(true, "specificuse.tld", null));
} }
@Test
public void testSuccess_allocationTokenForReservedDomain_showsFee() throws Exception {
setEppInput("domain_check_allocationtoken_fee_specificuse.xml");
createTld("example");
persistResource(
new AllocationToken.Builder()
.setDomainName("specificuse.tld")
.setToken("abc123")
.setTokenType(SINGLE_USE)
.build());
// Fees are shown for all non-reserved domains and the reserved domain matching this
// allocation token.
runFlowAssertResponse(loadFile("domain_check_allocationtoken_fee_specificuse_response.xml"));
}
@Test @Test
public void testSuccess_oneExists_allocationTokenForWrongDomain() throws Exception { public void testSuccess_oneExists_allocationTokenForWrongDomain() throws Exception {
setEppInput("domain_check_allocationtoken.xml"); setEppInput("domain_check_allocationtoken.xml");
@ -440,7 +455,10 @@ public class DomainCheckFlowTest extends ResourceCheckFlowTestCase<DomainCheckFl
@Test @Test
public void testSuccess_duplicatesAllowed() throws Exception { public void testSuccess_duplicatesAllowed() throws Exception {
setEppInput("domain_check_duplicates.xml"); setEppInput("domain_check_duplicates.xml");
doCheckTest(create(true, "example1.tld", null), create(true, "example1.tld", null)); doCheckTest(
create(true, "example1.tld", null),
create(true, "example2.tld", null),
create(true, "example1.tld", null));
} }
@Test @Test

View file

@ -0,0 +1,48 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<check>
<domain:check
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example1.tld</domain:name>
<domain:name>example2.example</domain:name>
<domain:name>reserved.tld</domain:name>
<domain:name>specificuse.tld</domain:name>
</domain:check>
</check>
<extension>
<allocationToken:allocationToken
xmlns:allocationToken=
"urn:ietf:params:xml:ns:allocationToken-1.0">
abc123
</allocationToken:allocationToken>
<fee:check
xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
<fee:domain>
<fee:name>example1.tld</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
</fee:domain>
<fee:domain>
<fee:name>example2.example</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
</fee:domain>
<fee:domain>
<fee:name>reserved.tld</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
</fee:domain>
<fee:domain>
<fee:name>specificuse.tld</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
</fee:domain>
</fee:check>
</extension>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<epp xmlns:launch="urn:ietf:params:xml:ns:launch-1.0" xmlns:secDNS="urn:ietf:params:xml:ns:secDNS-1.1" xmlns:host="urn:ietf:params:xml:ns:host-1.0" xmlns:fee11="urn:ietf:params:xml:ns:fee-0.11" xmlns:fee12="urn:ietf:params:xml:ns:fee-0.12" xmlns:fee="urn:ietf:params:xml:ns:fee-0.6" xmlns:rgp="urn:ietf:params:xml:ns:rgp-1.0" xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xmlns:contact="urn:ietf:params:xml:ns:contact-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:chkData>
<domain:cd>
<domain:name avail="false">example1.tld</domain:name>
<domain:reason>Alloc token invalid for domain</domain:reason>
</domain:cd>
<domain:cd>
<domain:name avail="false">example2.example</domain:name>
<domain:reason>Alloc token invalid for domain</domain:reason>
</domain:cd>
<domain:cd>
<domain:name avail="false">reserved.tld</domain:name>
<domain:reason>Reserved</domain:reason>
</domain:cd>
<domain:cd>
<domain:name avail="true">specificuse.tld</domain:name>
</domain:cd>
</domain:chkData>
</resData>
<extension>
<fee:chkData>
<fee:cd>
<fee:name>example2.example</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
<fee:fee description="create">13.00</fee:fee>
</fee:cd>
<fee:cd>
<fee:name>example1.tld</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
<fee:fee description="create">13.00</fee:fee>
</fee:cd>
<fee:cd>
<fee:name>reserved.tld</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
<fee:class>reserved</fee:class>
</fee:cd>
<fee:cd>
<fee:name>specificuse.tld</fee:name>
<fee:currency>USD</fee:currency>
<fee:command>create</fee:command>
<fee:period unit="y">1</fee:period>
<fee:fee description="create">13.00</fee:fee>
</fee:cd>
</fee:chkData>
</extension>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>server-trid</svTRID>
</trID>
</response>
</epp>

View file

@ -3,6 +3,7 @@
<check> <check>
<domain:check xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"> <domain:check xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example1.tld</domain:name> <domain:name>example1.tld</domain:name>
<domain:name>example2.tld</domain:name>
<domain:name>example1.tld</domain:name> <domain:name>example1.tld</domain:name>
</domain:check> </domain:check>
</check> </check>