Add extra flow logic hook for application create

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=137396935
This commit is contained in:
mountford 2016-10-27 08:18:39 -07:00 committed by Ben McIlwain
parent bc0116f3a0
commit 60cb1b4dfb
5 changed files with 113 additions and 0 deletions

View file

@ -44,6 +44,7 @@ import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.label.ReservedList.matchesAnchorTenantReservation;
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -233,6 +234,8 @@ public final class DomainApplicationCreateFlow extends LoggedInFlow implements T
DomainApplication newApplication = applicationBuilder.build();
HistoryEntry historyEntry = buildHistory(newApplication.getRepoId(), command.getPeriod());
ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>();
handleExtraFlowLogic(
registry.getTldStr(), command.getPeriod().getValue(), historyEntry, newApplication);
entitiesToSave.add(
newApplication,
historyEntry,
@ -333,6 +336,23 @@ public final class DomainApplicationCreateFlow extends LoggedInFlow implements T
return responseExtensionsBuilder.build();
}
private void handleExtraFlowLogic(
String tld, int years, HistoryEntry historyEntry, DomainApplication newApplication)
throws EppException {
Optional<RegistryExtraFlowLogic> extraFlowLogic =
RegistryExtraFlowLogicProxy.newInstanceForTld(tld);
if (extraFlowLogic.isPresent()) {
extraFlowLogic.get().performAdditionalApplicationCreateLogic(
newApplication,
clientId,
now,
years,
eppInput,
historyEntry);
extraFlowLogic.get().commitAdditionalLogicChanges();
}
}
/** Landrush applications are disallowed during sunrise. */
static class LandrushApplicationDisallowedDuringSunriseException
extends RequiredParameterMissingException {

View file

@ -15,6 +15,7 @@
package google.registry.flows.domain;
import google.registry.flows.EppException;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.DomainResource;
import google.registry.model.domain.fee.BaseFee;
import google.registry.model.eppinput.EppInput;
@ -36,6 +37,20 @@ public interface RegistryExtraFlowLogic {
public Set<String> getExtensionFlags(
DomainResource domainResource, String clientId, DateTime asOfDate);
/**
* Performs additional tasks required for an application create command.
*
* <p>Any changes should not be persisted to Datastore until commitAdditionalLogicChanges is
* called.
*/
public void performAdditionalApplicationCreateLogic(
DomainApplication application,
String clientId,
DateTime asOfDate,
int years,
EppInput eppInput,
HistoryEntry historyEntry) throws EppException;
/**
* Computes the expected creation fee.
*

View file

@ -105,6 +105,8 @@ import google.registry.flows.exceptions.ResourceAlreadyExistsException;
import google.registry.model.domain.DomainApplication;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.LrpTokenEntity;
import google.registry.model.domain.TestExtraLogicManager;
import google.registry.model.domain.TestExtraLogicManager.TestExtraLogicManagerSuccessException;
import google.registry.model.domain.launch.ApplicationStatus;
import google.registry.model.domain.launch.LaunchNotice;
import google.registry.model.domain.launch.LaunchPhase;
@ -155,6 +157,10 @@ public class DomainApplicationCreateFlowTest
setEppInput("domain_create_sunrise_encoded_signed_mark.xml");
createTld("tld", TldState.SUNRISE);
persistResource(Registry.get("tld").asBuilder().setReservedLists(createReservedList()).build());
createTld("flags", TldState.LANDRUSH);
RegistryExtraFlowLogicProxy.setOverride("flags", TestExtraLogicManager.class);
persistResource(
Registry.get("flags").asBuilder().setReservedLists(createReservedList()).build());
inject.setStaticField(TmchCertificateAuthority.class, "clock", clock);
clock.setTo(DateTime.parse("2014-09-09T09:09:09Z"));
}
@ -1686,4 +1692,20 @@ public class DomainApplicationCreateFlowTest
// .tld
doFailingDomainNameTest("xn--k3hel9n7bxlu1e.tld", InvalidIdnDomainLabelException.class);
}
@Test
public void testFailure_flags_feeMismatch() throws Exception {
persistContactsAndHosts();
setEppInput("domain_create_landrush_flags.xml", ImmutableMap.of("FEE", "12"));
thrown.expect(FeesMismatchException.class);
runFlow();
}
@Test
public void testSuccess_flags() throws Exception {
persistContactsAndHosts();
setEppInput("domain_create_landrush_flags.xml", ImmutableMap.of("FEE", "42"));
thrown.expect(TestExtraLogicManagerSuccessException.class, "flag1,flag2");
runFlow();
}
}

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>create-42.flags</domain:name>
<domain:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
</domain:ns>
<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>
<launch:create
xmlns:launch="urn:ietf:params:xml:ns:launch-1.0">
<launch:phase>landrush</launch:phase>
</launch:create>
<fee:create xmlns:fee="urn:ietf:params:xml:ns:fee-0.6">
<fee:currency>USD</fee:currency>
<fee:fee>%FEE%</fee:fee>
</fee:create>
<flags:create xmlns:flags="urn:google:params:xml:ns:flags-0.1">
<flags:flag>flag1</flags:flag>
<flags:flag>flag2</flags:flag>
</flags:create>
</extension>
<clTRID>ABC-12345</clTRID>
</command>
</epp>

View file

@ -99,6 +99,26 @@ public class TestExtraLogicManager implements RegistryExtraFlowLogic {
}
}
/**
* Performs additional tasks required for an application create command. Any changes should not be
* persisted to Datastore until commitAdditionalLogicChanges is called.
*/
@Override
public void performAdditionalApplicationCreateLogic(
DomainApplication application,
String clientId,
DateTime asOfDate,
int years,
EppInput eppInput,
HistoryEntry historyEntry) throws EppException {
FlagsCreateCommandExtension flags =
eppInput.getSingleExtension(FlagsCreateCommandExtension.class);
if (flags == null) {
return;
}
messageToThrow = Joiner.on(',').join(flags.getFlags());
}
/** Computes the expected create cost, for use in fee challenges and the like. */
@Override
public BaseFee getCreateFeeOrCredit(