Flatten the domain transfer flows

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=133906420
This commit is contained in:
cgoldfeder 2016-09-21 19:17:07 -07:00 committed by Ben McIlwain
parent 2d46c7c27c
commit 1b34f1e326
19 changed files with 848 additions and 351 deletions

View file

@ -337,7 +337,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
DateTime.parse("2001-01-01T00:01:00Z"));
assertCommandAndResponse(
"poll_ack.xml",
ImmutableMap.of("ID", "1-B-EXAMPLE-17-21"),
ImmutableMap.of("ID", "1-B-EXAMPLE-17-23"),
"poll_ack_response_empty.xml",
null,
DateTime.parse("2001-01-01T00:01:00Z"));
@ -349,7 +349,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
DateTime.parse("2001-01-06T00:01:00Z"));
assertCommandAndResponse(
"poll_ack.xml",
ImmutableMap.of("ID", "1-B-EXAMPLE-17-23"),
ImmutableMap.of("ID", "1-B-EXAMPLE-17-22"),
"poll_ack_response_empty.xml",
null,
DateTime.parse("2001-01-06T00:01:00Z"));
@ -365,7 +365,7 @@ public class EppLifecycleDomainTest extends EppTestCase {
DateTime.parse("2001-01-06T00:02:00Z"));
assertCommandAndResponse(
"poll_ack.xml",
ImmutableMap.of("ID", "1-B-EXAMPLE-17-22"),
ImmutableMap.of("ID", "1-B-EXAMPLE-17-21"),
"poll_ack_response_empty.xml",
null,
DateTime.parse("2001-01-06T00:02:00Z"));

View file

