// Copyright 2017 The Nomulus Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package google.registry.flows;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.model.eppoutput.Result.Code.SUCCESS;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_AND_CLOSE;
import static google.registry.model.eppoutput.Result.Code.SUCCESS_WITH_ACTION_PENDING;
import static google.registry.testing.DatastoreHelper.assertBillingEventsForResource;
import static google.registry.testing.DatastoreHelper.createTld;
import static google.registry.testing.DatastoreHelper.createTlds;
import static google.registry.testing.DatastoreHelper.getOnlyHistoryEntryOfType;
import static google.registry.testing.DatastoreHelper.persistResource;
import static google.registry.testing.EppMetricSubject.assertThat;
import static google.registry.util.DateTimeUtils.START_OF_TIME;
import static org.joda.money.CurrencyUnit.USD;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSortedMap;
import com.google.re2j.Matcher;
import com.google.re2j.Pattern;
import google.registry.model.billing.BillingEvent;
import google.registry.model.billing.BillingEvent.OneTime;
import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.domain.DomainResource;
import google.registry.model.registry.Registry;
import google.registry.model.registry.Registry.TldState;
import google.registry.model.reporting.HistoryEntry.Type;
import google.registry.testing.AppEngineRule;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** Tests for domain lifecycle. */
@RunWith(JUnit4.class)
public class EppLifecycleDomainTest extends EppTestCase {
@Rule
public final AppEngineRule appEngine =
AppEngineRule.builder().withDatastore().withTaskQueue().build();
@Before
public void initTld() {
createTlds("example", "tld");
}
@Test
public void testDomainDeleteRestore() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createContacts(DateTime.parse("2000-06-01T00:00:00Z"));
// Create domain example.tld
assertThatCommand(
"domain_create_no_hosts_or_dsdata.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime("2000-06-01T00:02:00Z")
.hasResponse(
"domain_create_response.xml",
ImmutableMap.of(
"DOMAIN", "example.tld",
"CRDATE", "2000-06-01T00:02:00.0Z",
"EXDATE", "2002-06-01T00:02:00.0Z"));
// Delete domain example.tld after its add grace period has expired.
assertThatCommand("domain_delete.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime("2000-07-01T00:02:00Z")
.hasResponse("generic_success_action_pending_response.xml");
// Restore the domain.
assertThatCommand("domain_update_restore_request.xml")
.atTime("2000-07-01T00:03:00Z")
.hasResponse("generic_success_response.xml");
assertThatLogoutSucceeds();
}
@Test
public void testDomainDeletion_withinAddGracePeriod_deletesImmediately() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createContacts(DateTime.parse("2000-06-01T00:00:00Z"));
// Create domain example.tld
DateTime createTime = DateTime.parse("2000-06-01T00:02:00Z");
assertThatCommand(
"domain_create_no_hosts_or_dsdata.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime(createTime)
.hasResponse(
"domain_create_response.xml",
ImmutableMap.of(
"DOMAIN", "example.tld",
"CRDATE", "2000-06-01T00:02:00.0Z",
"EXDATE", "2002-06-01T00:02:00.0Z"));
DomainResource domain =
loadByForeignKey(DomainResource.class, "example.tld", createTime.plusHours(1));
// Delete domain example.tld within the add grace period.
DateTime deleteTime = createTime.plusDays(1);
assertThatCommand("domain_delete.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime(deleteTime)
.hasResponse("generic_success_response.xml");
// Verify that it is immediately non-existent.
assertThatCommand("domain_info.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime(deleteTime.plusSeconds(1))
.hasResponse(
"response_error.xml",
ImmutableMap.of(
"CODE", "2303", "MSG", "The domain with given ID (example.tld) doesn't exist."));
// The expected one-time billing event, that should have an associated Cancellation.
OneTime oneTimeCreateBillingEvent = makeOneTimeCreateBillingEvent(domain, createTime);
// Verify that the OneTime billing event associated with the domain creation is canceled.
assertBillingEventsForResource(
domain,
// Check the existence of the expected create one-time billing event.
oneTimeCreateBillingEvent,
makeRecurringCreateBillingEvent(domain, createTime, deleteTime),
// Check for the existence of a cancellation for the given one-time billing event.
makeCancellationBillingEventFor(
domain, oneTimeCreateBillingEvent, createTime, deleteTime));
assertThatLogoutSucceeds();
}
@Test
public void testDomainDeletion_outsideAddGracePeriod_showsRedemptionPeriod() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createContacts(DateTime.parse("2000-06-01T00:00:00Z"));
DateTime createTime = DateTime.parse("2000-06-01T00:02:00Z");
// Create domain example.tld
assertThatCommand(
"domain_create_no_hosts_or_dsdata.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime(createTime)
.hasResponse(
"domain_create_response.xml",
ImmutableMap.of(
"DOMAIN", "example.tld",
"CRDATE", "2000-06-01T00:02:00.0Z",
"EXDATE", "2002-06-01T00:02:00.0Z"));
DateTime deleteTime = DateTime.parse("2000-07-07T00:02:00Z"); // 1 month and 6 days after
// Delete domain example.tld after its add grace period has expired.
assertThatCommand("domain_delete.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime(deleteTime)
.hasResponse("generic_success_action_pending_response.xml");
// Verify that domain shows redemptionPeriod soon after deletion.
assertThatCommand("domain_info.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime("2000-07-08T00:00:00Z")
.hasResponse(
"domain_info_response_wildcard.xml", ImmutableMap.of("STATUS", "redemptionPeriod"));
// Verify that the domain shows pendingDelete next.
assertThatCommand("domain_info.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime("2000-08-08T00:00:00Z")
.hasResponse(
"domain_info_response_wildcard.xml", ImmutableMap.of("STATUS", "pendingDelete"));
// Verify that the domain is non-existent (available for registration) later.
assertThatCommand("domain_info.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime("2000-09-01T00:00:00Z")
.hasResponse(
"response_error.xml",
ImmutableMap.of(
"CODE", "2303", "MSG", "The domain with given ID (example.tld) doesn't exist."));
DomainResource domain =
loadByForeignKey(
DomainResource.class, "example.tld", DateTime.parse("2000-08-01T00:02:00Z"));
// Verify that the autorenew was ended and that the one-time billing event is not canceled.
assertBillingEventsForResource(
domain,
makeOneTimeCreateBillingEvent(domain, createTime),
makeRecurringCreateBillingEvent(domain, createTime, deleteTime));
assertThatLogoutSucceeds();
}
@Test
public void testEapDomainDeletion_withinAddGracePeriod_eapFeeIsNotRefunded() throws Exception {
assertThatCommand("login_valid_fee_extension.xml").hasResponse("generic_success_response.xml");
createContacts(DateTime.parse("2000-06-01T00:00:00Z"));
// Set the EAP schedule.
persistResource(
Registry.get("tld")
.asBuilder()
.setEapFeeSchedule(
ImmutableSortedMap.of(
START_OF_TIME, Money.of(USD, 0),
DateTime.parse("2000-06-01T00:00:00Z"), Money.of(USD, 100),
DateTime.parse("2000-06-02T00:00:00Z"), Money.of(USD, 0)))
.build());
// Create domain example.tld, which should have an EAP fee of USD 100.
DateTime createTime = DateTime.parse("2000-06-01T00:02:00Z");
assertThatCommand("domain_create_eap_fee.xml")
.atTime(createTime)
.hasResponse("domain_create_response_eap_fee.xml");
DomainResource domain =
loadByForeignKey(
DomainResource.class, "example.tld", DateTime.parse("2000-06-01T00:03:00Z"));
// Delete domain example.tld within the add grade period.
DateTime deleteTime = createTime.plusDays(1);
assertThatCommand("domain_delete.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime(deleteTime)
.hasResponse("domain_delete_response_fee.xml");
// Verify that the OneTime billing event associated with the base fee of domain registration and
// is canceled and the autorenew is ended, but that the EAP fee is not canceled.
OneTime expectedCreateEapBillingEvent =
new BillingEvent.OneTime.Builder()
.setReason(Reason.FEE_EARLY_ACCESS)
.setTargetId("example.tld")
.setClientId("NewRegistrar")
.setPeriodYears(1)
.setCost(Money.parse("USD 100.00"))
.setEventTime(createTime)
.setBillingTime(createTime.plus(Registry.get("tld").getRenewGracePeriodLength()))
.setParent(getOnlyHistoryEntryOfType(domain, Type.DOMAIN_CREATE))
.build();
// The expected one-time billing event, that should have an associated Cancellation.
OneTime expectedOneTimeCreateBillingEvent = makeOneTimeCreateBillingEvent(domain, createTime);
assertBillingEventsForResource(
domain,
// Check for the expected create one-time billing event ...
expectedOneTimeCreateBillingEvent,
// ... and the expected one-time EAP fee billing event ...
expectedCreateEapBillingEvent,
makeRecurringCreateBillingEvent(domain, createTime, deleteTime),
// ... and verify that the create one-time billing event was canceled ...
makeCancellationBillingEventFor(
domain, expectedOneTimeCreateBillingEvent, createTime, deleteTime));
// ... but there was NOT a Cancellation for the EAP fee, as this would fail if additional
// billing events were present.
assertThatLogoutSucceeds();
}
@Test
public void testDomainDeletionWithSubordinateHost_fails() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createFakesite();
createSubordinateHost();
assertThatCommand("domain_delete.xml", ImmutableMap.of("DOMAIN", "fakesite.example"))
.atTime("2002-05-30T01:01:00Z")
.hasResponse(
"response_error.xml",
ImmutableMap.of("CODE", "2305", "MSG", "Domain to be deleted has subordinate hosts"));
assertThatLogoutSucceeds();
}
@Test
public void testDeletionOfDomain_afterRenameOfSubordinateHost_succeeds() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasNoTld()
.and()
.hasCommandName("Login")
.and()
.hasStatus(SUCCESS);
createFakesite();
createSubordinateHost();
// Update the ns3 host to no longer be on fakesite.example domain.
assertThatCommand("host_update_fakesite.xml")
.atTime("2002-05-30T01:01:00Z")
.hasResponse("generic_success_response.xml");
// Add assert about EppMetric
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("HostUpdate")
.and()
.hasStatus(SUCCESS);
// Delete the fakesite.example domain (which should succeed since it no longer has subords).
assertThatCommand("domain_delete.xml", ImmutableMap.of("DOMAIN", "fakesite.example"))
.atTime("2002-05-30T01:02:00Z")
.hasResponse("generic_success_action_pending_response.xml");
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasTld("example")
.and()
.hasCommandName("DomainDelete")
.and()
.hasStatus(SUCCESS_WITH_ACTION_PENDING);
// Check info on the renamed host and verify that it's still around and wasn't deleted.
assertThatCommand("host_info_ns9000_example.xml")
.atTime("2002-06-30T01:03:00Z")
.hasResponse("host_info_response_ns9000_example.xml");
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("HostInfo")
.and()
.hasStatus(SUCCESS);
assertThatLogoutSucceeds();
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("Logout")
.and()
.hasStatus(SUCCESS_AND_CLOSE);
}
@Test
public void testDeletionOfDomain_afterUpdateThatCreatesSubordinateHost_fails() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createFakesite();
// Create domain example.tld
assertThatCommand(
"domain_create_no_hosts_or_dsdata.xml", ImmutableMap.of("DOMAIN", "example.tld"))
.atTime("2000-06-02T00:00:00Z")
.hasResponse(
"domain_create_response.xml",
ImmutableMap.of(
"DOMAIN", "example.tld",
"CRDATE", "2000-06-02T00:00:00.0Z",
"EXDATE", "2002-06-02T00:00:00.0Z"));
// Create nameserver ns1.example.tld
assertThatCommand("host_create_example.xml")
.atTime("2000-06-02T00:01:00Z")
.hasResponse("host_create_response_example.xml");
// Update the ns1 host to be on the fakesite.example domain.
assertThatCommand("host_update_ns1_to_fakesite.xml")
.atTime("2002-05-30T01:01:00Z")
.hasResponse("generic_success_response.xml");
// Attempt to delete the fakesite.example domain (which should fail since it now has a
// subordinate host).
assertThatCommand("domain_delete.xml", ImmutableMap.of("DOMAIN", "fakesite.example"))
.atTime("2002-05-30T01:02:00Z")
.hasResponse(
"response_error.xml",
ImmutableMap.of("CODE", "2305", "MSG", "Domain to be deleted has subordinate hosts"));
// Check info on the renamed host and verify that it's still around and wasn't deleted.
assertThatCommand("host_info_fakesite.xml")
.atTime("2002-06-30T01:03:00Z")
.hasResponse("host_info_response_fakesite_post_update.xml");
// Verify that fakesite.example domain is still around and wasn't deleted.
assertThatCommand("domain_info_fakesite.xml")
.atTime("2002-05-30T01:00:00Z")
.hasResponse("domain_info_response_fakesite_ok_post_host_update.xml");
assertThatLogoutSucceeds();
}
@Test
public void testDomainCreation_failsBeforeSunrise() throws Exception {
DateTime sunriseDate = DateTime.parse("2000-05-30T00:00:00Z");
createTld(
"example",
ImmutableSortedMap.of(
START_OF_TIME,
TldState.PREDELEGATION,
sunriseDate,
TldState.SUNRISE,
sunriseDate.plusMonths(2),
TldState.GENERAL_AVAILABILITY));
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createContactsAndHosts();
assertThatCommand("domain_create_sunrise_encoded_mark.xml")
.atTime(sunriseDate.minusDays(1))
.hasResponse(
"response_error.xml",
ImmutableMap.of(
"CODE", "2002", "MSG", "Command is not allowed in the current registry phase"));
assertThatCommand("domain_info_testvalidate.xml")
.atTime(sunriseDate.plusDays(1))
.hasResponse(
"response_error.xml",
ImmutableMap.of(
"CODE", "2303",
"MSG", "The domain with given ID (test-validate.example) doesn't exist."));
assertThatLogoutSucceeds();
}
@Test
public void testDomainCheckFee_succeeds() throws Exception {
DateTime gaDate = DateTime.parse("2000-05-30T00:00:00Z");
createTld(
"example",
ImmutableSortedMap.of(
START_OF_TIME, TldState.PREDELEGATION,
gaDate, TldState.GENERAL_AVAILABILITY));
assertThatCommand("login_valid_fee_extension.xml").hasResponse("generic_success_response.xml");
assertThatCommand("domain_check_fee_premium.xml")
.atTime(gaDate.plusDays(1))
.hasResponse("domain_check_fee_premium_response.xml");
assertThat(getRecordedEppMetric())
.hasClientId("NewRegistrar")
.and()
.hasCommandName("DomainCheck")
.and()
.hasTld("example")
.and()
.hasStatus(SUCCESS);
assertThatLogoutSucceeds();
}
@Test
public void testDomainCreate_annualAutoRenewPollMessages_haveUniqueIds() throws Exception {
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
// Create the domain.
createFakesite();
// The first autorenew poll message isn't seen until after the initial two years of registration
// are up.
assertThatCommand("poll.xml")
.atTime("2001-01-01T00:01:00Z")
.hasResponse("poll_response_empty.xml");
assertThatCommand("poll.xml")
.atTime("2002-07-01T00:01:00Z")
.hasResponse(
"poll_response_autorenew.xml",
ImmutableMap.of(
"ID", "1-C-EXAMPLE-13-16-2002",
"QDATE", "2002-06-01T00:04:00Z",
"DOMAIN", "fakesite.example",
"EXDATE", "2003-06-01T00:04:00Z"));
assertThatCommand("poll_ack.xml", ImmutableMap.of("ID", "1-C-EXAMPLE-13-16-2002"))
.atTime("2002-07-01T00:02:00Z")
.hasResponse("poll_ack_response_empty.xml");
// The second autorenew poll message isn't seen until after another year, and it should have a
// different ID.
assertThatCommand("poll.xml")
.atTime("2002-07-01T00:05:00Z")
.hasResponse("poll_response_empty.xml");
assertThatCommand("poll.xml")
.atTime("2003-07-01T00:05:00Z")
.hasResponse(
"poll_response_autorenew.xml",
ImmutableMap.of(
"ID", "1-C-EXAMPLE-13-16-2003", // Note -- Year is different from previous ID.
"QDATE", "2003-06-01T00:04:00Z",
"DOMAIN", "fakesite.example",
"EXDATE", "2004-06-01T00:04:00Z"));
// Ack the second poll message and verify that none remain.
assertThatCommand("poll_ack.xml", ImmutableMap.of("ID", "1-C-EXAMPLE-13-16-2003"))
.atTime("2003-07-01T00:05:05Z")
.hasResponse("poll_ack_response_empty.xml");
assertThatCommand("poll.xml")
.atTime("2003-07-01T00:05:10Z")
.hasResponse("poll_response_empty.xml");
assertThatLogoutSucceeds();
}
@Test
public void testDomainTransferPollMessage_serverApproved() throws Exception {
// As the losing registrar, create the domain.
assertThatLoginSucceeds("NewRegistrar", "foo-BAR2");
createFakesite();
assertThatLogoutSucceeds();
// As the winning registrar, request a transfer. Capture the server trid; we'll need it later.
assertThatLoginSucceeds("TheRegistrar", "password2");
String response =
assertThatCommand("domain_transfer_request_1_year.xml")
.atTime("2001-01-01T00:00:00Z")
.hasResponse("domain_transfer_response_1_year.xml");
Matcher matcher = Pattern.compile("
TODO(b/76095570):have the same exact test on end-date sunrise - using the same .xml file - * that checks that an application was created. */ @Test public void testDomainCreation_startDateSunrise_noType() throws Exception { // The signed mark is valid between 2013 and 2017 DateTime sunriseDate = DateTime.parse("2014-09-08T09:09:09Z"); DateTime gaDate = sunriseDate.plusDays(30); createTld( "example", ImmutableSortedMap.of( START_OF_TIME, TldState.PREDELEGATION, sunriseDate, TldState.START_DATE_SUNRISE, gaDate, TldState.GENERAL_AVAILABILITY)); assertThatLogin("NewRegistrar", "foo-BAR2") .atTime(sunriseDate.minusDays(3)) .hasResponse("generic_success_response.xml"); createContactsAndHosts(); // During start-date sunrise, create with mark will succeed but without will fail. // We also test we can delete without a mark. assertThatCommand("domain_info.xml", ImmutableMap.of("DOMAIN", "test-validate.example")) .atTime(sunriseDate.plusDays(1)) .hasResponse( "response_error.xml", ImmutableMap.of( "CODE", "2303", "MSG", "The domain with given ID (test-validate.example) doesn't exist.")); assertThatCommand("domain_create_start_date_sunrise_encoded_mark_no_type.xml") .atTime(sunriseDate.plusDays(1).plusMinutes(1)) .hasResponse( "domain_create_response.xml", ImmutableMap.of( "DOMAIN", "test-validate.example", "CRDATE", "2014-09-09T09:10:09Z", "EXDATE", "2015-09-09T09:10:09Z")); assertThatCommand("domain_info.xml", ImmutableMap.of("DOMAIN", "test-validate.example")) .atTime(sunriseDate.plusDays(1).plusMinutes(2)) .hasResponse( "domain_info_response_ok_wildcard.xml", ImmutableMap.of( "DOMAIN", "test-validate.example", "CRDATE", "2014-09-09T09:10:09Z", "EXDATE", "2015-09-09T09:10:09Z")); assertThatLogoutSucceeds(); } }