mirror of
https://github.com/google/nomulus.git
synced 2025-07-20 17:56:08 +02:00
Handle pending transfers on domain imports from RDE deposits
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=148496597
This commit is contained in:
parent
3ca9bb6aeb
commit
9f90597691
14 changed files with 752 additions and 125 deletions
|
@ -18,11 +18,15 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.testing.DatastoreHelper.createTld;
|
||||
import static google.registry.testing.DatastoreHelper.getHistoryEntries;
|
||||
import static google.registry.testing.DatastoreHelper.getPollMessages;
|
||||
import static google.registry.testing.DatastoreHelper.newDomainResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistActiveContact;
|
||||
import static google.registry.testing.DatastoreHelper.persistResource;
|
||||
import static google.registry.testing.DatastoreHelper.persistSimpleResource;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.google.appengine.tools.cloudstorage.GcsFilename;
|
||||
import com.google.appengine.tools.cloudstorage.GcsService;
|
||||
|
@ -35,9 +39,13 @@ import com.googlecode.objectify.Key;
|
|||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.gcs.GcsUtils;
|
||||
import google.registry.mapreduce.MapreduceRunner;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.domain.DomainResource;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
import google.registry.model.eppcommon.Trid;
|
||||
import google.registry.model.poll.PollMessage;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.request.Response;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import google.registry.testing.mapreduce.MapreduceTestCase;
|
||||
|
@ -45,7 +53,10 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Seconds;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -56,6 +67,8 @@ import org.mockito.runners.MockitoJUnitRunner;
|
|||
public class RdeDomainImportActionTest extends MapreduceTestCase<RdeDomainImportAction> {
|
||||
|
||||
private static final ByteSource DEPOSIT_1_DOMAIN = RdeImportsTestData.get("deposit_1_domain.xml");
|
||||
private static final ByteSource DEPOSIT_1_DOMAIN_PENDING_TRANSFER =
|
||||
RdeImportsTestData.get("deposit_1_domain_pending_transfer.xml");
|
||||
private static final String IMPORT_BUCKET_NAME = "import-bucket";
|
||||
private static final String IMPORT_FILE_NAME = "escrow-file.xml";
|
||||
|
||||
|
@ -82,7 +95,7 @@ public class RdeDomainImportActionTest extends MapreduceTestCase<RdeDomainImport
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test_mapreduceSuccessfullyImportsDomain() throws Exception {
|
||||
public void testMapreduceSuccessfullyImportsDomain() throws Exception {
|
||||
pushToGcs(DEPOSIT_1_DOMAIN);
|
||||
runMapreduce();
|
||||
List<DomainResource> domains = ofy().load().type(DomainResource.class).list();
|
||||
|
@ -91,7 +104,7 @@ public class RdeDomainImportActionTest extends MapreduceTestCase<RdeDomainImport
|
|||
}
|
||||
|
||||
@Test
|
||||
public void test_mapreduceSuccessfullyCreatesHistoryEntry() throws Exception {
|
||||
public void testMapreduceSuccessfullyCreatesHistoryEntry() throws Exception {
|
||||
pushToGcs(DEPOSIT_1_DOMAIN);
|
||||
runMapreduce();
|
||||
List<DomainResource> domains = ofy().load().type(DomainResource.class).list();
|
||||
|
@ -104,7 +117,7 @@ public class RdeDomainImportActionTest extends MapreduceTestCase<RdeDomainImport
|
|||
|
||||
/** Ensures that a second pass on a domain does not import a new domain. */
|
||||
@Test
|
||||
public void test_mapreduceTwiceDoesNotDuplicateResources() throws Exception {
|
||||
public void testMapreduceTwiceDoesNotDuplicateResources() throws Exception {
|
||||
pushToGcs(DEPOSIT_1_DOMAIN);
|
||||
// Create domain and history entry first
|
||||
DomainResource existingDomain =
|
||||
|
@ -135,8 +148,147 @@ public class RdeDomainImportActionTest extends MapreduceTestCase<RdeDomainImport
|
|||
assertDnsTasksEnqueued("example1.test");
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the state of an imported pending transfer before and after implicit server approval
|
||||
*/
|
||||
@Test
|
||||
public void testMapreducePendingTransferServerApproval() throws Exception {
|
||||
pushToGcs(DEPOSIT_1_DOMAIN_PENDING_TRANSFER);
|
||||
runMapreduce();
|
||||
List<DomainResource> domains = ofy().load().type(DomainResource.class).list();
|
||||
assertThat(domains).hasSize(1);
|
||||
checkDomain(domains.get(0));
|
||||
// implicit server approval happens at 2015-01-08T22:00:00.0Z
|
||||
DateTime serverApprovalTime = DateTime.parse("2015-01-08T22:00:00.0Z");
|
||||
// Domain should be assigned to RegistrarX before server approval
|
||||
DomainResource beforeApproval =
|
||||
domains.get(0).cloneProjectedAtTime(serverApprovalTime.minus(Seconds.ONE));
|
||||
assertThat(beforeApproval.getCurrentSponsorClientId()).isEqualTo("RegistrarX");
|
||||
assertThat(loadAutorenewBillingEventForDomain(beforeApproval).getClientId())
|
||||
.isEqualTo("RegistrarX");
|
||||
assertThat(loadAutorenewPollMessageForDomain(beforeApproval).getClientId())
|
||||
.isEqualTo("RegistrarX");
|
||||
// Current expiration is 2015-04-03T22:00:00.0Z
|
||||
assertThat(beforeApproval.getRegistrationExpirationTime())
|
||||
.isEqualTo(DateTime.parse("2015-04-03T22:00:00.0Z"));
|
||||
// Domain is not yet in transfer grace period
|
||||
assertThat(beforeApproval.getGracePeriodStatuses()).doesNotContain(GracePeriodStatus.TRANSFER);
|
||||
// Check autorenew events - recurrence end is set to transfer approval time,
|
||||
// and client id is set to losing registrar. This is important in case the
|
||||
// transfer is cancelled or rejected.
|
||||
// Event time is set to domain expiration date.
|
||||
checkAutorenewBillingEvent(
|
||||
beforeApproval,
|
||||
"RegistrarX",
|
||||
DateTime.parse("2015-04-03T22:00:00.0Z"),
|
||||
DateTime.parse("2015-01-08T22:00:00.0Z"));
|
||||
checkAutorenewPollMessage(
|
||||
beforeApproval,
|
||||
"RegistrarX",
|
||||
DateTime.parse("2015-04-03T22:00:00.0Z"),
|
||||
DateTime.parse("2015-01-08T22:00:00.0Z"));
|
||||
|
||||
// Domain should be assigned to RegistrarY after server approval
|
||||
DomainResource afterApproval =
|
||||
domains.get(0).cloneProjectedAtTime(serverApprovalTime.plus(Seconds.ONE));
|
||||
assertThat(afterApproval.getCurrentSponsorClientId()).isEqualTo("RegistrarY");
|
||||
assertThat(loadAutorenewBillingEventForDomain(afterApproval).getClientId())
|
||||
.isEqualTo("RegistrarY");
|
||||
assertThat(loadAutorenewPollMessageForDomain(afterApproval).getClientId())
|
||||
.isEqualTo("RegistrarY");
|
||||
// New expiration should be incremented by 1 year
|
||||
assertThat(afterApproval.getRegistrationExpirationTime())
|
||||
.isEqualTo(DateTime.parse("2016-04-03T22:00:00.0Z"));
|
||||
// Domain should now be in transfer grace period
|
||||
assertThat(afterApproval.getGracePeriodStatuses()).contains(GracePeriodStatus.TRANSFER);
|
||||
// Check autorenew events - recurrence end is set to END_OF_TIME,
|
||||
// and client id is set to gaining registrar. This represents the new state of the domain,
|
||||
// unless the transfer is cancelled during the grace period, at which time it will
|
||||
// revert to the previous state.
|
||||
// Event time is set to domain expiration date.
|
||||
checkAutorenewBillingEvent(
|
||||
afterApproval, "RegistrarY", DateTime.parse("2016-04-03T22:00:00.0Z"), END_OF_TIME);
|
||||
checkAutorenewPollMessage(
|
||||
afterApproval, "RegistrarY", DateTime.parse("2016-04-03T22:00:00.0Z"), END_OF_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapreducePendingTransferEvents() throws Exception {
|
||||
pushToGcs(DEPOSIT_1_DOMAIN_PENDING_TRANSFER);
|
||||
runMapreduce();
|
||||
List<DomainResource> domains = ofy().load().type(DomainResource.class).list();
|
||||
assertThat(domains).hasSize(1);
|
||||
checkDomain(domains.get(0));
|
||||
checkTransferRequestPollMessage(domains.get(0), "RegistrarX",
|
||||
DateTime.parse("2015-01-03T22:00:00.0Z"));
|
||||
checkTransferServerApprovalPollMessage(domains.get(0), "RegistrarX",
|
||||
DateTime.parse("2015-01-08T22:00:00.0Z"));
|
||||
checkTransferServerApprovalPollMessage(domains.get(0), "RegistrarY",
|
||||
DateTime.parse("2015-01-08T22:00:00.0Z"));
|
||||
// Billing event is set to the end of the transfer grace period, 5 days after server approval
|
||||
checkTransferBillingEvent(domains.get(0), DateTime.parse("2015-01-13T22:00:00.0Z"));
|
||||
}
|
||||
|
||||
private static void checkTransferBillingEvent(
|
||||
DomainResource domain, DateTime automaticTransferTime) {
|
||||
for (BillingEvent.OneTime event :
|
||||
ofy().load().type(BillingEvent.OneTime.class).ancestor(domain).list()) {
|
||||
if (event.getReason() == BillingEvent.Reason.TRANSFER) {
|
||||
assertThat(event.getCost()).isEqualTo(Money.of(USD, 11));
|
||||
assertThat(event.getClientId()).isEqualTo("RegistrarY");
|
||||
assertThat(event.getBillingTime()).isEqualTo(automaticTransferTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Verifies the existence of a transfer request poll message */
|
||||
private static void checkTransferRequestPollMessage(
|
||||
DomainResource domain, String clientId, DateTime expectedAt) {
|
||||
for (PollMessage message : getPollMessages(domain)) {
|
||||
if (TransferStatus.PENDING.getMessage().equals(message.getMsg())
|
||||
&& clientId.equals(message.getClientId())
|
||||
&& expectedAt.equals(message.getEventTime())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Expected transfer request poll message");
|
||||
}
|
||||
|
||||
/** Verifies the existence of a transfer request poll message */
|
||||
private static void checkTransferServerApprovalPollMessage(
|
||||
DomainResource domain, String clientId, DateTime expectedAt) {
|
||||
for (PollMessage message : getPollMessages(domain)) {
|
||||
if (TransferStatus.SERVER_APPROVED.getMessage().equals(message.getMsg())
|
||||
&& clientId.equals(message.getClientId())
|
||||
&& expectedAt.equals(message.getEventTime())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
fail("Expected transfer request poll message");
|
||||
}
|
||||
|
||||
/** Verifies autorenew {@link PollMessage} is correct */
|
||||
private static void checkAutorenewPollMessage(
|
||||
DomainResource domain, String clientId, DateTime expectedAt, DateTime recurrenceEndTime) {
|
||||
PollMessage.Autorenew autorenewPollMessage = loadAutorenewPollMessageForDomain(domain);
|
||||
assertThat(autorenewPollMessage).isNotNull();
|
||||
assertThat(autorenewPollMessage.getClientId()).isEqualTo(clientId);
|
||||
assertThat(autorenewPollMessage.getEventTime()).isEqualTo(expectedAt);
|
||||
assertThat(autorenewPollMessage.getAutorenewEndTime()).isEqualTo(recurrenceEndTime);
|
||||
}
|
||||
|
||||
/** Verifies autorenew {@link BillingEvent} is correct */
|
||||
private static void checkAutorenewBillingEvent(
|
||||
DomainResource domain, String clientId, DateTime expectedAt, DateTime recurrenceEndTime) {
|
||||
BillingEvent.Recurring autorenewBillingEvent = loadAutorenewBillingEventForDomain(domain);
|
||||
assertThat(autorenewBillingEvent).isNotNull();
|
||||
assertThat(autorenewBillingEvent.getClientId()).isEqualTo(clientId);
|
||||
assertThat(autorenewBillingEvent.getEventTime()).isEqualTo(expectedAt);
|
||||
assertThat(autorenewBillingEvent.getRecurrenceEndTime()).isEqualTo(recurrenceEndTime);
|
||||
}
|
||||
|
||||
/** Verify history entry fields are correct */
|
||||
private void checkHistoryEntry(HistoryEntry entry, DomainResource parent) {
|
||||
private static void checkHistoryEntry(HistoryEntry entry, DomainResource parent) {
|
||||
assertThat(entry.getType()).isEqualTo(HistoryEntry.Type.RDE_IMPORT);
|
||||
assertThat(entry.getClientId()).isEqualTo(parent.getCurrentSponsorClientId());
|
||||
assertThat(entry.getXmlBytes().length).isGreaterThan(0);
|
||||
|
@ -146,8 +298,8 @@ public class RdeDomainImportActionTest extends MapreduceTestCase<RdeDomainImport
|
|||
assertThat(entry.getParent()).isEqualTo(Key.create(parent));
|
||||
}
|
||||
|
||||
/** Verifies that domain id and ROID match expected values */
|
||||
private void checkDomain(DomainResource domain) {
|
||||
/** Verifies that domain fields match expected values */
|
||||
private static void checkDomain(DomainResource domain) {
|
||||
assertThat(domain.getFullyQualifiedDomainName()).isEqualTo("example1.test");
|
||||
assertThat(domain.getRepoId()).isEqualTo("Dexample1-TEST");
|
||||
}
|
||||
|
@ -174,6 +326,16 @@ public class RdeDomainImportActionTest extends MapreduceTestCase<RdeDomainImport
|
|||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static BillingEvent.Recurring loadAutorenewBillingEventForDomain(DomainResource domain) {
|
||||
return ofy().load().key(domain.getAutorenewBillingEvent()).now();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static PollMessage.Autorenew loadAutorenewPollMessageForDomain(DomainResource domain) {
|
||||
return ofy().load().key(domain.getAutorenewPollMessage()).now();
|
||||
}
|
||||
|
||||
private static HistoryEntry createHistoryEntry(String roid, String clid, byte[] objectXml) {
|
||||
return new HistoryEntry.Builder()
|
||||
.setType(HistoryEntry.Type.RDE_IMPORT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue