From 4e7dd7a95abe5e786666ee4338fd3463fc8c8f80 Mon Sep 17 00:00:00 2001 From: gbrodman Date: Fri, 2 Apr 2021 11:41:00 -0400 Subject: [PATCH] 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. --- .../registry/flows/domain/DomainInfoFlow.java | 15 +- .../domain/DomainTransferCancelFlow.java | 12 +- .../registry/model/domain/DomainContent.java | 15 +- .../rde/DomainBaseToXjcConverter.java | 5 +- .../tools/GenerateDnsReportCommand.java | 16 +- .../registry/tools/UpdateDomainCommand.java | 17 +- .../writer/clouddns/CloudDnsWriterTest.java | 38 +-- .../writer/dnsupdate/DnsUpdateWriterTest.java | 30 +- .../flows/domain/DomainInfoFlowTest.java | 119 ++++---- .../domain/DomainTransferCancelFlowTest.java | 70 +++-- .../rde/DomainBaseToXjcConverterTest.java | 69 +++-- .../registry/testing/DatabaseHelper.java | 1 + .../tools/GenerateDnsReportCommandTest.java | 22 +- .../tools/UpdateDomainCommandTest.java | 128 ++++---- .../whois/DomainWhoisResponseTest.java | 280 ++++++++++-------- 15 files changed, 442 insertions(+), 395 deletions(-) diff --git a/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java b/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java index 9ace8b972..532e363b8 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainInfoFlow.java @@ -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) diff --git a/core/src/main/java/google/registry/flows/domain/DomainTransferCancelFlow.java b/core/src/main/java/google/registry/flows/domain/DomainTransferCancelFlow.java index 8a8fa1d07..d2b504534 100644 --- a/core/src/main/java/google/registry/flows/domain/DomainTransferCancelFlow.java +++ b/core/src/main/java/google/registry/flows/domain/DomainTransferCancelFlow.java @@ -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().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); diff --git a/core/src/main/java/google/registry/model/domain/DomainContent.java b/core/src/main/java/google/registry/model/domain/DomainContent.java index 189fd8646..305e38aa2 100644 --- a/core/src/main/java/google/registry/model/domain/DomainContent.java +++ b/core/src/main/java/google/registry/model/domain/DomainContent.java @@ -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 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. */ diff --git a/core/src/main/java/google/registry/rde/DomainBaseToXjcConverter.java b/core/src/main/java/google/registry/rde/DomainBaseToXjcConverter.java index f0976ca36..8ed46d5be 100644 --- a/core/src/main/java/google/registry/rde/DomainBaseToXjcConverter.java +++ b/core/src/main/java/google/registry/rde/DomainBaseToXjcConverter.java @@ -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", diff --git a/core/src/main/java/google/registry/tools/GenerateDnsReportCommand.java b/core/src/main/java/google/registry/tools/GenerateDnsReportCommand.java index ac70ea620..f761d593a 100644 --- a/core/src/main/java/google/registry/tools/GenerateDnsReportCommand.java +++ b/core/src/main/java/google/registry/tools/GenerateDnsReportCommand.java @@ -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 domains = ofy().load().type(DomainBase.class).filter("tld", tld); + Iterable 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 nameservers = ofy().load().type(HostResource.class); + Iterable nameservers = + transactIfJpaTm(() -> tm().loadAllOf(HostResource.class)); for (HostResource nameserver : nameservers) { // Skip deleted hosts and external hosts. if (isBeforeOrAt(nameserver.getDeletionTime(), now) diff --git a/core/src/main/java/google/registry/tools/UpdateDomainCommand.java b/core/src/main/java/google/registry/tools/UpdateDomainCommand.java index 8a84d7078..2462f7c39 100644 --- a/core/src/main/java/google/registry/tools/UpdateDomainCommand.java +++ b/core/src/main/java/google/registry/tools/UpdateDomainCommand.java @@ -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 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 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 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())); } } diff --git a/core/src/test/java/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java b/core/src/test/java/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java index 59e435741..6a924641c 100644 --- a/core/src/test/java/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java +++ b/core/src/test/java/google/registry/dns/writer/clouddns/CloudDnsWriterTest.java @@ -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(); diff --git a/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java b/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java index b624bc350..59ddc9f4f 100644 --- a/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java +++ b/core/src/test/java/google/registry/dns/writer/dnsupdate/DnsUpdateWriterTest.java @@ -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")) diff --git a/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java b/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java index 66cc56ed0..8f4144de0 100644 --- a/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java +++ b/core/src/test/java/google/registry/flows/domain/DomainInfoFlowTest.java @@ -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 { @Order(value = Order.DEFAULT - 3) @@ -201,87 +204,87 @@ class DomainInfoFlowTest extends ResourceFlowTestCase { @@ -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 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)) diff --git a/core/src/test/java/google/registry/rde/DomainBaseToXjcConverterTest.java b/core/src/test/java/google/registry/rde/DomainBaseToXjcConverterTest.java index 9649d4c6e..5787be2a5 100644 --- a/core/src/test/java/google/registry/rde/DomainBaseToXjcConverterTest.java +++ b/core/src/test/java/google/registry/rde/DomainBaseToXjcConverterTest.java @@ -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; *

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)) diff --git a/core/src/test/java/google/registry/testing/DatabaseHelper.java b/core/src/test/java/google/registry/testing/DatabaseHelper.java index 9e69c3976..4c57cf8e3 100644 --- a/core/src/test/java/google/registry/testing/DatabaseHelper.java +++ b/core/src/test/java/google/registry/testing/DatabaseHelper.java @@ -1111,6 +1111,7 @@ public class DatabaseHelper { tm().put( new HistoryEntry.Builder() .setParent(resource) + .setClientId(resource.getPersistedCurrentSponsorClientId()) .setType(getHistoryEntryType(resource)) .setModificationTime(tm().getTransactionTime()) .build() diff --git a/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java b/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java index 38c974a2a..338d37dcf 100644 --- a/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java +++ b/core/src/test/java/google/registry/tools/GenerateDnsReportCommandTest.java @@ -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 { private final DateTime now = DateTime.now(UTC); @@ -158,7 +160,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase output = (Iterable) getOutputAsJson(); @@ -166,7 +168,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase runCommand("--tld=foobar")); } - @Test + @TestOfyAndSql void testFailure_missingTldParameter() { assertThrows(ParameterException.class, () -> runCommand("")); } diff --git a/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java b/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java index b4ca09ff2..e8eaf8650 100644 --- a/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java +++ b/core/src/test/java/google/registry/tools/UpdateDomainCommandTest.java @@ -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 { private DomainBase domain; @@ -62,7 +65,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase adminResourceKey1 = adminContact1.createVKey(); - VKey adminResourceKey2 = adminContact2.createVKey(); - VKey techResourceKey1 = techContact1.createVKey(); - VKey techResourceKey2 = techContact2.createVKey(); + ContactResource adminContact = persistResource(newContactResource("crr-admin1")); + ContactResource techContact = persistResource(newContactResource("crr-tech1")); + VKey adminContactKey = adminContact.createVKey(); + VKey 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> nameservers = ImmutableSet.of(host.createVKey()); @@ -256,14 +250,14 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase adminResourceKey1 = adminContact1.createVKey(); - VKey adminResourceKey2 = adminContact2.createVKey(); - VKey techResourceKey1 = techContact1.createVKey(); - VKey techResourceKey2 = techContact2.createVKey(); + ContactResource adminContact = persistResource(newContactResource("crr-admin1")); + ContactResource techContact = persistResource(newContactResource("crr-tech1")); + VKey adminContactKey = adminContact.createVKey(); + VKey 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> nameservers = ImmutableSet.of(host.createVKey()); @@ -393,7 +385,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase> nameservers = ImmutableSet.of(host.createVKey()); @@ -416,7 +408,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase hostResource1Key = hostResource1.createVKey(); VKey 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(