Convert DomainTCF and DomainContent to tm() (#1046)

Note: this also includes conversions of the tests of any class that
called the converted DomainContent method to make sure that we caught
everything.
This commit is contained in:
gbrodman 2021-04-02 11:41:00 -04:00 committed by GitHub
parent 8952687207
commit 4e7dd7a95a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 442 additions and 395 deletions

View file

@ -22,6 +22,7 @@ import static google.registry.flows.domain.DomainFlowUtils.handleFeeRequest;
import static google.registry.flows.domain.DomainFlowUtils.loadForeignKeyedDesignatedContacts;
import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@ -100,9 +101,11 @@ public final class DomainInfoFlow implements Flow {
verifyOptionalAuthInfo(authInfo, domain);
flowCustomLogic.afterValidation(
AfterValidationParameters.newBuilder().setDomain(domain).build());
// Prefetch all referenced resources. Calling values() blocks until loading is done.
tm().loadByKeys(domain.getNameservers());
tm().loadByKeys(domain.getReferencedContacts());
// In ofy, refetch all referenced resources.
if (tm().isOfy()) {
tm().loadByKeys(domain.getNameservers());
tm().loadByKeys(domain.getReferencedContacts());
}
// Registrars can only see a few fields on unauthorized domains.
// This is a policy decision that is left up to us by the rfcs.
DomainInfoData.Builder infoBuilder =
@ -110,14 +113,16 @@ public final class DomainInfoFlow implements Flow {
.setFullyQualifiedDomainName(domain.getDomainName())
.setRepoId(domain.getRepoId())
.setCurrentSponsorClientId(domain.getCurrentSponsorClientId())
.setRegistrant(tm().loadByKey(domain.getRegistrant()).getContactId());
.setRegistrant(
transactIfJpaTm(() -> tm().loadByKey(domain.getRegistrant())).getContactId());
// If authInfo is non-null, then the caller is authorized to see the full information since we
// will have already verified the authInfo is valid.
if (clientId.equals(domain.getCurrentSponsorClientId()) || authInfo.isPresent()) {
HostsRequest hostsRequest = ((Info) resourceCommand).getHostsRequest();
infoBuilder
.setStatusValues(domain.getStatusValues())
.setContacts(loadForeignKeyedDesignatedContacts(domain.getContacts()))
.setContacts(
transactIfJpaTm(() -> loadForeignKeyedDesignatedContacts(domain.getContacts())))
.setNameservers(hostsRequest.requestDelegated() ? domain.loadNameserverHostNames() : null)
.setSubordinateHosts(
hostsRequest.requestSubordinate() ? domain.getSubordinateHosts() : null)

View file

@ -25,7 +25,6 @@ import static google.registry.flows.domain.DomainFlowUtils.updateAutorenewRecurr
import static google.registry.flows.domain.DomainTransferUtils.createLosingTransferPollMessage;
import static google.registry.flows.domain.DomainTransferUtils.createTransferResponse;
import static google.registry.model.ResourceTransferUtils.denyPendingTransfer;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.reporting.DomainTransactionRecord.TransactionReportField.TRANSFER_SUCCESSFUL;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.END_OF_TIME;
@ -39,7 +38,6 @@ import google.registry.flows.FlowModule.Superuser;
import google.registry.flows.FlowModule.TargetId;
import google.registry.flows.TransactionalFlow;
import google.registry.flows.annotations.ReportingSpec;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.metadata.MetadataExtension;
import google.registry.model.eppcommon.AuthInfo;
@ -100,11 +98,11 @@ public final class DomainTransferCancelFlow implements TransactionalFlow {
HistoryEntry historyEntry = buildHistoryEntry(existingDomain, registry, now);
DomainBase newDomain =
denyPendingTransfer(existingDomain, TransferStatus.CLIENT_CANCELLED, now, clientId);
ofy().save().<ImmutableObject>entities(
newDomain,
historyEntry,
createLosingTransferPollMessage(
targetId, newDomain.getTransferData(), null, historyEntry));
tm().putAll(
newDomain,
historyEntry,
createLosingTransferPollMessage(
targetId, newDomain.getTransferData(), null, historyEntry));
// Reopen the autorenew event and poll message that we closed for the implicit transfer. This
// may recreate the autorenew poll message if it was deleted when the transfer request was made.
updateAutorenewRecurrenceEndTime(existingDomain, END_OF_TIME);

View file

@ -23,8 +23,9 @@ import static com.google.common.collect.Sets.difference;
import static com.google.common.collect.Sets.intersection;
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
import static google.registry.model.EppResourceUtils.setAutomaticTransferSuccessProperties;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
import static google.registry.util.CollectionUtils.forceEmptyToNull;
import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy;
@ -670,13 +671,11 @@ public class DomainContent extends EppResource
/** Loads and returns the fully qualified host names of all linked nameservers. */
public ImmutableSortedSet<String> loadNameserverHostNames() {
return ofy()
.load()
.keys(getNameservers().stream().map(VKey::getOfyKey).collect(toImmutableSet()))
.values()
.stream()
.map(HostResource::getHostName)
.collect(toImmutableSortedSet(Ordering.natural()));
return transactIfJpaTm(
() ->
tm().loadByKeys(getNameservers()).values().stream()
.map(HostResource::getHostName)
.collect(toImmutableSortedSet(Ordering.natural())));
}
/** A key to the registrant who registered this domain. */

View file

@ -16,6 +16,7 @@ package google.registry.rde;
import static com.google.common.base.Preconditions.checkState;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
import com.google.common.base.Ascii;
import com.google.common.base.Strings;
@ -172,7 +173,7 @@ final class DomainBaseToXjcConverter {
if (registrant == null) {
logger.atWarning().log("Domain %s has no registrant contact.", domainName);
} else {
ContactResource registrantContact = tm().loadByKey(registrant);
ContactResource registrantContact = transactIfJpaTm(() -> tm().loadByKey(registrant));
checkState(
registrantContact != null,
"Registrant contact %s on domain %s does not exist",
@ -305,7 +306,7 @@ final class DomainBaseToXjcConverter {
"Contact key for type %s is null on domain %s",
model.getType(),
domainName);
ContactResource contact = tm().loadByKey(model.getContactKey());
ContactResource contact = transactIfJpaTm(() -> tm().loadByKey(model.getContactKey()));
checkState(
contact != null,
"Contact %s on domain %s does not exist",

View file

@ -18,6 +18,9 @@ import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.io.BaseEncoding.base16;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.assertTldExists;
import static google.registry.persistence.transaction.TransactionManagerFactory.jpaTm;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
import static google.registry.util.DateTimeUtils.isBeforeOrAt;
import static java.nio.charset.StandardCharsets.US_ASCII;
@ -71,7 +74,15 @@ final class GenerateDnsReportCommand implements CommandWithRemoteApi {
String generate() {
result.append("[\n");
Iterable<DomainBase> domains = ofy().load().type(DomainBase.class).filter("tld", tld);
Iterable<DomainBase> domains =
tm().isOfy()
? ofy().load().type(DomainBase.class).filter("tld", tld)
: tm().transact(
() ->
jpaTm()
.query("FROM Domain WHERE tld = :tld", DomainBase.class)
.setParameter("tld", tld)
.getResultList());
for (DomainBase domain : domains) {
// Skip deleted domains and domains that don't get published to DNS.
if (isBeforeOrAt(domain.getDeletionTime(), now) || !domain.shouldPublishToDns()) {
@ -80,7 +91,8 @@ final class GenerateDnsReportCommand implements CommandWithRemoteApi {
write(domain);
}
Iterable<HostResource> nameservers = ofy().load().type(HostResource.class);
Iterable<HostResource> nameservers =
transactIfJpaTm(() -> tm().loadAllOf(HostResource.class));
for (HostResource nameserver : nameservers) {
// Skip deleted hosts and external hosts.
if (isBeforeOrAt(nameserver.getDeletionTime(), now)

View file

@ -21,6 +21,7 @@ import static google.registry.model.domain.rgp.GracePeriodStatus.AUTO_RENEW;
import static google.registry.model.eppcommon.StatusValue.PENDING_DELETE;
import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
import static google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static java.util.function.Predicate.isEqual;
@ -68,10 +69,10 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
validateWith = NameserversParameter.class)
private Set<String> addNameservers = new HashSet<>();
// TODO(b/184067241): enforce only one of each type of contact
@Parameter(
names = "--add_admins",
description = "Admins to add. Cannot be set if --admins is set."
)
names = "--add_admins",
description = "Admins to add. Cannot be set if --admins is set.")
private List<String> addAdmins = new ArrayList<>();
@Parameter(names = "--add_techs", description = "Techs to add. Cannot be set if --techs is set.")
@ -339,9 +340,11 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
ImmutableSet<String> getContactsOfType(
DomainBase domainBase, final DesignatedContact.Type contactType) {
return domainBase.getContacts().stream()
.filter(contact -> contact.getType().equals(contactType))
.map(contact -> tm().loadByKey(contact.getContactKey()).getContactId())
.collect(toImmutableSet());
return transactIfJpaTm(
() ->
domainBase.getContacts().stream()
.filter(contact -> contact.getType().equals(contactType))
.map(contact -> tm().loadByKey(contact.getContactKey()).getContactId())
.collect(toImmutableSet()));
}
}

View file

@ -45,6 +45,8 @@ import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.persistence.VKey;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.TestOfyAndSql;
import google.registry.util.Retrier;
import google.registry.util.SystemClock;
import google.registry.util.SystemSleeper;
@ -54,7 +56,6 @@ import java.net.Inet6Address;
import java.net.InetAddress;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor;
@ -67,6 +68,7 @@ import org.mockito.quality.Strictness;
/** Test case for {@link CloudDnsWriter}. */
@ExtendWith(MockitoExtension.class)
@DualDatabaseTest
public class CloudDnsWriterTest {
@RegisterExtension
@ -312,7 +314,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testLoadDomain_nonExistentDomain() {
writer.publishDomain("example.tld");
@ -320,7 +322,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testLoadDomain_noDsDataOrNameservers() {
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
writer.publishDomain("example.tld");
@ -328,7 +330,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 0, 0, 0));
}
@Test
@TestOfyAndSql
void testLoadDomain_deleteOldData() {
stubZone = fakeDomainRecords("example.tld", 2, 2, 2, 2);
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
@ -337,7 +339,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 0, 0, 0));
}
@Test
@TestOfyAndSql
void testLoadDomain_withExternalNs() {
persistResource(
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 0));
@ -346,7 +348,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 0, 1, 0));
}
@Test
@TestOfyAndSql
void testLoadDomain_withDsData() {
persistResource(
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 1));
@ -355,7 +357,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 0, 1, 1));
}
@Test
@TestOfyAndSql
void testLoadDomain_withInBailiwickNs_IPv4() {
persistResource(
fakeDomain(
@ -370,7 +372,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0));
}
@Test
@TestOfyAndSql
void testLoadDomain_withInBailiwickNs_IPv6() {
persistResource(
fakeDomain(
@ -385,7 +387,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 1, 0, 0));
}
@Test
@TestOfyAndSql
void testLoadDomain_withNameserveThatEndsWithDomainName() {
persistResource(
fakeDomain(
@ -398,7 +400,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testLoadHost_externalHost() {
writer.publishHost("ns1.example.com");
@ -406,7 +408,7 @@ public class CloudDnsWriterTest {
verifyZone(ImmutableSet.of());
}
@Test
@TestOfyAndSql
void testLoadHost_removeStaleNsRecords() {
// Initialize the zone with both NS records
stubZone = fakeDomainRecords("example.tld", 2, 0, 0, 0);
@ -429,7 +431,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void retryMutateZoneOnError() {
CloudDnsWriter spyWriter = spy(writer);
// First call - throw. Second call - do nothing.
@ -443,7 +445,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testLoadDomain_withClientHold() {
persistResource(
fakeDomain(
@ -459,7 +461,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testLoadDomain_withServerHold() {
persistResource(
fakeDomain(
@ -476,7 +478,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testLoadDomain_withPendingDelete() {
persistResource(
fakeDomain(
@ -491,7 +493,7 @@ public class CloudDnsWriterTest {
verifyZone(ImmutableSet.of());
}
@Test
@TestOfyAndSql
void testDuplicateRecords() {
// In publishing DNS records, we can end up publishing information on the same host twice
// (through a domain change and a host change), so this scenario needs to work.
@ -509,7 +511,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0));
}
@Test
@TestOfyAndSql
void testInvalidZoneNames() {
createTld("triple.secret.tld");
persistResource(
@ -525,7 +527,7 @@ public class CloudDnsWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testEmptyCommit() {
writer.commit();
verify(dnsConnection, times(0)).changes();

View file

@ -42,14 +42,15 @@ import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.model.ofy.Ofy;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeClock;
import google.registry.testing.InjectExtension;
import google.registry.testing.TestOfyAndSql;
import java.util.ArrayList;
import java.util.Collections;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor;
@ -70,6 +71,7 @@ import org.xbill.DNS.Update;
/** Unit tests for {@link DnsUpdateWriter}. */
@ExtendWith(MockitoExtension.class)
@DualDatabaseTest
public class DnsUpdateWriterTest {
@RegisterExtension
@ -96,7 +98,7 @@ public class DnsUpdateWriterTest {
"tld", Duration.ZERO, Duration.ZERO, Duration.ZERO, mockResolver, clock);
}
@Test
@TestOfyAndSql
void testPublishDomainCreate_publishesNameServers() throws Exception {
HostResource host1 = persistActiveHost("ns1.example.tld");
HostResource host2 = persistActiveHost("ns2.example.tld");
@ -119,7 +121,7 @@ public class DnsUpdateWriterTest {
}
@MockitoSettings(strictness = Strictness.LENIENT)
@Test
@TestOfyAndSql
void testPublishAtomic_noCommit() {
HostResource host1 = persistActiveHost("ns.example1.tld");
DomainBase domain1 =
@ -143,7 +145,7 @@ public class DnsUpdateWriterTest {
verifyNoInteractions(mockResolver);
}
@Test
@TestOfyAndSql
void testPublishAtomic_oneUpdate() throws Exception {
HostResource host1 = persistActiveHost("ns.example1.tld");
DomainBase domain1 =
@ -175,7 +177,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 4); // The delete and NS sets for each TLD
}
@Test
@TestOfyAndSql
void testPublishDomainCreate_publishesDelegationSigner() throws Exception {
DomainBase domain =
persistActiveDomain("example.tld")
@ -199,7 +201,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 3); // The delete, the NS, and DS sets
}
@Test
@TestOfyAndSql
void testPublishDomainWhenNotActive_removesDnsRecords() throws Exception {
DomainBase domain =
persistActiveDomain("example.tld")
@ -219,7 +221,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 1); // Just the delete set
}
@Test
@TestOfyAndSql
void testPublishDomainDelete_removesDnsRecords() throws Exception {
persistDeletedDomain("example.tld", clock.nowUtc().minusDays(1));
@ -233,7 +235,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 1); // Just the delete set
}
@Test
@TestOfyAndSql
void testPublishHostCreate_publishesAddressRecords() throws Exception {
HostResource host =
persistResource(
@ -266,7 +268,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 5);
}
@Test
@TestOfyAndSql
void testPublishHostDelete_removesDnsRecords() throws Exception {
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
persistActiveDomain("example.tld");
@ -282,7 +284,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 2); // Just the delete set
}
@Test
@TestOfyAndSql
void testPublishHostDelete_removesGlueRecords() throws Exception {
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
persistResource(
@ -303,7 +305,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 3);
}
@Test
@TestOfyAndSql
void testPublishDomainExternalAndInBailiwickNameServer() throws Exception {
HostResource externalNameserver = persistResource(newHostResource("ns1.example.com"));
HostResource inBailiwickNameserver =
@ -340,7 +342,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 5);
}
@Test
@TestOfyAndSql
void testPublishDomainDeleteOrphanGlues() throws Exception {
HostResource inBailiwickNameserver =
persistResource(
@ -378,7 +380,7 @@ public class DnsUpdateWriterTest {
@MockitoSettings(strictness = Strictness.LENIENT)
@SuppressWarnings("AssertThrowsMultipleStatements")
@Test
@TestOfyAndSql
void testPublishDomainFails_whenDnsUpdateReturnsError() throws Exception {
DomainBase domain =
persistActiveDomain("example.tld")
@ -399,7 +401,7 @@ public class DnsUpdateWriterTest {
@MockitoSettings(strictness = Strictness.LENIENT)
@SuppressWarnings("AssertThrowsMultipleStatements")
@Test
@TestOfyAndSql
void testPublishHostFails_whenDnsUpdateReturnsError() throws Exception {
HostResource host =
persistActiveSubordinateHost("ns1.example.tld", persistActiveDomain("example.tld"))

View file

@ -16,8 +16,8 @@ package google.registry.flows.domain;
import static com.google.common.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registry.TldState.QUIET_PERIOD;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.testing.DatabaseHelper.assertNoBillingEvents;
import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.newDomainBase;
@ -65,15 +65,18 @@ import google.registry.model.registry.Registry;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.ReplayExtension;
import google.registry.testing.SetClockExtension;
import google.registry.testing.TestOfyAndSql;
import google.registry.testing.TestOfyOnly;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DomainInfoFlow}. */
@DualDatabaseTest
class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase> {
@Order(value = Order.DEFAULT - 3)
@ -201,87 +204,87 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest(expectedXmlFilename, true);
}
@Test
@TestOfyAndSql
void testSuccess_allHosts() throws Exception {
doSuccessfulTest("domain_info_response.xml");
}
@Test
@TestOfyAndSql
void testSuccess_clTridNotSpecified() throws Exception {
setEppInput("domain_info_no_cltrid.xml");
doSuccessfulTest("domain_info_response_no_cltrid.xml");
}
@Test
@TestOfyAndSql
void testSuccess_allHosts_noDelegatedHosts() throws Exception {
// There aren't any delegated hosts.
doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_defaultHosts() throws Exception {
setEppInput("domain_info_default_hosts.xml");
doSuccessfulTest("domain_info_response.xml");
}
@Test
@TestOfyAndSql
void testSuccess_defaultHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_default_hosts.xml");
// There aren't any delegated hosts.
doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_delegatedHosts() throws Exception {
setEppInput("domain_info_delegated_hosts.xml");
doSuccessfulTest("domain_info_response_delegated_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_delegatedHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_delegated_hosts.xml");
// There aren't any delegated hosts.
doSuccessfulTestNoNameservers("domain_info_response_none_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_subordinateHosts() throws Exception {
setEppInput("domain_info_subordinate_hosts.xml");
doSuccessfulTest("domain_info_response_subordinate_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_subordinateHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_subordinate_hosts.xml");
doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_noneHosts() throws Exception {
setEppInput("domain_info_none_hosts.xml");
doSuccessfulTest("domain_info_response_none_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_noneHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_none_hosts.xml");
doSuccessfulTestNoNameservers("domain_info_response_none_hosts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_unauthorized() throws Exception {
sessionMetadata.setClientId("ClientZ");
doSuccessfulTest("domain_info_response_unauthorized.xml");
}
@Test
@TestOfyAndSql
void testSuccess_differentRegistrarWithAuthInfo() throws Exception {
setEppInput("domain_info_with_auth.xml");
sessionMetadata.setClientId("ClientZ");
doSuccessfulTest("domain_info_response.xml");
}
@Test
@TestOfyAndSql
void testSuccess_differentRegistrarWithRegistrantAuthInfo() throws Exception {
persistTestEntities(false);
setEppInput("domain_info_with_contact_auth.xml");
@ -290,7 +293,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_differentRegistrarWithContactAuthInfo() throws Exception {
persistTestEntities(false);
setEppInput("domain_info_with_contact_auth.xml");
@ -299,7 +302,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_inQuietPeriod() throws Exception {
persistResource(
Registry.get("tld")
@ -309,7 +312,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response.xml");
}
@Test
@TestOfyAndSql
void testSuccess_secDns() throws Exception {
persistTestEntities(false);
// Add the dsData to the saved resource and change the nameservers to match the sample xml.
@ -349,12 +352,12 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_addperiod.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_addGracePeriod() throws Exception {
doAddPeriodTest(GracePeriodStatus.ADD);
}
@Test
@TestOfyAndSql
void testSuccess_autoRenewGracePeriod() throws Exception {
persistTestEntities(false);
HistoryEntry historyEntry =
@ -391,7 +394,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_autorenewperiod.xml", false, ImmutableMap.of(), true);
}
@Test
@TestOfyAndSql
void testSuccess_redemptionGracePeriod() throws Exception {
persistTestEntities(false);
// Add an REDEMPTION grace period to the saved resource, and change a few other fields to match
@ -411,7 +414,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_redemptionperiod.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_renewGracePeriod() throws Exception {
persistTestEntities(false);
// Add an RENEW grace period to the saved resource.
@ -429,7 +432,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_renewperiod.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_multipleRenewGracePeriods() throws Exception {
persistTestEntities(false);
// Add multiple RENEW grace periods to the saved resource.
@ -454,7 +457,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_renewperiod.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_transferGracePeriod() throws Exception {
persistTestEntities(false);
// Add an TRANSFER grace period to the saved resource.
@ -472,7 +475,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_transferperiod.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_pendingDelete() throws Exception {
persistTestEntities(false);
// Set the domain to be pending delete with no grace period, which will cause an RGP status of
@ -482,7 +485,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_pendingdelete.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_stackedAddRenewGracePeriods() throws Exception {
persistTestEntities(false);
// Add both an ADD and RENEW grace period, both which should show up in the RGP status.
@ -507,7 +510,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_stackedaddrenewperiod.xml", false);
}
@Test
@TestOfyAndSql
void testSuccess_secDnsAndAddGracePeriod() throws Exception {
persistTestEntities(false);
// Add both an ADD grace period and SecDNS data.
@ -529,14 +532,14 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_dsdata_addperiod.xml", false);
}
@Test
@TestOfyAndSql
void testFailure_neverExisted() throws Exception {
ResourceDoesNotExistException thrown =
assertThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@TestOfyAndSql
void testFailure_existedButWasDeleted() throws Exception {
persistResource(
newDomainBase("example.tld")
@ -548,7 +551,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@TestOfyAndSql
void testFailure_differentRegistrarWrongAuthInfo() {
persistTestEntities(false);
// Change the password of the domain so that it does not match the file.
@ -563,7 +566,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_wrongAuthInfo() {
persistTestEntities(false);
// Change the password of the domain so that it does not match the file.
@ -577,7 +580,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_differentRegistrarWrongRegistrantAuthInfo() {
persistTestEntities(false);
// Change the password of the registrant so that it does not match the file.
@ -595,7 +598,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_wrongRegistrantAuthInfo() {
persistTestEntities(false);
// Change the password of the registrant so that it does not match the file.
@ -612,7 +615,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_differentRegistrarWrongContactAuthInfo() {
persistTestEntities(false);
// Change the password of the contact so that it does not match the file.
@ -630,7 +633,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_wrongContactAuthInfo() {
persistTestEntities(false);
// Change the password of the contact so that it does not match the file.
@ -647,7 +650,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_differentRegistrarUnrelatedContactAuthInfo() {
persistTestEntities(false);
ContactResource unrelatedContact = persistActiveContact("foo1234");
@ -659,7 +662,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_unrelatedContactAuthInfo() {
persistTestEntities(false);
ContactResource unrelatedContact = persistActiveContact("foo1234");
@ -674,7 +677,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
* Test create command. Fee extension version 6 is the only one which supports fee extensions on
* info commands and responses, so we don't need to test the other versions.
*/
@Test
@TestOfyAndSql
void testFeeExtension_createCommand() throws Exception {
setEppInput(
"domain_info_fee.xml",
@ -694,7 +697,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test renew command. */
@Test
@TestOfyAndSql
void testFeeExtension_renewCommand() throws Exception {
setEppInput(
"domain_info_fee.xml",
@ -714,7 +717,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test transfer command. */
@Test
@TestOfyAndSql
void testFeeExtension_transferCommand() throws Exception {
setEppInput(
"domain_info_fee.xml",
@ -734,7 +737,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test restore command. */
@Test
@TestOfyAndSql
void testFeeExtension_restoreCommand() throws Exception {
setEppInput(
"domain_info_fee.xml",
@ -746,7 +749,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_fee_restore_response.xml", false);
}
@Test
@TestOfyAndSql
void testFeeExtension_restoreCommand_pendingDelete_noRenewal() throws Exception {
setEppInput(
"domain_info_fee.xml",
@ -761,7 +764,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_fee_restore_response_no_renewal.xml", false);
}
@Test
@TestOfyAndSql
void testFeeExtension_restoreCommand_pendingDelete_withRenewal() throws Exception {
createTld("example");
setEppInput(
@ -780,7 +783,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test create command on a premium label. */
@Test
@TestOfyAndSql
void testFeeExtension_createCommandPremium() throws Exception {
createTld("example");
setEppInput(
@ -798,7 +801,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test renew command on a premium label. */
@Test
@TestOfyAndSql
void testFeeExtension_renewCommandPremium() throws Exception {
createTld("example");
setEppInput(
@ -816,7 +819,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test transfer command on a premium label. */
@Test
@TestOfyAndSql
void testFeeExtension_transferCommandPremium() throws Exception {
createTld("example");
setEppInput(
@ -834,7 +837,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test restore command on a premium label. */
@Test
@TestOfyAndSql
void testFeeExtension_restoreCommandPremium() throws Exception {
createTld("example");
setEppInput(
@ -849,7 +852,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test setting the currency explicitly to a wrong value. */
@Test
@TestOfyAndSql
void testFeeExtension_wrongCurrency() {
setEppInput(
"domain_info_fee.xml",
@ -863,7 +866,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFeeExtension_unknownCurrency() {
setEppInput(
"domain_info_fee.xml",
@ -877,7 +880,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test requesting a period that isn't in years. */
@Test
@TestOfyAndSql
void testFeeExtension_periodNotInYears() {
setEppInput(
"domain_info_fee.xml",
@ -892,7 +895,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test a command that specifies a phase. */
@Test
@TestOfyAndSql
void testFeeExtension_commandPhase() {
setEppInput("domain_info_fee_command_phase.xml");
persistTestEntities(false);
@ -901,7 +904,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test a command that specifies a subphase. */
@Test
@TestOfyAndSql
void testFeeExtension_commandSubphase() {
setEppInput("domain_info_fee_command_subphase.xml");
persistTestEntities(false);
@ -910,7 +913,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test a restore for more than one year. */
@Test
@TestOfyAndSql
void testFeeExtension_multiyearRestore() {
setEppInput(
"domain_info_fee.xml",
@ -924,7 +927,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test a transfer for more than one year. */
@Test
@TestOfyAndSql
void testFeeExtension_multiyearTransfer() {
setEppInput(
"domain_info_fee.xml",
@ -938,11 +941,11 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
}
/** Test that we load contacts and hosts as a batch rather than individually. */
@Test
@TestOfyOnly // batching only relevant for Datastore
void testBatchLoadingOfReferences() throws Exception {
persistTestEntities(false);
// Clear out the session cache so that we count actual Datastore calls.
ofy().clearSessionCache();
tm().clearSessionCache();
int numPreviousReads = RequestCapturingAsyncDatastoreService.getReads().size();
doSuccessfulTest("domain_info_response.xml", false);
// Get all of the keys loaded in the flow, with each distinct load() call as a list of keys.
@ -966,7 +969,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertThat(numReadsWithContactsOrHosts).isEqualTo(2);
}
@Test
@TestOfyAndSql
void testIcannActivityReportField_getsLogged() throws Exception {
persistTestEntities(false);
runFlow();

View file

@ -45,24 +45,27 @@ import google.registry.flows.exceptions.NotTransferInitiatorException;
import google.registry.model.contact.ContactAuthInfo;
import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.poll.PollMessage;
import google.registry.model.registry.Registry;
import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.TransferData;
import google.registry.model.transfer.DomainTransferData;
import google.registry.model.transfer.TransferResponse.DomainTransferResponse;
import google.registry.model.transfer.TransferStatus;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.ReplayExtension;
import google.registry.testing.TestOfyAndSql;
import org.joda.time.DateTime;
import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DomainTransferCancelFlow}. */
@DualDatabaseTest
class DomainTransferCancelFlowTest
extends DomainTransferFlowTestCase<DomainTransferCancelFlow, DomainBase> {
@ -77,8 +80,7 @@ class DomainTransferCancelFlowTest
setupDomainWithPendingTransfer("example", "tld");
}
private void doSuccessfulTest(String commandFilename, String expectedXmlFilename)
throws Exception {
private void doSuccessfulTest(String commandFilename) throws Exception {
setEppInput(commandFilename);
// Replace the ROID in the xml file with the one generated in our test.
@ -125,8 +127,8 @@ class DomainTransferCancelFlowTest
assertTransactionalFlow(true);
DateTime originalExpirationTime = domain.getRegistrationExpirationTime();
ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods();
TransferData originalTransferData = domain.getTransferData();
runFlowAssertResponse(loadFile(expectedXmlFilename));
DomainTransferData originalTransferData = domain.getTransferData();
runFlowAssertResponse(loadFile("domain_transfer_cancel_response.xml"));
// Transfer should have been cancelled. Verify correct fields were set.
domain = reloadResourceByForeignKey();
@ -199,31 +201,29 @@ class DomainTransferCancelFlowTest
runFlow();
}
@Test
@TestOfyAndSql
void testDryRun() throws Exception {
setEppInput("domain_transfer_cancel.xml");
eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
dryRunFlowAssertResponse(loadFile("domain_transfer_cancel_response.xml"));
}
@Test
@TestOfyAndSql
void testSuccess() throws Exception {
doSuccessfulTest("domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml");
doSuccessfulTest("domain_transfer_cancel.xml");
}
@Test
@TestOfyAndSql
void testSuccess_domainAuthInfo() throws Exception {
doSuccessfulTest(
"domain_transfer_cancel_domain_authinfo.xml", "domain_transfer_cancel_response.xml");
doSuccessfulTest("domain_transfer_cancel_domain_authinfo.xml");
}
@Test
@TestOfyAndSql
void testSuccess_contactAuthInfo() throws Exception {
doSuccessfulTest(
"domain_transfer_cancel_contact_authinfo.xml", "domain_transfer_cancel_response.xml");
doSuccessfulTest("domain_transfer_cancel_contact_authinfo.xml");
}
@Test
@TestOfyAndSql
void testFailure_badContactPassword() {
// Change the contact's password so it does not match the password in the file.
contact =
@ -239,7 +239,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_badDomainPassword() {
// Change the domain's password so it does not match the password in the file.
domain =
@ -255,7 +255,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_neverBeenTransferred() {
changeTransferStatus(null);
EppException thrown =
@ -264,7 +264,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_clientApproved() {
changeTransferStatus(TransferStatus.CLIENT_APPROVED);
EppException thrown =
@ -273,7 +273,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_clientRejected() {
changeTransferStatus(TransferStatus.CLIENT_REJECTED);
EppException thrown =
@ -282,7 +282,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_clientCancelled() {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
EppException thrown =
@ -291,7 +291,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_serverApproved() {
changeTransferStatus(TransferStatus.SERVER_APPROVED);
EppException thrown =
@ -300,7 +300,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_serverCancelled() {
changeTransferStatus(TransferStatus.SERVER_CANCELLED);
EppException thrown =
@ -309,7 +309,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_sponsoringClient() {
setClientIdForFlow("TheRegistrar");
EppException thrown =
@ -318,7 +318,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_unrelatedClient() {
setClientIdForFlow("ClientZ");
EppException thrown =
@ -327,7 +327,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testFailure_deletedDomain() throws Exception {
domain =
persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
@ -337,7 +337,7 @@ class DomainTransferCancelFlowTest
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@TestOfyAndSql
void testFailure_nonexistentDomain() throws Exception {
deleteTestDomain(domain, clock.nowUtc());
ResourceDoesNotExistException thrown =
@ -346,20 +346,18 @@ class DomainTransferCancelFlowTest
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
}
@Test
@TestOfyAndSql
void testFailure_notAuthorizedForTld() {
persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
EppException thrown =
assertThrows(
NotAuthorizedForTldException.class,
() ->
doSuccessfulTest(
"domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"));
() -> doSuccessfulTest("domain_transfer_cancel.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml();
}
@Test
@TestOfyAndSql
void testSuccess_superuserNotAuthorizedForTld() throws Exception {
persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
@ -371,7 +369,7 @@ class DomainTransferCancelFlowTest
// NB: No need to test pending delete status since pending transfers will get cancelled upon
// entering pending delete phase. So it's already handled in that test case.
@Test
@TestOfyAndSql
void testIcannActivityReportField_getsLogged() throws Exception {
clock.advanceOneMilli();
runFlow();
@ -379,7 +377,7 @@ class DomainTransferCancelFlowTest
assertTldsFieldLogged("tld");
}
@Test
@TestOfyAndSql
void testIcannTransactionRecord_noRecordsToCancel() throws Exception {
clock.advanceOneMilli();
runFlow();
@ -388,7 +386,7 @@ class DomainTransferCancelFlowTest
assertThat(persistedEntry.getDomainTransactionRecords()).isEmpty();
}
@Test
@TestOfyAndSql
void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception {
clock.advanceOneMilli();
persistResource(
@ -403,7 +401,7 @@ class DomainTransferCancelFlowTest
DomainTransactionRecord notCancellableRecord =
DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), RESTORED_DOMAINS, 5);
persistResource(
new HistoryEntry.Builder()
new DomainHistory.Builder()
.setType(DOMAIN_TRANSFER_REQUEST)
.setParent(domain)
.setModificationTime(clock.nowUtc().minusDays(4))

View file

@ -41,6 +41,7 @@ import google.registry.model.contact.PostalInfo;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData;
@ -55,7 +56,9 @@ import google.registry.model.reporting.HistoryEntry;
import google.registry.model.transfer.DomainTransferData;
import google.registry.model.transfer.TransferStatus;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeClock;
import google.registry.testing.TestOfyAndSql;
import google.registry.util.Idn;
import google.registry.xjc.domain.XjcDomainStatusType;
import google.registry.xjc.domain.XjcDomainStatusValueType;
@ -71,7 +74,6 @@ import java.io.ByteArrayOutputStream;
import org.joda.money.Money;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/**
@ -80,6 +82,7 @@ import org.junit.jupiter.api.extension.RegisterExtension;
* <p>This tests the mapping between {@link DomainBase} and {@link XjcRdeDomain} as well as some
* exceptional conditions.
*/
@DualDatabaseTest
public class DomainBaseToXjcConverterTest {
@RegisterExtension
@ -94,11 +97,11 @@ public class DomainBaseToXjcConverterTest {
createTld("xn--q9jyb4c");
}
@Test
@TestOfyAndSql
void testConvertThick() {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.FULL);
assertThat(bean.getClID()).isEqualTo("GetTheeBack");
assertThat(bean.getClID()).isEqualTo("TheRegistrar");
assertThat(
bean.getContacts().stream()
@ -111,7 +114,7 @@ public class DomainBaseToXjcConverterTest {
// that created the domain name object. An OPTIONAL client attribute
// is used to specify the client that performed the operation.
// This will always be null for us since we track each registrar as a separate client.
assertThat(bean.getCrRr().getValue()).isEqualTo("LawyerCat");
assertThat(bean.getCrRr().getValue()).isEqualTo("TheRegistrar");
assertThat(bean.getCrRr().getClient()).isNull();
assertThat(bean.getExDate()).isEqualTo(DateTime.parse("1930-01-01T00:00:00Z"));
@ -163,19 +166,19 @@ public class DomainBaseToXjcConverterTest {
assertThat(bean.getTrDate()).isEqualTo(DateTime.parse("1910-01-01T00:00:00Z"));
assertThat(bean.getTrnData().getTrStatus().toString()).isEqualTo("PENDING");
assertThat(bean.getTrnData().getReRr().getValue()).isEqualTo("gaining");
assertThat(bean.getTrnData().getAcRr().getValue()).isEqualTo("losing");
assertThat(bean.getTrnData().getReRr().getValue()).isEqualTo("NewRegistrar");
assertThat(bean.getTrnData().getAcRr().getValue()).isEqualTo("TheRegistrar");
assertThat(bean.getTrnData().getAcDate()).isEqualTo(DateTime.parse("1925-04-20T00:00:00Z"));
assertThat(bean.getTrnData().getReDate()).isEqualTo(DateTime.parse("1919-01-01T00:00:00Z"));
assertThat(bean.getTrnData().getExDate()).isEqualTo(DateTime.parse("1931-01-01T00:00:00Z"));
assertThat(bean.getUpDate()).isEqualTo(DateTime.parse("1920-01-01T00:00:00Z"));
assertThat(bean.getUpRr().getValue()).isEqualTo("IntoTheTempest");
assertThat(bean.getUpRr().getValue()).isEqualTo("TheRegistrar");
assertThat(bean.getUpRr().getClient()).isNull();
}
@Test
@TestOfyAndSql
void testConvertThin() {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.THIN);
assertThat(bean.getRegistrant()).isNull();
@ -183,13 +186,13 @@ public class DomainBaseToXjcConverterTest {
assertThat(bean.getSecDNS()).isNull();
}
@Test
@TestOfyAndSql
void testMarshalThick() throws Exception {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.FULL);
wrapDeposit(bean).marshal(new ByteArrayOutputStream(), UTF_8);
}
@Test
@TestOfyAndSql
void testMarshalThin() throws Exception {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.THIN);
wrapDeposit(bean).marshal(new ByteArrayOutputStream(), UTF_8);
@ -214,9 +217,15 @@ public class DomainBaseToXjcConverterTest {
static DomainBase makeDomainBase(FakeClock clock) {
DomainBase domain =
newDomainBase("example.xn--q9jyb4c").asBuilder().setRepoId("2-Q9JYB4C").build();
HistoryEntry historyEntry =
persistResource(new HistoryEntry.Builder().setParent(domain).build());
persistResource(
newDomainBase("example.xn--q9jyb4c").asBuilder().setRepoId("2-Q9JYB4C").build());
DomainHistory domainHistory =
persistResource(
new DomainHistory.Builder()
.setModificationTime(clock.nowUtc())
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setParent(domain)
.build());
BillingEvent.OneTime billingEvent =
persistResource(
new BillingEvent.OneTime.Builder()
@ -227,7 +236,7 @@ public class DomainBaseToXjcConverterTest {
.setPeriodYears(2)
.setEventTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setBillingTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setParent(historyEntry)
.setParent(domainHistory)
.build());
domain =
domain
@ -253,15 +262,15 @@ public class DomainBaseToXjcConverterTest {
"bird or fiend!? i shrieked upstarting",
"bog@cat.みんな")
.createVKey())))
.setCreationClientId("LawyerCat")
.setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("GetTheeBack")
.setPersistedCurrentSponsorClientId("TheRegistrar")
.setDsData(
ImmutableSet.of(
DelegationSignerData.create(123, 200, 230, base16().decode("1234567890"))))
.setDomainName(Idn.toASCII("love.みんな"))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("IntoTheTempest")
.setLastEppUpdateClientId("TheRegistrar")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setNameservers(
ImmutableSet.of(
@ -288,13 +297,13 @@ public class DomainBaseToXjcConverterTest {
.setPeriodYears(2)
.setEventTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setBillingTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setParent(historyEntry)
.setParent(domainHistory)
.build())),
GracePeriod.create(
GracePeriodStatus.TRANSFER,
domain.getRepoId(),
DateTime.parse("1920-01-01T00:00:00Z"),
"foo",
"TheRegistrar",
null)))
.setSubordinateHosts(ImmutableSet.of("home.by.horror.haunted"))
.setStatusValues(
@ -312,7 +321,7 @@ public class DomainBaseToXjcConverterTest {
.setClientId("TheRegistrar")
.setEventTime(END_OF_TIME)
.setRecurrenceEndTime(END_OF_TIME)
.setParent(historyEntry)
.setParent(domainHistory)
.build())
.createVKey())
.setAutorenewPollMessage(
@ -323,13 +332,13 @@ public class DomainBaseToXjcConverterTest {
.setEventTime(END_OF_TIME)
.setAutorenewEndTime(END_OF_TIME)
.setMsg("Domain was auto-renewed.")
.setParent(historyEntry)
.setParent(domainHistory)
.build())
.createVKey())
.setTransferData(
new DomainTransferData.Builder()
.setGainingClientId("gaining")
.setLosingClientId("losing")
.setGainingClientId("NewRegistrar")
.setLosingClientId("TheRegistrar")
.setPendingTransferExpirationTime(DateTime.parse("1925-04-20T00:00:00Z"))
.setServerApproveBillingEvent(billingEvent.createVKey())
.setServerApproveAutorenewEvent(
@ -341,7 +350,7 @@ public class DomainBaseToXjcConverterTest {
.setClientId("TheRegistrar")
.setEventTime(END_OF_TIME)
.setRecurrenceEndTime(END_OF_TIME)
.setParent(historyEntry)
.setParent(domainHistory)
.build())
.createVKey())
.setServerApproveAutorenewPollMessage(
@ -352,7 +361,7 @@ public class DomainBaseToXjcConverterTest {
.setEventTime(END_OF_TIME)
.setAutorenewEndTime(END_OF_TIME)
.setMsg("Domain was auto-renewed.")
.setParent(historyEntry)
.setParent(domainHistory)
.build())
.createVKey())
.setServerApproveEntities(ImmutableSet.of(billingEvent.createVKey()))
@ -374,8 +383,8 @@ public class DomainBaseToXjcConverterTest {
new ContactResource.Builder()
.setContactId(id)
.setEmailAddress(email)
.setPersistedCurrentSponsorClientId("GetTheeBack")
.setCreationClientId("GetTheeBack")
.setPersistedCurrentSponsorClientId("TheRegistrar")
.setCreationClientId("TheRegistrar")
.setCreationTimeForTest(END_OF_TIME)
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
@ -403,13 +412,13 @@ public class DomainBaseToXjcConverterTest {
clock.advanceOneMilli();
return persistEppResource(
new HostResource.Builder()
.setCreationClientId("LawyerCat")
.setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat")
.setPersistedCurrentSponsorClientId("TheRegistrar")
.setHostName(Idn.toASCII(fqhn))
.setInetAddresses(ImmutableSet.of(InetAddresses.forString(ip)))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat")
.setLastEppUpdateClientId("TheRegistrar")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId(repoId)
.setStatusValues(ImmutableSet.of(StatusValue.OK))

View file

@ -1111,6 +1111,7 @@ public class DatabaseHelper {
tm().put(
new HistoryEntry.Builder()
.setParent(resource)
.setClientId(resource.getPersistedCurrentSponsorClientId())
.setType(getHistoryEntryType(resource))
.setModificationTime(tm().getTransactionTime())
.build()

View file

@ -36,7 +36,9 @@ import google.registry.model.domain.DomainBase;
import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeClock;
import google.registry.testing.TestOfyAndSql;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Files;
@ -46,9 +48,9 @@ import org.joda.time.DateTime;
import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GenerateDnsReportCommand}. */
@DualDatabaseTest
class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportCommand> {
private final DateTime now = DateTime.now(UTC);
@ -158,7 +160,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
persistActiveDomain("should-be-ignored.example");
}
@Test
@TestOfyAndSql
void testSuccess() throws Exception {
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
Iterable<?> output = (Iterable<?>) getOutputAsJson();
@ -166,7 +168,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
assertThat(output).containsAtLeast(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
}
@Test
@TestOfyAndSql
void testSuccess_skipDeletedDomain() throws Exception {
persistResource(domain1.asBuilder().setDeletionTime(now).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -174,7 +176,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
}
@Test
@TestOfyAndSql
void testSuccess_skipDeletedNameserver() throws Exception {
persistResource(nameserver1.asBuilder().setDeletionTime(now).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -183,7 +185,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
assertThat(output).containsAtLeast(DOMAIN2_OUTPUT, NAMESERVER2_OUTPUT);
}
@Test
@TestOfyAndSql
void testSuccess_skipClientHoldDomain() throws Exception {
persistResource(domain1.asBuilder().addStatusValue(StatusValue.CLIENT_HOLD).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -191,7 +193,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
}
@Test
@TestOfyAndSql
void testSuccess_skipServerHoldDomain() throws Exception {
persistResource(domain1.asBuilder().addStatusValue(StatusValue.SERVER_HOLD).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -199,7 +201,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
}
@Test
@TestOfyAndSql
void testSuccess_skipPendingDeleteDomain() throws Exception {
persistResource(
domain1
@ -212,7 +214,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
}
@Test
@TestOfyAndSql
void testSuccess_skipDomainsWithoutNameservers() throws Exception {
persistResource(domain1.asBuilder().setNameservers(ImmutableSet.of()).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -220,12 +222,12 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
}
@Test
@TestOfyAndSql
void testFailure_tldDoesNotExist() {
assertThrows(IllegalArgumentException.class, () -> runCommand("--tld=foobar"));
}
@Test
@TestOfyAndSql
void testFailure_missingTldParameter() {
assertThrows(ParameterException.class, () -> runCommand(""));
}

View file

@ -37,18 +37,21 @@ import google.registry.model.billing.BillingEvent.Reason;
import google.registry.model.contact.ContactResource;
import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod;
import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource;
import google.registry.model.ofy.Ofy;
import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.InjectExtension;
import google.registry.testing.TestOfyAndSql;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link UpdateDomainCommand}. */
@DualDatabaseTest
class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand> {
private DomainBase domain;
@ -62,7 +65,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
domain = persistActiveDomain("example.tld");
}
@Test
@TestOfyAndSql
void testSuccess_complete() throws Exception {
runCommandForced(
"--client=NewRegistrar",
@ -82,7 +85,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_complete.xml");
}
@Test
@TestOfyAndSql
void testSuccess_completeWithSquareBrackets() throws Exception {
runCommandForced(
"--client=NewRegistrar",
@ -102,7 +105,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_complete.xml");
}
@Test
@TestOfyAndSql
void testSuccess_multipleDomains() throws Exception {
createTld("abc");
persistActiveDomain("example.abc");
@ -127,12 +130,12 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
.verifySent("domain_update_complete_abc.xml");
}
@Test
@TestOfyAndSql
void testSuccess_multipleDomains_setNameservers() throws Exception {
runTest_multipleDomains_setNameservers("-n ns1.foo.fake,ns2.foo.fake");
}
@Test
@TestOfyAndSql
void testSuccess_multipleDomains_setNameserversWithSquareBrackets() throws Exception {
runTest_multipleDomains_setNameservers("-n ns[1-2].foo.fake");
}
@ -162,7 +165,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
ImmutableMap.of("DOMAIN", "example.tld", "REMOVEHOST", "baz.bar.tld"));
}
@Test
@TestOfyAndSql
void testSuccess_add() throws Exception {
runCommandForced(
"--client=NewRegistrar",
@ -175,7 +178,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_add.xml");
}
@Test
@TestOfyAndSql
void testSuccess_remove() throws Exception {
runCommandForced(
"--client=NewRegistrar",
@ -188,14 +191,14 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_remove.xml");
}
@Test
@TestOfyAndSql
void testSuccess_change() throws Exception {
runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR", "example.tld");
eppVerifier.verifySent("domain_update_change.xml");
}
@Test
@TestOfyAndSql
void testSuccess_setNameservers() throws Exception {
HostResource host1 = persistActiveHost("ns1.zdns.google");
HostResource host2 = persistActiveHost("ns2.zdns.google");
@ -208,37 +211,28 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_set_nameservers.xml");
}
@Test
@TestOfyAndSql
void testSuccess_setContacts() throws Exception {
ContactResource adminContact1 = persistResource(newContactResource("crr-admin1"));
ContactResource adminContact2 = persistResource(newContactResource("crr-admin2"));
ContactResource techContact1 = persistResource(newContactResource("crr-tech1"));
ContactResource techContact2 = persistResource(newContactResource("crr-tech2"));
VKey<ContactResource> adminResourceKey1 = adminContact1.createVKey();
VKey<ContactResource> adminResourceKey2 = adminContact2.createVKey();
VKey<ContactResource> techResourceKey1 = techContact1.createVKey();
VKey<ContactResource> techResourceKey2 = techContact2.createVKey();
ContactResource adminContact = persistResource(newContactResource("crr-admin1"));
ContactResource techContact = persistResource(newContactResource("crr-tech1"));
VKey<ContactResource> adminContactKey = adminContact.createVKey();
VKey<ContactResource> techContactKey = techContact.createVKey();
persistResource(
newDomainBase("example.tld")
.asBuilder()
.setContacts(
ImmutableSet.of(
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey1),
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey2),
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey1),
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey2)))
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminContactKey),
DesignatedContact.create(DesignatedContact.Type.TECH, techContactKey)))
.build());
runCommandForced(
"--client=NewRegistrar",
"--admins=crr-admin2,crr-admin3",
"--techs=crr-tech2,crr-tech3",
"example.tld");
"--client=NewRegistrar", "--admins=crr-admin3", "--techs=crr-tech3", "example.tld");
eppVerifier.verifySent("domain_update_set_contacts.xml");
}
@Test
@TestOfyAndSql
void testSuccess_setStatuses() throws Exception {
HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey());
@ -256,14 +250,14 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_set_statuses.xml");
}
@Test
@TestOfyAndSql
void testSuccess_setDsRecords() throws Exception {
runCommandForced(
"--client=NewRegistrar", "--ds_records=1 2 3 abcd,4 5 6 EF01", "example.tld");
eppVerifier.verifySent("domain_update_set_ds_records.xml");
}
@Test
@TestOfyAndSql
void testSuccess_setDsRecords_withUnneededClear() throws Exception {
runCommandForced(
"--client=NewRegistrar",
@ -273,7 +267,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_set_ds_records.xml");
}
@Test
@TestOfyAndSql
void testSuccess_clearDsRecords() throws Exception {
runCommandForced(
"--client=NewRegistrar",
@ -282,14 +276,14 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_clear_ds_records.xml");
}
@Test
@TestOfyAndSql
void testSuccess_enableAutorenew() throws Exception {
runCommandForced("--client=NewRegistrar", "--autorenews=true", "example.tld");
eppVerifier.verifySent(
"domain_update_set_autorenew.xml", ImmutableMap.of("AUTORENEWS", "true"));
}
@Test
@TestOfyAndSql
void testSuccess_disableAutorenew() throws Exception {
runCommandForced("--client=NewRegistrar", "--autorenews=false", "example.tld");
eppVerifier.verifySent(
@ -297,11 +291,15 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(getStderrAsString()).doesNotContain("autorenew grace period");
}
@Test
@TestOfyAndSql
void testSuccess_disableAutorenew_inAutorenewGracePeriod() throws Exception {
HistoryEntry createHistoryEntry =
persistResource(
new HistoryEntry.Builder().setType(DOMAIN_CREATE).setParent(domain).build());
new DomainHistory.Builder()
.setModificationTime(fakeClock.nowUtc())
.setType(DOMAIN_CREATE)
.setParent(domain)
.build());
BillingEvent.Recurring autorenewBillingEvent =
persistResource(
new BillingEvent.Recurring.Builder()
@ -335,40 +333,34 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(stdErr).contains("example.tld");
}
@Test
@TestOfyAndSql
void testSuccess_canUpdatePendingDeleteDomain_whenSuperuserPassesOverrideFlag() throws Exception {
ContactResource adminContact1 = persistResource(newContactResource("crr-admin1"));
ContactResource adminContact2 = persistResource(newContactResource("crr-admin2"));
ContactResource techContact1 = persistResource(newContactResource("crr-tech1"));
ContactResource techContact2 = persistResource(newContactResource("crr-tech2"));
VKey<ContactResource> adminResourceKey1 = adminContact1.createVKey();
VKey<ContactResource> adminResourceKey2 = adminContact2.createVKey();
VKey<ContactResource> techResourceKey1 = techContact1.createVKey();
VKey<ContactResource> techResourceKey2 = techContact2.createVKey();
ContactResource adminContact = persistResource(newContactResource("crr-admin1"));
ContactResource techContact = persistResource(newContactResource("crr-tech1"));
VKey<ContactResource> adminContactKey = adminContact.createVKey();
VKey<ContactResource> techContactKey = techContact.createVKey();
persistResource(
newDomainBase("example.tld")
.asBuilder()
.setContacts(
ImmutableSet.of(
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey1),
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey2),
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey1),
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey2)))
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminContactKey),
DesignatedContact.create(DesignatedContact.Type.TECH, techContactKey)))
.setStatusValues(ImmutableSet.of(PENDING_DELETE))
.build());
runCommandForced(
"--client=NewRegistrar",
"--admins=crr-admin2,crr-admin3",
"--techs=crr-tech2,crr-tech3",
"--admins=crr-admin3",
"--techs=crr-tech3",
"--superuser",
"--force_in_pending_delete",
"example.tld");
eppVerifier.expectSuperuser().verifySent("domain_update_set_contacts.xml");
}
@Test
@TestOfyAndSql
void testFailure_cantUpdateRegistryLockedDomainEvenAsSuperuser() {
HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey());
@ -393,7 +385,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
.contains("The domain 'example.tld' has status SERVER_UPDATE_PROHIBITED.");
}
@Test
@TestOfyAndSql
void testFailure_cantUpdatePendingDeleteDomainEvenAsSuperuser_withoutPassingOverrideFlag() {
HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey());
@ -416,7 +408,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(e).hasMessageThat().contains("The domain 'example.tld' has status PENDING_DELETE.");
}
@Test
@TestOfyAndSql
void testFailure_duplicateDomains() {
IllegalArgumentException thrown =
assertThrows(
@ -431,7 +423,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found");
}
@Test
@TestOfyAndSql
void testFailure_missingDomain() {
ParameterException thrown =
assertThrows(
@ -442,7 +434,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("Main parameters are required");
}
@Test
@TestOfyAndSql
void testFailure_missingClientId() {
ParameterException thrown =
assertThrows(
@ -451,7 +443,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("--client");
}
@Test
@TestOfyAndSql
void testFailure_addTooManyNameServers() {
IllegalArgumentException thrown =
assertThrows(
@ -470,7 +462,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("You can add at most 13 nameservers");
}
@Test
@TestOfyAndSql
void testFailure_providedNameserversAndAddNameservers() {
IllegalArgumentException thrown =
assertThrows(
@ -488,7 +480,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_nameservers and remove_nameservers flags.");
}
@Test
@TestOfyAndSql
void testFailure_providedNameserversAndRemoveNameservers() {
IllegalArgumentException thrown =
assertThrows(
@ -506,7 +498,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_nameservers and remove_nameservers flags.");
}
@Test
@TestOfyAndSql
void testFailure_providedAdminsAndAddAdmins() {
IllegalArgumentException thrown =
assertThrows(
@ -524,7 +516,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_admins and remove_admins flags.");
}
@Test
@TestOfyAndSql
void testFailure_providedAdminsAndRemoveAdmins() {
IllegalArgumentException thrown =
assertThrows(
@ -542,7 +534,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_admins and remove_admins flags.");
}
@Test
@TestOfyAndSql
void testFailure_providedTechsAndAddTechs() {
IllegalArgumentException thrown =
assertThrows(
@ -559,7 +551,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
}
@Test
@TestOfyAndSql
void testFailure_providedTechsAndRemoveTechs() {
IllegalArgumentException thrown =
assertThrows(
@ -576,7 +568,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
"If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
}
@Test
@TestOfyAndSql
void testFailure_providedStatusesAndAddStatuses() {
IllegalArgumentException thrown =
assertThrows(
@ -594,7 +586,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_statuses and remove_statuses flags.");
}
@Test
@TestOfyAndSql
void testFailure_providedStatusesAndRemoveStatuses() {
IllegalArgumentException thrown =
assertThrows(
@ -612,7 +604,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_statuses and remove_statuses flags.");
}
@Test
@TestOfyAndSql
void testFailure_provideDsRecordsAndAddDsRecords() {
IllegalArgumentException thrown =
assertThrows(
@ -630,7 +622,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_ds_records and remove_ds_records flags.");
}
@Test
@TestOfyAndSql
void testFailure_provideDsRecordsAndRemoveDsRecords() {
IllegalArgumentException thrown =
assertThrows(
@ -648,7 +640,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_ds_records and remove_ds_records flags.");
}
@Test
@TestOfyAndSql
void testFailure_clearDsRecordsAndAddDsRecords() {
IllegalArgumentException thrown =
assertThrows(
@ -666,7 +658,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_ds_records and remove_ds_records flags.");
}
@Test
@TestOfyAndSql
void testFailure_clearDsRecordsAndRemoveDsRecords() {
IllegalArgumentException thrown =
assertThrows(

View file

@ -38,14 +38,16 @@ import google.registry.model.registrar.Registrar;
import google.registry.model.registrar.RegistrarContact;
import google.registry.persistence.VKey;
import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeClock;
import google.registry.testing.TestOfyAndSql;
import google.registry.whois.WhoisResponse.WhoisResponseResults;
import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DomainWhoisResponse}. */
@DualDatabaseTest
class DomainWhoisResponseTest {
@RegisterExtension
@ -97,130 +99,146 @@ class DomainWhoisResponseTest {
.setRepoId("2-ROID")
.build());
registrant = persistResource(new ContactResource.Builder()
.setContactId("5372808-ERL")
.setRepoId("4-ROID")
.setLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.LOCALIZED)
.setName("SHOULD NOT BE USED")
.setOrg("SHOULD NOT BE USED")
.setAddress(new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.INTERNATIONALIZED)
.setName("EXAMPLE REGISTRANT")
.setOrg("Tom & Jerry Corp.")
.setAddress(new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setVoiceNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551212")
.setExtension("1234")
.build())
.setFaxNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551213")
.setExtension("4321")
.build())
.setEmailAddress("EMAIL@EXAMPLE.tld")
.build());
registrant =
persistResource(
new ContactResource.Builder()
.setContactId("5372808-ERL")
.setRepoId("4-ROID")
.setCreationClientId("NewRegistrar")
.setPersistedCurrentSponsorClientId("NewRegistrar")
.setLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.LOCALIZED)
.setName("SHOULD NOT BE USED")
.setOrg("SHOULD NOT BE USED")
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.INTERNATIONALIZED)
.setName("EXAMPLE REGISTRANT")
.setOrg("Tom & Jerry Corp.")
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setVoiceNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551212")
.setExtension("1234")
.build())
.setFaxNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551213")
.setExtension("4321")
.build())
.setEmailAddress("EMAIL@EXAMPLE.tld")
.build());
adminContact = persistResource(new ContactResource.Builder()
.setContactId("5372809-ERL")
.setRepoId("5-ROID")
.setLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.LOCALIZED)
.setName("SHOULD NOT BE USED")
.setOrg("SHOULD NOT BE USED")
.setAddress(new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.INTERNATIONALIZED)
.setName("EXAMPLE REGISTRANT ADMINISTRATIVE")
.setOrg("EXAMPLE REGISTRANT ORGANIZATION")
.setAddress(new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setVoiceNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551212")
.setExtension("1234")
.build())
.setFaxNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551213")
.build())
.setEmailAddress("EMAIL@EXAMPLE.tld")
.build());
adminContact =
persistResource(
new ContactResource.Builder()
.setContactId("5372809-ERL")
.setRepoId("5-ROID")
.setCreationClientId("NewRegistrar")
.setPersistedCurrentSponsorClientId("NewRegistrar")
.setLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.LOCALIZED)
.setName("SHOULD NOT BE USED")
.setOrg("SHOULD NOT BE USED")
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.INTERNATIONALIZED)
.setName("EXAMPLE REGISTRANT ADMINISTRATIVE")
.setOrg("EXAMPLE REGISTRANT ORGANIZATION")
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setVoiceNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551212")
.setExtension("1234")
.build())
.setFaxNumber(
new ContactPhoneNumber.Builder().setPhoneNumber("+1.5555551213").build())
.setEmailAddress("EMAIL@EXAMPLE.tld")
.build());
techContact = persistResource(new ContactResource.Builder()
.setContactId("5372811-ERL")
.setRepoId("6-ROID")
.setLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.LOCALIZED)
.setName("SHOULD NOT BE USED")
.setOrg("SHOULD NOT BE USED")
.setAddress(new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.INTERNATIONALIZED)
.setName("EXAMPLE REGISTRAR TECHNICAL")
.setOrg("EXAMPLE REGISTRAR LLC")
.setAddress(new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setVoiceNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.1235551234")
.setExtension("1234")
.build())
.setFaxNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551213")
.setExtension("93")
.build())
.setEmailAddress("EMAIL@EXAMPLE.tld")
.build());
techContact =
persistResource(
new ContactResource.Builder()
.setContactId("5372811-ERL")
.setRepoId("6-ROID")
.setCreationClientId("NewRegistrar")
.setPersistedCurrentSponsorClientId("NewRegistrar")
.setLocalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.LOCALIZED)
.setName("SHOULD NOT BE USED")
.setOrg("SHOULD NOT BE USED")
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setInternationalizedPostalInfo(
new PostalInfo.Builder()
.setType(PostalInfo.Type.INTERNATIONALIZED)
.setName("EXAMPLE REGISTRAR TECHNICAL")
.setOrg("EXAMPLE REGISTRAR LLC")
.setAddress(
new ContactAddress.Builder()
.setStreet(ImmutableList.of("123 EXAMPLE STREET"))
.setCity("ANYTOWN")
.setState("AP")
.setZip("A1A1A1")
.setCountryCode("EX")
.build())
.build())
.setVoiceNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.1235551234")
.setExtension("1234")
.build())
.setFaxNumber(
new ContactPhoneNumber.Builder()
.setPhoneNumber("+1.5555551213")
.setExtension("93")
.build())
.setEmailAddress("EMAIL@EXAMPLE.tld")
.build());
VKey<HostResource> hostResource1Key = hostResource1.createVKey();
VKey<HostResource> hostResource2Key = hostResource2.createVKey();
@ -234,10 +252,11 @@ class DomainWhoisResponseTest {
new DomainBase.Builder()
.setDomainName("example.tld")
.setRepoId(repoId)
.setCreationClientId("NewRegistrar")
.setPersistedCurrentSponsorClientId("NewRegistrar")
.setLastEppUpdateTime(DateTime.parse("2009-05-29T20:13:00Z"))
.setCreationTimeForTest(DateTime.parse("2000-10-08T00:45:00Z"))
.setRegistrationExpirationTime(DateTime.parse("2010-10-08T00:44:59Z"))
.setPersistedCurrentSponsorClientId("NewRegistrar")
.setStatusValues(
ImmutableSet.of(
StatusValue.CLIENT_DELETE_PROHIBITED,
@ -253,13 +272,14 @@ class DomainWhoisResponseTest {
.setDsData(ImmutableSet.of(DelegationSignerData.create(1, 2, 3, "deadface")))
.setGracePeriods(
ImmutableSet.of(
GracePeriod.create(GracePeriodStatus.ADD, repoId, END_OF_TIME, "", null),
GracePeriod.create(
GracePeriodStatus.TRANSFER, repoId, END_OF_TIME, "", null)))
GracePeriodStatus.ADD, repoId, END_OF_TIME, "NewRegistrar", null),
GracePeriod.create(
GracePeriodStatus.TRANSFER, repoId, END_OF_TIME, "NewRegistrar", null)))
.build());
}
@Test
@TestOfyAndSql
void getPlainTextOutputTest() {
DomainWhoisResponse domainWhoisResponse =
new DomainWhoisResponse(domainBase, false, "Please contact registrar", clock.nowUtc());
@ -270,7 +290,7 @@ class DomainWhoisResponseTest {
.isEqualTo(WhoisResponseResults.create(loadFile("whois_domain.txt"), 1));
}
@Test
@TestOfyAndSql
void getPlainTextOutputTest_registrarAbuseInfoMissing() {
persistResource(abuseContact.asBuilder().setVisibleInDomainWhoisAsAbuse(false).build());
DomainWhoisResponse domainWhoisResponse =
@ -282,7 +302,7 @@ class DomainWhoisResponseTest {
loadFile("whois_domain_registrar_abuse_info_missing.txt"), 1));
}
@Test
@TestOfyAndSql
void getPlainTextOutputTest_fullOutput() {
DomainWhoisResponse domainWhoisResponse =
new DomainWhoisResponse(domainBase, true, "Please contact registrar", clock.nowUtc());
@ -293,7 +313,7 @@ class DomainWhoisResponseTest {
.isEqualTo(WhoisResponseResults.create(loadFile("whois_domain_full_output.txt"), 1));
}
@Test
@TestOfyAndSql
void addImplicitOkStatusTest() {
DomainWhoisResponse domainWhoisResponse =
new DomainWhoisResponse(