@ -304,7 +304,7 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
}
/** Run a flow, marshal the result to EPP, and assert that the output is as expected. */
public void runFlowAssertResponse(
public EppOutput runFlowAssertResponse(
CommitMode commitMode, UserPrivileges userPrivileges, String xml, String... ignoredPaths)
throws Exception {
// Always ignore the server trid, since it's generated and meaningless to flow correctness.
@ -332,15 +332,18 @@ public abstract class FlowTestCase<F extends Flow> extends ShardableTestCase {
}
// Clear the cache so that we don't see stale results in tests.
ofy().clearSessionCache();
return output;
}
public void dryRunFlowAssertResponse(String xml, String... ignoredPaths) throws Exception {
public EppOutput dryRunFlowAssertResponse(String xml, String... ignoredPaths) throws Exception {
List<Object> beforeEntities = ofy().load().list();
runFlowAssertResponse(CommitMode.DRY_RUN, UserPrivileges.NORMAL, xml, ignoredPaths);
EppOutput output =
runFlowAssertResponse(CommitMode.DRY_RUN, UserPrivileges.NORMAL, xml, ignoredPaths);
assertThat(ofy().load()).containsExactlyElementsIn(beforeEntities);
return output;
}
public void runFlowAssertResponse(String xml, String... ignoredPaths) throws Exception {
runFlowAssertResponse(CommitMode.LIVE, UserPrivileges.NORMAL, xml, ignoredPaths);
public EppOutput runFlowAssertResponse(String xml, String... ignoredPaths) throws Exception {
return runFlowAssertResponse(CommitMode.LIVE, UserPrivileges.NORMAL, xml, ignoredPaths);
}
}

View file

@ -14,6 +14,7 @@
package google.registry.flows.domain;
import static com.google.common.collect.Iterables.getOnlyElement;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.EppResourceUtils.loadByUniqueId;
import static google.registry.model.ofy.ObjectifyService.ofy;
@ -39,9 +40,9 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
import google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException;
import google.registry.flows.ResourceMutatePendingTransferFlow.NotPendingTransferException;
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
import google.registry.flows.exceptions.NotPendingTransferException;
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
import google.registry.model.EppResource;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Cancellation;
@ -61,7 +62,7 @@ import google.registry.model.poll.PollMessage;
import google.registry.model.registrar.Registrar;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferResponse;
import google.registry.model.transfer.TransferResponse.DomainTransferResponse;
import google.registry.model.transfer.TransferStatus;
import org.joda.money.Money;
import org.joda.time.DateTime;
@ -212,12 +213,12 @@ public class DomainTransferApproveFlowTest
assertThat(gainingTransferPollMessage.getEventTime()).isEqualTo(clock.nowUtc());
assertThat(gainingAutorenewPollMessage.getEventTime())
.isEqualTo(domain.getRegistrationExpirationTime());
assertThat(
Iterables.getOnlyElement(FluentIterable
.from(gainingTransferPollMessage.getResponseData())
.filter(TransferResponse.class))
.getTransferStatus())
.isEqualTo(TransferStatus.CLIENT_APPROVED);
DomainTransferResponse transferResponse = getOnlyElement(FluentIterable
.from(gainingTransferPollMessage.getResponseData())
.filter(DomainTransferResponse.class));
assertThat(transferResponse.getTransferStatus()).isEqualTo(TransferStatus.CLIENT_APPROVED);
assertThat(transferResponse.getExtendedRegistrationExpirationTime())
.isEqualTo(domain.getRegistrationExpirationTime());
PendingActionNotificationResponse panData = Iterables.getOnlyElement(FluentIterable
.from(gainingTransferPollMessage.getResponseData())
.filter(PendingActionNotificationResponse.class));

View file

@ -27,10 +27,10 @@ import static google.registry.util.DateTimeUtils.END_OF_TIME;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException;
import google.registry.flows.ResourceMutatePendingTransferFlow.NotPendingTransferException;
import google.registry.flows.ResourceTransferCancelFlow.NotTransferInitiatorException;
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
import google.registry.flows.exceptions.NotPendingTransferException;
import google.registry.flows.exceptions.NotTransferInitiatorException;
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
import google.registry.model.contact.ContactAuthInfo;
import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainResource;

View file

@ -15,6 +15,7 @@
package google.registry.flows.domain;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.domain.DomainResource.extendRegistrationWithCap;
import static google.registry.testing.DatastoreHelper.assertBillingEvents;
import static google.registry.testing.DatastoreHelper.deleteResource;
import static google.registry.testing.DatastoreHelper.getPollMessages;
@ -22,15 +23,18 @@ import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.DomainResourceSubject.assertAboutDomains;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceQueryFlow.ResourceToQueryDoesNotExistException;
import google.registry.flows.ResourceTransferQueryFlow.NoTransferHistoryToQueryException;
import google.registry.flows.ResourceTransferQueryFlow.NotAuthorizedToViewTransferException;
import google.registry.flows.exceptions.NoTransferHistoryToQueryException;
import google.registry.flows.exceptions.NotAuthorizedToViewTransferException;
import google.registry.flows.exceptions.ResourceToQueryDoesNotExistException;
import google.registry.model.contact.ContactAuthInfo;
import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainResource;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.eppoutput.EppOutput;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferResponse.DomainTransferResponse;
import google.registry.model.transfer.TransferStatus;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
@ -45,14 +49,16 @@ public class DomainTransferQueryFlowTest
setupDomainWithPendingTransfer();
}
private void doSuccessfulTest(String commandFilename, String expectedXmlFilename)
throws Exception {
private void doSuccessfulTest(
String commandFilename,
String expectedXmlFilename,
DateTime newExpirationTime) throws Exception {
setEppInput(commandFilename);
// Replace the ROID in the xml file with the one generated in our test.
eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
// Setup done; run the test.
assertTransactionalFlow(false);
runFlowAssertResponse(readFile(expectedXmlFilename));
EppOutput output = runFlowAssertResponse(readFile(expectedXmlFilename));
assertAboutDomains().that(domain).hasOneHistoryEntryEachOfTypes(
HistoryEntry.Type.DOMAIN_CREATE,
HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST);
@ -61,10 +67,11 @@ public class DomainTransferQueryFlowTest
getGainingClientAutorenewEvent(),
getLosingClientAutorenewEvent());
// Look in the future and make sure the poll messages for implicit ack are there.
assertThat(getPollMessages("NewRegistrar", clock.nowUtc().plusYears(1)))
.hasSize(1);
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusYears(1)))
.hasSize(1);
assertThat(getPollMessages("NewRegistrar", clock.nowUtc().plusYears(1))).hasSize(1);
assertThat(getPollMessages("TheRegistrar", clock.nowUtc().plusYears(1))).hasSize(1);
DomainTransferResponse response =
((DomainTransferResponse) output.getResponse().getResponseData().get(0));
assertThat(response.getExtendedRegistrationExpirationTime()).isEqualTo(newExpirationTime);
}
private void doFailingTest(String commandFilename) throws Exception {
@ -78,61 +85,95 @@ public class DomainTransferQueryFlowTest
@Test
public void testSuccess() throws Exception {
doSuccessfulTest("domain_transfer_query.xml", "domain_transfer_query_response.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response.xml",
domain.getRegistrationExpirationTime().plusYears(1));
}
@Test
public void testSuccess_sponsoringClient() throws Exception {
setClientIdForFlow("TheRegistrar");
doSuccessfulTest("domain_transfer_query.xml", "domain_transfer_query_response.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response.xml",
domain.getRegistrationExpirationTime().plusYears(1));
}
@Test
public void testSuccess_domainAuthInfo() throws Exception {
setClientIdForFlow("ClientZ");
doSuccessfulTest("domain_transfer_query_domain_authinfo.xml",
"domain_transfer_query_response.xml");
doSuccessfulTest(
"domain_transfer_query_domain_authinfo.xml",
"domain_transfer_query_response.xml",
domain.getRegistrationExpirationTime().plusYears(1));
}
@Test
public void testSuccess_contactAuthInfo() throws Exception {
setClientIdForFlow("ClientZ");
doSuccessfulTest("domain_transfer_query_contact_authinfo.xml",
"domain_transfer_query_response.xml");
doSuccessfulTest(
"domain_transfer_query_contact_authinfo.xml",
"domain_transfer_query_response.xml",
domain.getRegistrationExpirationTime().plusYears(1));
}
@Test
public void testSuccess_clientApproved() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
doSuccessfulTest("domain_transfer_query.xml",
"domain_transfer_query_response_client_approved.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response_client_approved.xml",
domain.getRegistrationExpirationTime().plusYears(1));
}
@Test
public void testSuccess_clientRejected() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
doSuccessfulTest("domain_transfer_query.xml",
"domain_transfer_query_response_client_rejected.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response_client_rejected.xml",
null);
}
@Test
public void testSuccess_clientCancelled() throws Exception {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
doSuccessfulTest("domain_transfer_query.xml",
"domain_transfer_query_response_client_cancelled.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response_client_cancelled.xml",
null);
}
@Test
public void testSuccess_serverApproved() throws Exception {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
doSuccessfulTest("domain_transfer_query.xml",
"domain_transfer_query_response_server_approved.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response_server_approved.xml",
domain.getRegistrationExpirationTime().plusYears(1));
}
@Test
public void testSuccess_serverCancelled() throws Exception {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
doSuccessfulTest("domain_transfer_query.xml",
"domain_transfer_query_response_server_cancelled.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response_server_cancelled.xml",
null);
}
@Test
public void testSuccess_tenYears() throws Exception {
domain = persistResource(domain.asBuilder()
.setTransferData(domain.getTransferData().asBuilder()
.setExtendedRegistrationYears(10)
.build())
.build());
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response_10_years.xml",
extendRegistrationWithCap(clock.nowUtc(), domain.getRegistrationExpirationTime(), 10));
}
@Test
@ -140,8 +181,10 @@ public class DomainTransferQueryFlowTest
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
domain = persistResource(
domain.asBuilder().setDeletionTime(clock.nowUtc().plusDays(1)).build());
doSuccessfulTest("domain_transfer_query.xml",
"domain_transfer_query_response_server_cancelled.xml");
doSuccessfulTest(
"domain_transfer_query.xml",
"domain_transfer_query_response_server_cancelled.xml",
null);
}
@Test

View file

@ -28,9 +28,9 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceFlowUtils.ResourceNotOwnedException;
import google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException;
import google.registry.flows.ResourceMutatePendingTransferFlow.NotPendingTransferException;
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
import google.registry.flows.exceptions.NotPendingTransferException;
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
import google.registry.model.contact.ContactAuthInfo;
import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainResource;

View file

@ -40,11 +40,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Iterables;
import google.registry.flows.ResourceFlowUtils.BadAuthInfoForResourceException;
import google.registry.flows.ResourceMutateFlow.ResourceToMutateDoesNotExistException;
import google.registry.flows.ResourceTransferRequestFlow.AlreadyPendingTransferException;
import google.registry.flows.ResourceTransferRequestFlow.MissingTransferRequestAuthInfoException;
import google.registry.flows.ResourceTransferRequestFlow.ObjectAlreadySponsoredException;
import google.registry.flows.SingleResourceFlow.ResourceStatusProhibitsOperationException;
import google.registry.flows.domain.DomainFlowUtils.BadPeriodUnitException;
import google.registry.flows.domain.DomainFlowUtils.CurrencyUnitMismatchException;
import google.registry.flows.domain.DomainFlowUtils.CurrencyValueScaleException;
@ -53,6 +48,11 @@ import google.registry.flows.domain.DomainFlowUtils.FeesRequiredForPremiumNameEx
import google.registry.flows.domain.DomainFlowUtils.NotAuthorizedForTldException;
import google.registry.flows.domain.DomainFlowUtils.PremiumNameBlockedException;
import google.registry.flows.domain.DomainFlowUtils.UnsupportedFeeAttributeException;
import google.registry.flows.exceptions.AlreadyPendingTransferException;
import google.registry.flows.exceptions.MissingTransferRequestAuthInfoException;
import google.registry.flows.exceptions.ObjectAlreadySponsoredException;
import google.registry.flows.exceptions.ResourceStatusProhibitsOperationException;
import google.registry.flows.exceptions.ResourceToMutateDoesNotExistException;
import google.registry.model.EppResource;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.Cancellation.Builder;
@ -224,8 +224,7 @@ public class DomainTransferRequestFlowTest
// Two poll messages on the gaining registrar's side at the expected expiration time: a
// (OneTime) transfer approved message, and an Autorenew poll message.
assertThat(getPollMessages("NewRegistrar", expectedExpirationTime))
.hasSize(2);
assertThat(getPollMessages("NewRegistrar", expectedExpirationTime)).hasSize(2);
PollMessage transferApprovedPollMessage = getOnlyPollMessage(
"NewRegistrar", implicitTransferTime, PollMessage.OneTime.class);
PollMessage autorenewPollMessage = getOnlyPollMessage(

View file

@ -0,0 +1,23 @@
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<response>
<result code="1000">
<msg>Command completed successfully</msg>
</result>
<resData>
<domain:trnData
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.tld</domain:name>
<domain:trStatus>pending</domain:trStatus>
<domain:reID>NewRegistrar</domain:reID>
<domain:reDate>2000-06-06T22:00:00.0Z</domain:reDate>
<domain:acID>TheRegistrar</domain:acID>
<domain:acDate>2000-06-11T22:00:00.0Z</domain:acDate>
<domain:exDate>2010-06-09T22:00:00.0Z</domain:exDate>
</domain:trnData>
</resData>
<trID>
<clTRID>ABC-12345</clTRID>
<svTRID>server-trid</svTRID>
</trID>
</response>
</epp>

View file

@ -3,7 +3,7 @@
<result code="1301">
<msg>Command completed successfully; ack to dequeue</msg>
</result>
<msgQ count="1" id="1-B-EXAMPLE-17-21">
<msgQ count="1" id="1-B-EXAMPLE-17-23">
<qDate>2001-01-01T00:00:00Z</qDate>
<msg>Transfer requested.</msg>
</msgQ>

View file

@ -3,7 +3,7 @@
<result code="1301">
<msg>Command completed successfully; ack to dequeue</msg>
</result>
<msgQ count="1" id="1-B-EXAMPLE-17-23">
<msgQ count="1" id="1-B-EXAMPLE-17-22">
<qDate>2001-01-06T00:00:00Z</qDate>
<msg>Transfer approved.</msg>
</msgQ>

View file

@ -4,7 +4,7 @@
<result code="1301">
<msg>Command completed successfully; ack to dequeue</msg>
</result>
<msgQ count="1" id="1-B-EXAMPLE-17-22">
<msgQ count="1" id="1-B-EXAMPLE-17-21">
<qDate>2001-01-06T00:00:00Z</qDate>
<msg>Transfer approved.</msg>
</msgQ>