From 09beacf7465a27b728f8b1c6adea46fff09619e3 Mon Sep 17 00:00:00 2001 From: mountford Date: Wed, 9 Nov 2016 13:41:45 -0800 Subject: [PATCH] Add extra flow logic hook for domain allocation ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=138679232 --- .../flows/domain/DomainAllocateFlow.java | 18 ++++++++++++++++ .../flows/domain/RegistryExtraFlowLogic.java | 9 ++++++++ .../flows/domain/DomainAllocateFlowTest.java | 21 +++++++++++++++++-- .../flows/domain/testdata/domain_allocate.xml | 2 +- .../model/domain/TestExtraLogicManager.java | 12 +++++++++++ 5 files changed, 59 insertions(+), 3 deletions(-) diff --git a/java/google/registry/flows/domain/DomainAllocateFlow.java b/java/google/registry/flows/domain/DomainAllocateFlow.java index 73d302c3b..413feba5b 100644 --- a/java/google/registry/flows/domain/DomainAllocateFlow.java +++ b/java/google/registry/flows/domain/DomainAllocateFlow.java @@ -37,6 +37,7 @@ import static google.registry.util.CollectionUtils.isNullOrEmpty; import static google.registry.util.DateTimeUtils.END_OF_TIME; import static google.registry.util.DateTimeUtils.leapSafeAddYears; +import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.net.InternetDomainName; @@ -175,6 +176,7 @@ public class DomainAllocateFlow implements TransactionalFlow { .setNameservers(command.getNameservers()) .setContacts(command.getContacts()) .build(); + handleExtraFlowLogic(registry.getTldStr(), years, historyEntry, newDomain, now); entitiesToSave.add( newDomain, buildApplicationHistory(application, now), @@ -360,6 +362,22 @@ public class DomainAllocateFlow implements TransactionalFlow { && !matchesAnchorTenantReservation(domainName, authInfoToken); } + private void handleExtraFlowLogic( + String tld, int years, HistoryEntry historyEntry, DomainResource newDomain, DateTime now) + throws EppException { + Optional extraFlowLogic = + RegistryExtraFlowLogicProxy.newInstanceForTld(tld); + if (extraFlowLogic.isPresent()) { + extraFlowLogic.get().performAdditionalDomainAllocateLogic( + newDomain, + clientId, + now, + years, + eppInput, + historyEntry); + } + } + private void enqueueTasks(AllocateCreateExtension allocateCreate, DomainResource newDomain) { if (newDomain.shouldPublishToDns()) { DnsQueue.create().addDomainRefreshTask(newDomain.getFullyQualifiedDomainName()); diff --git a/java/google/registry/flows/domain/RegistryExtraFlowLogic.java b/java/google/registry/flows/domain/RegistryExtraFlowLogic.java index f9da770f9..96e550fe9 100644 --- a/java/google/registry/flows/domain/RegistryExtraFlowLogic.java +++ b/java/google/registry/flows/domain/RegistryExtraFlowLogic.java @@ -69,6 +69,15 @@ public interface RegistryExtraFlowLogic { EppInput eppInput, HistoryEntry historyEntry) throws EppException; + /** Performs additional tasks required for an allocate command. */ + public void performAdditionalDomainAllocateLogic( + DomainResource domain, + String clientId, + DateTime asOfDate, + int years, + EppInput eppInput, + HistoryEntry historyEntry) throws EppException; + /** Computes the expected creation fee. */ public BaseFee getCreateFeeOrCredit( String domainName, diff --git a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java index 5286258de..dc0e4fee8 100644 --- a/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java +++ b/javatests/google/registry/flows/domain/DomainAllocateFlowTest.java @@ -52,6 +52,8 @@ import google.registry.model.billing.BillingEvent.Reason; import google.registry.model.domain.DomainApplication; import google.registry.model.domain.DomainResource; import google.registry.model.domain.GracePeriod; +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.LaunchInfoResponseExtension; import google.registry.model.domain.launch.LaunchNotice; @@ -92,7 +94,9 @@ public class DomainAllocateFlowTest @Before public void initAllocateTest() throws Exception { - setEppInput("domain_allocate.xml", ImmutableMap.of("APPLICATIONID", "2-TLD")); + setEppInput( + "domain_allocate.xml", + ImmutableMap.of("APPLICATIONID", "2-TLD", "DOMAIN", "example-one.tld")); clock.setTo(APPLICATION_TIME); } @@ -378,7 +382,9 @@ public class DomainAllocateFlowTest @Test public void testSuccess_hexApplicationId() throws Exception { - setEppInput("domain_allocate.xml", ImmutableMap.of("APPLICATIONID", "A-TLD")); + setEppInput( + "domain_allocate.xml", + ImmutableMap.of("APPLICATIONID", "A-TLD", "DOMAIN", "example-one.tld")); applicationId = "A-TLD"; // Grab the next 8 ids so that when the application is created it gets dec 10, or hex A. // (one additional ID goes to the reserved list created before the application). @@ -485,4 +491,15 @@ public class DomainAllocateFlowTest thrown.expect(OnlySuperuserCanAllocateException.class); runFlow(CommitMode.LIVE, UserPrivileges.NORMAL); } + + @Test + public void testSuccess_extra() throws Exception { + setEppInput( + "domain_allocate.xml", + ImmutableMap.of("APPLICATIONID", "2-EXTRA", "DOMAIN", "domain.extra")); + setupDomainApplication("extra", TldState.QUIET_PERIOD); + RegistryExtraFlowLogicProxy.setOverride("extra", TestExtraLogicManager.class); + thrown.expect(TestExtraLogicManagerSuccessException.class, "allocated"); + runFlowAsSuperuser(); + } } diff --git a/javatests/google/registry/flows/domain/testdata/domain_allocate.xml b/javatests/google/registry/flows/domain/testdata/domain_allocate.xml index 265402f7b..e9cd898fb 100644 --- a/javatests/google/registry/flows/domain/testdata/domain_allocate.xml +++ b/javatests/google/registry/flows/domain/testdata/domain_allocate.xml @@ -3,7 +3,7 @@ - example-one.tld + %DOMAIN% 2 ns1.example.net diff --git a/javatests/google/registry/model/domain/TestExtraLogicManager.java b/javatests/google/registry/model/domain/TestExtraLogicManager.java index 4c1259e79..a03332355 100644 --- a/javatests/google/registry/model/domain/TestExtraLogicManager.java +++ b/javatests/google/registry/model/domain/TestExtraLogicManager.java @@ -165,6 +165,18 @@ public class TestExtraLogicManager implements RegistryExtraFlowLogic { return domainNameToFeeOrCredit(domainName); } + /** Performs additional tasks required for an allocate command. */ + @Override + public void performAdditionalDomainAllocateLogic( + DomainResource domain, + String clientId, + DateTime asOfDate, + int years, + EppInput eppInput, + HistoryEntry historyEntry) throws EppException { + throw new TestExtraLogicManagerSuccessException("allocated"); + } + /** Performs additional tasks required for a create command. */ @Override public void performAdditionalDomainCreateLogic(