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.flows.domain.DomainFlowUtils.loadForeignKeyedDesignatedContacts;
import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.model.EppResourceUtils.loadByForeignKey;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; 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.ImmutableList;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -100,9 +101,11 @@ public final class DomainInfoFlow implements Flow {
verifyOptionalAuthInfo(authInfo, domain); verifyOptionalAuthInfo(authInfo, domain);
flowCustomLogic.afterValidation( flowCustomLogic.afterValidation(
AfterValidationParameters.newBuilder().setDomain(domain).build()); AfterValidationParameters.newBuilder().setDomain(domain).build());
// Prefetch all referenced resources. Calling values() blocks until loading is done. // In ofy, refetch all referenced resources.
tm().loadByKeys(domain.getNameservers()); if (tm().isOfy()) {
tm().loadByKeys(domain.getReferencedContacts()); tm().loadByKeys(domain.getNameservers());
tm().loadByKeys(domain.getReferencedContacts());
}
// Registrars can only see a few fields on unauthorized domains. // Registrars can only see a few fields on unauthorized domains.
// This is a policy decision that is left up to us by the rfcs. // This is a policy decision that is left up to us by the rfcs.
DomainInfoData.Builder infoBuilder = DomainInfoData.Builder infoBuilder =
@ -110,14 +113,16 @@ public final class DomainInfoFlow implements Flow {
.setFullyQualifiedDomainName(domain.getDomainName()) .setFullyQualifiedDomainName(domain.getDomainName())
.setRepoId(domain.getRepoId()) .setRepoId(domain.getRepoId())
.setCurrentSponsorClientId(domain.getCurrentSponsorClientId()) .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 // 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. // will have already verified the authInfo is valid.
if (clientId.equals(domain.getCurrentSponsorClientId()) || authInfo.isPresent()) { if (clientId.equals(domain.getCurrentSponsorClientId()) || authInfo.isPresent()) {
HostsRequest hostsRequest = ((Info) resourceCommand).getHostsRequest(); HostsRequest hostsRequest = ((Info) resourceCommand).getHostsRequest();
infoBuilder infoBuilder
.setStatusValues(domain.getStatusValues()) .setStatusValues(domain.getStatusValues())
.setContacts(loadForeignKeyedDesignatedContacts(domain.getContacts())) .setContacts(
transactIfJpaTm(() -> loadForeignKeyedDesignatedContacts(domain.getContacts())))
.setNameservers(hostsRequest.requestDelegated() ? domain.loadNameserverHostNames() : null) .setNameservers(hostsRequest.requestDelegated() ? domain.loadNameserverHostNames() : null)
.setSubordinateHosts( .setSubordinateHosts(
hostsRequest.requestSubordinate() ? domain.getSubordinateHosts() : null) 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.createLosingTransferPollMessage;
import static google.registry.flows.domain.DomainTransferUtils.createTransferResponse; import static google.registry.flows.domain.DomainTransferUtils.createTransferResponse;
import static google.registry.model.ResourceTransferUtils.denyPendingTransfer; 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.model.reporting.DomainTransactionRecord.TransactionReportField.TRANSFER_SUCCESSFUL;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
import static google.registry.util.DateTimeUtils.END_OF_TIME; 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.FlowModule.TargetId;
import google.registry.flows.TransactionalFlow; import google.registry.flows.TransactionalFlow;
import google.registry.flows.annotations.ReportingSpec; import google.registry.flows.annotations.ReportingSpec;
import google.registry.model.ImmutableObject;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.metadata.MetadataExtension; import google.registry.model.domain.metadata.MetadataExtension;
import google.registry.model.eppcommon.AuthInfo; import google.registry.model.eppcommon.AuthInfo;
@ -100,11 +98,11 @@ public final class DomainTransferCancelFlow implements TransactionalFlow {
HistoryEntry historyEntry = buildHistoryEntry(existingDomain, registry, now); HistoryEntry historyEntry = buildHistoryEntry(existingDomain, registry, now);
DomainBase newDomain = DomainBase newDomain =
denyPendingTransfer(existingDomain, TransferStatus.CLIENT_CANCELLED, now, clientId); denyPendingTransfer(existingDomain, TransferStatus.CLIENT_CANCELLED, now, clientId);
ofy().save().<ImmutableObject>entities( tm().putAll(
newDomain, newDomain,
historyEntry, historyEntry,
createLosingTransferPollMessage( createLosingTransferPollMessage(
targetId, newDomain.getTransferData(), null, historyEntry)); targetId, newDomain.getTransferData(), null, historyEntry));
// Reopen the autorenew event and poll message that we closed for the implicit transfer. This // 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. // may recreate the autorenew poll message if it was deleted when the transfer request was made.
updateAutorenewRecurrenceEndTime(existingDomain, END_OF_TIME); 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 com.google.common.collect.Sets.intersection;
import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime; import static google.registry.model.EppResourceUtils.projectResourceOntoBuilderAtTime;
import static google.registry.model.EppResourceUtils.setAutomaticTransferSuccessProperties; 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.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.forceEmptyToNull;
import static google.registry.util.CollectionUtils.nullToEmpty; import static google.registry.util.CollectionUtils.nullToEmpty;
import static google.registry.util.CollectionUtils.nullToEmptyImmutableCopy; 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. */ /** Loads and returns the fully qualified host names of all linked nameservers. */
public ImmutableSortedSet<String> loadNameserverHostNames() { public ImmutableSortedSet<String> loadNameserverHostNames() {
return ofy() return transactIfJpaTm(
.load() () ->
.keys(getNameservers().stream().map(VKey::getOfyKey).collect(toImmutableSet())) tm().loadByKeys(getNameservers()).values().stream()
.values() .map(HostResource::getHostName)
.stream() .collect(toImmutableSortedSet(Ordering.natural())));
.map(HostResource::getHostName)
.collect(toImmutableSortedSet(Ordering.natural()));
} }
/** A key to the registrant who registered this domain. */ /** 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 com.google.common.base.Preconditions.checkState;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; 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.Ascii;
import com.google.common.base.Strings; import com.google.common.base.Strings;
@ -172,7 +173,7 @@ final class DomainBaseToXjcConverter {
if (registrant == null) { if (registrant == null) {
logger.atWarning().log("Domain %s has no registrant contact.", domainName); logger.atWarning().log("Domain %s has no registrant contact.", domainName);
} else { } else {
ContactResource registrantContact = tm().loadByKey(registrant); ContactResource registrantContact = transactIfJpaTm(() -> tm().loadByKey(registrant));
checkState( checkState(
registrantContact != null, registrantContact != null,
"Registrant contact %s on domain %s does not exist", "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", "Contact key for type %s is null on domain %s",
model.getType(), model.getType(),
domainName); domainName);
ContactResource contact = tm().loadByKey(model.getContactKey()); ContactResource contact = transactIfJpaTm(() -> tm().loadByKey(model.getContactKey()));
checkState( checkState(
contact != null, contact != null,
"Contact %s on domain %s does not exist", "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 com.google.common.io.BaseEncoding.base16;
import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.model.ofy.ObjectifyService.ofy;
import static google.registry.model.registry.Registries.assertTldExists; 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 google.registry.util.DateTimeUtils.isBeforeOrAt;
import static java.nio.charset.StandardCharsets.US_ASCII; import static java.nio.charset.StandardCharsets.US_ASCII;
@ -71,7 +74,15 @@ final class GenerateDnsReportCommand implements CommandWithRemoteApi {
String generate() { String generate() {
result.append("[\n"); 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) { for (DomainBase domain : domains) {
// Skip deleted domains and domains that don't get published to DNS. // Skip deleted domains and domains that don't get published to DNS.
if (isBeforeOrAt(domain.getDeletionTime(), now) || !domain.shouldPublishToDns()) { if (isBeforeOrAt(domain.getDeletionTime(), now) || !domain.shouldPublishToDns()) {
@ -80,7 +91,8 @@ final class GenerateDnsReportCommand implements CommandWithRemoteApi {
write(domain); write(domain);
} }
Iterable<HostResource> nameservers = ofy().load().type(HostResource.class); Iterable<HostResource> nameservers =
transactIfJpaTm(() -> tm().loadAllOf(HostResource.class));
for (HostResource nameserver : nameservers) { for (HostResource nameserver : nameservers) {
// Skip deleted hosts and external hosts. // Skip deleted hosts and external hosts.
if (isBeforeOrAt(nameserver.getDeletionTime(), now) 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.PENDING_DELETE;
import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED; import static google.registry.model.eppcommon.StatusValue.SERVER_UPDATE_PROHIBITED;
import static google.registry.persistence.transaction.TransactionManagerFactory.tm; 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 google.registry.util.PreconditionsUtils.checkArgumentPresent;
import static java.util.function.Predicate.isEqual; import static java.util.function.Predicate.isEqual;
@ -68,10 +69,10 @@ final class UpdateDomainCommand extends CreateOrUpdateDomainCommand {
validateWith = NameserversParameter.class) validateWith = NameserversParameter.class)
private Set<String> addNameservers = new HashSet<>(); private Set<String> addNameservers = new HashSet<>();
// TODO(b/184067241): enforce only one of each type of contact
@Parameter( @Parameter(
names = "--add_admins", names = "--add_admins",
description = "Admins to add. Cannot be set if --admins is set." description = "Admins to add. Cannot be set if --admins is set.")
)
private List<String> addAdmins = new ArrayList<>(); private List<String> addAdmins = new ArrayList<>();
@Parameter(names = "--add_techs", description = "Techs to add. Cannot be set if --techs is set.") @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( ImmutableSet<String> getContactsOfType(
DomainBase domainBase, final DesignatedContact.Type contactType) { DomainBase domainBase, final DesignatedContact.Type contactType) {
return domainBase.getContacts().stream() return transactIfJpaTm(
.filter(contact -> contact.getType().equals(contactType)) () ->
.map(contact -> tm().loadByKey(contact.getContactKey()).getContactId()) domainBase.getContacts().stream()
.collect(toImmutableSet()); .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.model.host.HostResource;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.TestOfyAndSql;
import google.registry.util.Retrier; import google.registry.util.Retrier;
import google.registry.util.SystemClock; import google.registry.util.SystemClock;
import google.registry.util.SystemSleeper; import google.registry.util.SystemSleeper;
@ -54,7 +56,6 @@ import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach; 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.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@ -67,6 +68,7 @@ import org.mockito.quality.Strictness;
/** Test case for {@link CloudDnsWriter}. */ /** Test case for {@link CloudDnsWriter}. */
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
@DualDatabaseTest
public class CloudDnsWriterTest { public class CloudDnsWriterTest {
@RegisterExtension @RegisterExtension
@ -312,7 +314,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testLoadDomain_nonExistentDomain() { void testLoadDomain_nonExistentDomain() {
writer.publishDomain("example.tld"); writer.publishDomain("example.tld");
@ -320,7 +322,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testLoadDomain_noDsDataOrNameservers() { void testLoadDomain_noDsDataOrNameservers() {
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0)); persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
writer.publishDomain("example.tld"); writer.publishDomain("example.tld");
@ -328,7 +330,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 0, 0, 0)); verifyZone(fakeDomainRecords("example.tld", 0, 0, 0, 0));
} }
@Test @TestOfyAndSql
void testLoadDomain_deleteOldData() { void testLoadDomain_deleteOldData() {
stubZone = fakeDomainRecords("example.tld", 2, 2, 2, 2); stubZone = fakeDomainRecords("example.tld", 2, 2, 2, 2);
persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0)); persistResource(fakeDomain("example.tld", ImmutableSet.of(), 0));
@ -337,7 +339,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 0, 0, 0)); verifyZone(fakeDomainRecords("example.tld", 0, 0, 0, 0));
} }
@Test @TestOfyAndSql
void testLoadDomain_withExternalNs() { void testLoadDomain_withExternalNs() {
persistResource( persistResource(
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 0)); 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)); verifyZone(fakeDomainRecords("example.tld", 0, 0, 1, 0));
} }
@Test @TestOfyAndSql
void testLoadDomain_withDsData() { void testLoadDomain_withDsData() {
persistResource( persistResource(
fakeDomain("example.tld", ImmutableSet.of(persistResource(fakeHost("0.external"))), 1)); 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)); verifyZone(fakeDomainRecords("example.tld", 0, 0, 1, 1));
} }
@Test @TestOfyAndSql
void testLoadDomain_withInBailiwickNs_IPv4() { void testLoadDomain_withInBailiwickNs_IPv4() {
persistResource( persistResource(
fakeDomain( fakeDomain(
@ -370,7 +372,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0)); verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0));
} }
@Test @TestOfyAndSql
void testLoadDomain_withInBailiwickNs_IPv6() { void testLoadDomain_withInBailiwickNs_IPv6() {
persistResource( persistResource(
fakeDomain( fakeDomain(
@ -385,7 +387,7 @@ public class CloudDnsWriterTest {
verifyZone(fakeDomainRecords("example.tld", 0, 1, 0, 0)); verifyZone(fakeDomainRecords("example.tld", 0, 1, 0, 0));
} }
@Test @TestOfyAndSql
void testLoadDomain_withNameserveThatEndsWithDomainName() { void testLoadDomain_withNameserveThatEndsWithDomainName() {
persistResource( persistResource(
fakeDomain( fakeDomain(
@ -398,7 +400,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testLoadHost_externalHost() { void testLoadHost_externalHost() {
writer.publishHost("ns1.example.com"); writer.publishHost("ns1.example.com");
@ -406,7 +408,7 @@ public class CloudDnsWriterTest {
verifyZone(ImmutableSet.of()); verifyZone(ImmutableSet.of());
} }
@Test @TestOfyAndSql
void testLoadHost_removeStaleNsRecords() { void testLoadHost_removeStaleNsRecords() {
// Initialize the zone with both NS records // Initialize the zone with both NS records
stubZone = fakeDomainRecords("example.tld", 2, 0, 0, 0); stubZone = fakeDomainRecords("example.tld", 2, 0, 0, 0);
@ -429,7 +431,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void retryMutateZoneOnError() { void retryMutateZoneOnError() {
CloudDnsWriter spyWriter = spy(writer); CloudDnsWriter spyWriter = spy(writer);
// First call - throw. Second call - do nothing. // First call - throw. Second call - do nothing.
@ -443,7 +445,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testLoadDomain_withClientHold() { void testLoadDomain_withClientHold() {
persistResource( persistResource(
fakeDomain( fakeDomain(
@ -459,7 +461,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testLoadDomain_withServerHold() { void testLoadDomain_withServerHold() {
persistResource( persistResource(
fakeDomain( fakeDomain(
@ -476,7 +478,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testLoadDomain_withPendingDelete() { void testLoadDomain_withPendingDelete() {
persistResource( persistResource(
fakeDomain( fakeDomain(
@ -491,7 +493,7 @@ public class CloudDnsWriterTest {
verifyZone(ImmutableSet.of()); verifyZone(ImmutableSet.of());
} }
@Test @TestOfyAndSql
void testDuplicateRecords() { void testDuplicateRecords() {
// In publishing DNS records, we can end up publishing information on the same host twice // 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. // (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)); verifyZone(fakeDomainRecords("example.tld", 1, 0, 0, 0));
} }
@Test @TestOfyAndSql
void testInvalidZoneNames() { void testInvalidZoneNames() {
createTld("triple.secret.tld"); createTld("triple.secret.tld");
persistResource( persistResource(
@ -525,7 +527,7 @@ public class CloudDnsWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testEmptyCommit() { void testEmptyCommit() {
writer.commit(); writer.commit();
verify(dnsConnection, times(0)).changes(); 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.host.HostResource;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
import google.registry.testing.InjectExtension; import google.registry.testing.InjectExtension;
import google.registry.testing.TestOfyAndSql;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach; 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.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
@ -70,6 +71,7 @@ import org.xbill.DNS.Update;
/** Unit tests for {@link DnsUpdateWriter}. */ /** Unit tests for {@link DnsUpdateWriter}. */
@ExtendWith(MockitoExtension.class) @ExtendWith(MockitoExtension.class)
@DualDatabaseTest
public class DnsUpdateWriterTest { public class DnsUpdateWriterTest {
@RegisterExtension @RegisterExtension
@ -96,7 +98,7 @@ public class DnsUpdateWriterTest {
"tld", Duration.ZERO, Duration.ZERO, Duration.ZERO, mockResolver, clock); "tld", Duration.ZERO, Duration.ZERO, Duration.ZERO, mockResolver, clock);
} }
@Test @TestOfyAndSql
void testPublishDomainCreate_publishesNameServers() throws Exception { void testPublishDomainCreate_publishesNameServers() throws Exception {
HostResource host1 = persistActiveHost("ns1.example.tld"); HostResource host1 = persistActiveHost("ns1.example.tld");
HostResource host2 = persistActiveHost("ns2.example.tld"); HostResource host2 = persistActiveHost("ns2.example.tld");
@ -119,7 +121,7 @@ public class DnsUpdateWriterTest {
} }
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@Test @TestOfyAndSql
void testPublishAtomic_noCommit() { void testPublishAtomic_noCommit() {
HostResource host1 = persistActiveHost("ns.example1.tld"); HostResource host1 = persistActiveHost("ns.example1.tld");
DomainBase domain1 = DomainBase domain1 =
@ -143,7 +145,7 @@ public class DnsUpdateWriterTest {
verifyNoInteractions(mockResolver); verifyNoInteractions(mockResolver);
} }
@Test @TestOfyAndSql
void testPublishAtomic_oneUpdate() throws Exception { void testPublishAtomic_oneUpdate() throws Exception {
HostResource host1 = persistActiveHost("ns.example1.tld"); HostResource host1 = persistActiveHost("ns.example1.tld");
DomainBase domain1 = DomainBase domain1 =
@ -175,7 +177,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 4); // The delete and NS sets for each TLD assertThatTotalUpdateSetsIs(update, 4); // The delete and NS sets for each TLD
} }
@Test @TestOfyAndSql
void testPublishDomainCreate_publishesDelegationSigner() throws Exception { void testPublishDomainCreate_publishesDelegationSigner() throws Exception {
DomainBase domain = DomainBase domain =
persistActiveDomain("example.tld") persistActiveDomain("example.tld")
@ -199,7 +201,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 3); // The delete, the NS, and DS sets assertThatTotalUpdateSetsIs(update, 3); // The delete, the NS, and DS sets
} }
@Test @TestOfyAndSql
void testPublishDomainWhenNotActive_removesDnsRecords() throws Exception { void testPublishDomainWhenNotActive_removesDnsRecords() throws Exception {
DomainBase domain = DomainBase domain =
persistActiveDomain("example.tld") persistActiveDomain("example.tld")
@ -219,7 +221,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 1); // Just the delete set assertThatTotalUpdateSetsIs(update, 1); // Just the delete set
} }
@Test @TestOfyAndSql
void testPublishDomainDelete_removesDnsRecords() throws Exception { void testPublishDomainDelete_removesDnsRecords() throws Exception {
persistDeletedDomain("example.tld", clock.nowUtc().minusDays(1)); persistDeletedDomain("example.tld", clock.nowUtc().minusDays(1));
@ -233,7 +235,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 1); // Just the delete set assertThatTotalUpdateSetsIs(update, 1); // Just the delete set
} }
@Test @TestOfyAndSql
void testPublishHostCreate_publishesAddressRecords() throws Exception { void testPublishHostCreate_publishesAddressRecords() throws Exception {
HostResource host = HostResource host =
persistResource( persistResource(
@ -266,7 +268,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 5); assertThatTotalUpdateSetsIs(update, 5);
} }
@Test @TestOfyAndSql
void testPublishHostDelete_removesDnsRecords() throws Exception { void testPublishHostDelete_removesDnsRecords() throws Exception {
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1)); persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
persistActiveDomain("example.tld"); persistActiveDomain("example.tld");
@ -282,7 +284,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 2); // Just the delete set assertThatTotalUpdateSetsIs(update, 2); // Just the delete set
} }
@Test @TestOfyAndSql
void testPublishHostDelete_removesGlueRecords() throws Exception { void testPublishHostDelete_removesGlueRecords() throws Exception {
persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1)); persistDeletedHost("ns1.example.tld", clock.nowUtc().minusDays(1));
persistResource( persistResource(
@ -303,7 +305,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 3); assertThatTotalUpdateSetsIs(update, 3);
} }
@Test @TestOfyAndSql
void testPublishDomainExternalAndInBailiwickNameServer() throws Exception { void testPublishDomainExternalAndInBailiwickNameServer() throws Exception {
HostResource externalNameserver = persistResource(newHostResource("ns1.example.com")); HostResource externalNameserver = persistResource(newHostResource("ns1.example.com"));
HostResource inBailiwickNameserver = HostResource inBailiwickNameserver =
@ -340,7 +342,7 @@ public class DnsUpdateWriterTest {
assertThatTotalUpdateSetsIs(update, 5); assertThatTotalUpdateSetsIs(update, 5);
} }
@Test @TestOfyAndSql
void testPublishDomainDeleteOrphanGlues() throws Exception { void testPublishDomainDeleteOrphanGlues() throws Exception {
HostResource inBailiwickNameserver = HostResource inBailiwickNameserver =
persistResource( persistResource(
@ -378,7 +380,7 @@ public class DnsUpdateWriterTest {
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@SuppressWarnings("AssertThrowsMultipleStatements") @SuppressWarnings("AssertThrowsMultipleStatements")
@Test @TestOfyAndSql
void testPublishDomainFails_whenDnsUpdateReturnsError() throws Exception { void testPublishDomainFails_whenDnsUpdateReturnsError() throws Exception {
DomainBase domain = DomainBase domain =
persistActiveDomain("example.tld") persistActiveDomain("example.tld")
@ -399,7 +401,7 @@ public class DnsUpdateWriterTest {
@MockitoSettings(strictness = Strictness.LENIENT) @MockitoSettings(strictness = Strictness.LENIENT)
@SuppressWarnings("AssertThrowsMultipleStatements") @SuppressWarnings("AssertThrowsMultipleStatements")
@Test @TestOfyAndSql
void testPublishHostFails_whenDnsUpdateReturnsError() throws Exception { void testPublishHostFails_whenDnsUpdateReturnsError() throws Exception {
HostResource host = HostResource host =
persistActiveSubordinateHost("ns1.example.tld", persistActiveDomain("example.tld")) 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.io.BaseEncoding.base16;
import static com.google.common.truth.Truth.assertThat; 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.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.assertNoBillingEvents;
import static google.registry.testing.DatabaseHelper.createTld; import static google.registry.testing.DatabaseHelper.createTld;
import static google.registry.testing.DatabaseHelper.newDomainBase; 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.model.reporting.HistoryEntry;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.ReplayExtension; import google.registry.testing.ReplayExtension;
import google.registry.testing.SetClockExtension; import google.registry.testing.SetClockExtension;
import google.registry.testing.TestOfyAndSql;
import google.registry.testing.TestOfyOnly;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DomainInfoFlow}. */ /** Unit tests for {@link DomainInfoFlow}. */
@DualDatabaseTest
class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase> { class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase> {
@Order(value = Order.DEFAULT - 3) @Order(value = Order.DEFAULT - 3)
@ -201,87 +204,87 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest(expectedXmlFilename, true); doSuccessfulTest(expectedXmlFilename, true);
} }
@Test @TestOfyAndSql
void testSuccess_allHosts() throws Exception { void testSuccess_allHosts() throws Exception {
doSuccessfulTest("domain_info_response.xml"); doSuccessfulTest("domain_info_response.xml");
} }
@Test @TestOfyAndSql
void testSuccess_clTridNotSpecified() throws Exception { void testSuccess_clTridNotSpecified() throws Exception {
setEppInput("domain_info_no_cltrid.xml"); setEppInput("domain_info_no_cltrid.xml");
doSuccessfulTest("domain_info_response_no_cltrid.xml"); doSuccessfulTest("domain_info_response_no_cltrid.xml");
} }
@Test @TestOfyAndSql
void testSuccess_allHosts_noDelegatedHosts() throws Exception { void testSuccess_allHosts_noDelegatedHosts() throws Exception {
// There aren't any delegated hosts. // There aren't any delegated hosts.
doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml"); doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_defaultHosts() throws Exception { void testSuccess_defaultHosts() throws Exception {
setEppInput("domain_info_default_hosts.xml"); setEppInput("domain_info_default_hosts.xml");
doSuccessfulTest("domain_info_response.xml"); doSuccessfulTest("domain_info_response.xml");
} }
@Test @TestOfyAndSql
void testSuccess_defaultHosts_noDelegatedHosts() throws Exception { void testSuccess_defaultHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_default_hosts.xml"); setEppInput("domain_info_default_hosts.xml");
// There aren't any delegated hosts. // There aren't any delegated hosts.
doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml"); doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_delegatedHosts() throws Exception { void testSuccess_delegatedHosts() throws Exception {
setEppInput("domain_info_delegated_hosts.xml"); setEppInput("domain_info_delegated_hosts.xml");
doSuccessfulTest("domain_info_response_delegated_hosts.xml"); doSuccessfulTest("domain_info_response_delegated_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_delegatedHosts_noDelegatedHosts() throws Exception { void testSuccess_delegatedHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_delegated_hosts.xml"); setEppInput("domain_info_delegated_hosts.xml");
// There aren't any delegated hosts. // There aren't any delegated hosts.
doSuccessfulTestNoNameservers("domain_info_response_none_hosts.xml"); doSuccessfulTestNoNameservers("domain_info_response_none_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_subordinateHosts() throws Exception { void testSuccess_subordinateHosts() throws Exception {
setEppInput("domain_info_subordinate_hosts.xml"); setEppInput("domain_info_subordinate_hosts.xml");
doSuccessfulTest("domain_info_response_subordinate_hosts.xml"); doSuccessfulTest("domain_info_response_subordinate_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_subordinateHosts_noDelegatedHosts() throws Exception { void testSuccess_subordinateHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_subordinate_hosts.xml"); setEppInput("domain_info_subordinate_hosts.xml");
doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml"); doSuccessfulTestNoNameservers("domain_info_response_subordinate_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_noneHosts() throws Exception { void testSuccess_noneHosts() throws Exception {
setEppInput("domain_info_none_hosts.xml"); setEppInput("domain_info_none_hosts.xml");
doSuccessfulTest("domain_info_response_none_hosts.xml"); doSuccessfulTest("domain_info_response_none_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_noneHosts_noDelegatedHosts() throws Exception { void testSuccess_noneHosts_noDelegatedHosts() throws Exception {
setEppInput("domain_info_none_hosts.xml"); setEppInput("domain_info_none_hosts.xml");
doSuccessfulTestNoNameservers("domain_info_response_none_hosts.xml"); doSuccessfulTestNoNameservers("domain_info_response_none_hosts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_unauthorized() throws Exception { void testSuccess_unauthorized() throws Exception {
sessionMetadata.setClientId("ClientZ"); sessionMetadata.setClientId("ClientZ");
doSuccessfulTest("domain_info_response_unauthorized.xml"); doSuccessfulTest("domain_info_response_unauthorized.xml");
} }
@Test @TestOfyAndSql
void testSuccess_differentRegistrarWithAuthInfo() throws Exception { void testSuccess_differentRegistrarWithAuthInfo() throws Exception {
setEppInput("domain_info_with_auth.xml"); setEppInput("domain_info_with_auth.xml");
sessionMetadata.setClientId("ClientZ"); sessionMetadata.setClientId("ClientZ");
doSuccessfulTest("domain_info_response.xml"); doSuccessfulTest("domain_info_response.xml");
} }
@Test @TestOfyAndSql
void testSuccess_differentRegistrarWithRegistrantAuthInfo() throws Exception { void testSuccess_differentRegistrarWithRegistrantAuthInfo() throws Exception {
persistTestEntities(false); persistTestEntities(false);
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
@ -290,7 +293,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response.xml", false); doSuccessfulTest("domain_info_response.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_differentRegistrarWithContactAuthInfo() throws Exception { void testSuccess_differentRegistrarWithContactAuthInfo() throws Exception {
persistTestEntities(false); persistTestEntities(false);
setEppInput("domain_info_with_contact_auth.xml"); setEppInput("domain_info_with_contact_auth.xml");
@ -299,7 +302,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response.xml", false); doSuccessfulTest("domain_info_response.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_inQuietPeriod() throws Exception { void testSuccess_inQuietPeriod() throws Exception {
persistResource( persistResource(
Registry.get("tld") Registry.get("tld")
@ -309,7 +312,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response.xml"); doSuccessfulTest("domain_info_response.xml");
} }
@Test @TestOfyAndSql
void testSuccess_secDns() throws Exception { void testSuccess_secDns() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Add the dsData to the saved resource and change the nameservers to match the sample xml. // 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); doSuccessfulTest("domain_info_response_addperiod.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_addGracePeriod() throws Exception { void testSuccess_addGracePeriod() throws Exception {
doAddPeriodTest(GracePeriodStatus.ADD); doAddPeriodTest(GracePeriodStatus.ADD);
} }
@Test @TestOfyAndSql
void testSuccess_autoRenewGracePeriod() throws Exception { void testSuccess_autoRenewGracePeriod() throws Exception {
persistTestEntities(false); persistTestEntities(false);
HistoryEntry historyEntry = HistoryEntry historyEntry =
@ -391,7 +394,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_response_autorenewperiod.xml", false, ImmutableMap.of(), true); doSuccessfulTest("domain_info_response_autorenewperiod.xml", false, ImmutableMap.of(), true);
} }
@Test @TestOfyAndSql
void testSuccess_redemptionGracePeriod() throws Exception { void testSuccess_redemptionGracePeriod() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Add an REDEMPTION grace period to the saved resource, and change a few other fields to match // 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); doSuccessfulTest("domain_info_response_redemptionperiod.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_renewGracePeriod() throws Exception { void testSuccess_renewGracePeriod() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Add an RENEW grace period to the saved resource. // 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); doSuccessfulTest("domain_info_response_renewperiod.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_multipleRenewGracePeriods() throws Exception { void testSuccess_multipleRenewGracePeriods() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Add multiple RENEW grace periods to the saved resource. // 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); doSuccessfulTest("domain_info_response_renewperiod.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_transferGracePeriod() throws Exception { void testSuccess_transferGracePeriod() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Add an TRANSFER grace period to the saved resource. // 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); doSuccessfulTest("domain_info_response_transferperiod.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_pendingDelete() throws Exception { void testSuccess_pendingDelete() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Set the domain to be pending delete with no grace period, which will cause an RGP status of // 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); doSuccessfulTest("domain_info_response_pendingdelete.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_stackedAddRenewGracePeriods() throws Exception { void testSuccess_stackedAddRenewGracePeriods() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Add both an ADD and RENEW grace period, both which should show up in the RGP status. // 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); doSuccessfulTest("domain_info_response_stackedaddrenewperiod.xml", false);
} }
@Test @TestOfyAndSql
void testSuccess_secDnsAndAddGracePeriod() throws Exception { void testSuccess_secDnsAndAddGracePeriod() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Add both an ADD grace period and SecDNS data. // 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); doSuccessfulTest("domain_info_response_dsdata_addperiod.xml", false);
} }
@Test @TestOfyAndSql
void testFailure_neverExisted() throws Exception { void testFailure_neverExisted() throws Exception {
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
assertThrows(ResourceDoesNotExistException.class, this::runFlow); assertThrows(ResourceDoesNotExistException.class, this::runFlow);
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @TestOfyAndSql
void testFailure_existedButWasDeleted() throws Exception { void testFailure_existedButWasDeleted() throws Exception {
persistResource( persistResource(
newDomainBase("example.tld") newDomainBase("example.tld")
@ -548,7 +551,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @TestOfyAndSql
void testFailure_differentRegistrarWrongAuthInfo() { void testFailure_differentRegistrarWrongAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
// Change the password of the domain so that it does not match the file. // 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(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_wrongAuthInfo() { void testFailure_wrongAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
// Change the password of the domain so that it does not match the file. // 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(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_differentRegistrarWrongRegistrantAuthInfo() { void testFailure_differentRegistrarWrongRegistrantAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
// Change the password of the registrant so that it does not match the file. // 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(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_wrongRegistrantAuthInfo() { void testFailure_wrongRegistrantAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
// Change the password of the registrant so that it does not match the file. // 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(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_differentRegistrarWrongContactAuthInfo() { void testFailure_differentRegistrarWrongContactAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
// Change the password of the contact so that it does not match the file. // 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(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_wrongContactAuthInfo() { void testFailure_wrongContactAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
// Change the password of the contact so that it does not match the file. // 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(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_differentRegistrarUnrelatedContactAuthInfo() { void testFailure_differentRegistrarUnrelatedContactAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
ContactResource unrelatedContact = persistActiveContact("foo1234"); ContactResource unrelatedContact = persistActiveContact("foo1234");
@ -659,7 +662,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_unrelatedContactAuthInfo() { void testFailure_unrelatedContactAuthInfo() {
persistTestEntities(false); persistTestEntities(false);
ContactResource unrelatedContact = persistActiveContact("foo1234"); 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 * 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. * info commands and responses, so we don't need to test the other versions.
*/ */
@Test @TestOfyAndSql
void testFeeExtension_createCommand() throws Exception { void testFeeExtension_createCommand() throws Exception {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -694,7 +697,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test renew command. */ /** Test renew command. */
@Test @TestOfyAndSql
void testFeeExtension_renewCommand() throws Exception { void testFeeExtension_renewCommand() throws Exception {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -714,7 +717,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test transfer command. */ /** Test transfer command. */
@Test @TestOfyAndSql
void testFeeExtension_transferCommand() throws Exception { void testFeeExtension_transferCommand() throws Exception {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -734,7 +737,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test restore command. */ /** Test restore command. */
@Test @TestOfyAndSql
void testFeeExtension_restoreCommand() throws Exception { void testFeeExtension_restoreCommand() throws Exception {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -746,7 +749,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_fee_restore_response.xml", false); doSuccessfulTest("domain_info_fee_restore_response.xml", false);
} }
@Test @TestOfyAndSql
void testFeeExtension_restoreCommand_pendingDelete_noRenewal() throws Exception { void testFeeExtension_restoreCommand_pendingDelete_noRenewal() throws Exception {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -761,7 +764,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
doSuccessfulTest("domain_info_fee_restore_response_no_renewal.xml", false); doSuccessfulTest("domain_info_fee_restore_response_no_renewal.xml", false);
} }
@Test @TestOfyAndSql
void testFeeExtension_restoreCommand_pendingDelete_withRenewal() throws Exception { void testFeeExtension_restoreCommand_pendingDelete_withRenewal() throws Exception {
createTld("example"); createTld("example");
setEppInput( setEppInput(
@ -780,7 +783,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test create command on a premium label. */ /** Test create command on a premium label. */
@Test @TestOfyAndSql
void testFeeExtension_createCommandPremium() throws Exception { void testFeeExtension_createCommandPremium() throws Exception {
createTld("example"); createTld("example");
setEppInput( setEppInput(
@ -798,7 +801,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test renew command on a premium label. */ /** Test renew command on a premium label. */
@Test @TestOfyAndSql
void testFeeExtension_renewCommandPremium() throws Exception { void testFeeExtension_renewCommandPremium() throws Exception {
createTld("example"); createTld("example");
setEppInput( setEppInput(
@ -816,7 +819,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test transfer command on a premium label. */ /** Test transfer command on a premium label. */
@Test @TestOfyAndSql
void testFeeExtension_transferCommandPremium() throws Exception { void testFeeExtension_transferCommandPremium() throws Exception {
createTld("example"); createTld("example");
setEppInput( setEppInput(
@ -834,7 +837,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test restore command on a premium label. */ /** Test restore command on a premium label. */
@Test @TestOfyAndSql
void testFeeExtension_restoreCommandPremium() throws Exception { void testFeeExtension_restoreCommandPremium() throws Exception {
createTld("example"); createTld("example");
setEppInput( setEppInput(
@ -849,7 +852,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test setting the currency explicitly to a wrong value. */ /** Test setting the currency explicitly to a wrong value. */
@Test @TestOfyAndSql
void testFeeExtension_wrongCurrency() { void testFeeExtension_wrongCurrency() {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -863,7 +866,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFeeExtension_unknownCurrency() { void testFeeExtension_unknownCurrency() {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -877,7 +880,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test requesting a period that isn't in years. */ /** Test requesting a period that isn't in years. */
@Test @TestOfyAndSql
void testFeeExtension_periodNotInYears() { void testFeeExtension_periodNotInYears() {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -892,7 +895,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test a command that specifies a phase. */ /** Test a command that specifies a phase. */
@Test @TestOfyAndSql
void testFeeExtension_commandPhase() { void testFeeExtension_commandPhase() {
setEppInput("domain_info_fee_command_phase.xml"); setEppInput("domain_info_fee_command_phase.xml");
persistTestEntities(false); persistTestEntities(false);
@ -901,7 +904,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test a command that specifies a subphase. */ /** Test a command that specifies a subphase. */
@Test @TestOfyAndSql
void testFeeExtension_commandSubphase() { void testFeeExtension_commandSubphase() {
setEppInput("domain_info_fee_command_subphase.xml"); setEppInput("domain_info_fee_command_subphase.xml");
persistTestEntities(false); persistTestEntities(false);
@ -910,7 +913,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test a restore for more than one year. */ /** Test a restore for more than one year. */
@Test @TestOfyAndSql
void testFeeExtension_multiyearRestore() { void testFeeExtension_multiyearRestore() {
setEppInput( setEppInput(
"domain_info_fee.xml", "domain_info_fee.xml",
@ -924,7 +927,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
} }
/** Test a transfer for more than one year. */ /** Test a transfer for more than one year. */
@Test @TestOfyAndSql
void testFeeExtension_multiyearTransfer() { void testFeeExtension_multiyearTransfer() {
setEppInput( setEppInput(
"domain_info_fee.xml", "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 that we load contacts and hosts as a batch rather than individually. */
@Test @TestOfyOnly // batching only relevant for Datastore
void testBatchLoadingOfReferences() throws Exception { void testBatchLoadingOfReferences() throws Exception {
persistTestEntities(false); persistTestEntities(false);
// Clear out the session cache so that we count actual Datastore calls. // Clear out the session cache so that we count actual Datastore calls.
ofy().clearSessionCache(); tm().clearSessionCache();
int numPreviousReads = RequestCapturingAsyncDatastoreService.getReads().size(); int numPreviousReads = RequestCapturingAsyncDatastoreService.getReads().size();
doSuccessfulTest("domain_info_response.xml", false); 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. // 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); assertThat(numReadsWithContactsOrHosts).isEqualTo(2);
} }
@Test @TestOfyAndSql
void testIcannActivityReportField_getsLogged() throws Exception { void testIcannActivityReportField_getsLogged() throws Exception {
persistTestEntities(false); persistTestEntities(false);
runFlow(); runFlow();

View file

@ -45,24 +45,27 @@ import google.registry.flows.exceptions.NotTransferInitiatorException;
import google.registry.model.contact.ContactAuthInfo; import google.registry.model.contact.ContactAuthInfo;
import google.registry.model.domain.DomainAuthInfo; import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.eppcommon.AuthInfo.PasswordAuth; import google.registry.model.eppcommon.AuthInfo.PasswordAuth;
import google.registry.model.poll.PollMessage; import google.registry.model.poll.PollMessage;
import google.registry.model.registry.Registry; import google.registry.model.registry.Registry;
import google.registry.model.reporting.DomainTransactionRecord; import google.registry.model.reporting.DomainTransactionRecord;
import google.registry.model.reporting.HistoryEntry; 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.TransferResponse.DomainTransferResponse;
import google.registry.model.transfer.TransferStatus; import google.registry.model.transfer.TransferStatus;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.ReplayExtension; import google.registry.testing.ReplayExtension;
import google.registry.testing.TestOfyAndSql;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.Duration; import org.joda.time.Duration;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link DomainTransferCancelFlow}. */ /** Unit tests for {@link DomainTransferCancelFlow}. */
@DualDatabaseTest
class DomainTransferCancelFlowTest class DomainTransferCancelFlowTest
extends DomainTransferFlowTestCase<DomainTransferCancelFlow, DomainBase> { extends DomainTransferFlowTestCase<DomainTransferCancelFlow, DomainBase> {
@ -77,8 +80,7 @@ class DomainTransferCancelFlowTest
setupDomainWithPendingTransfer("example", "tld"); setupDomainWithPendingTransfer("example", "tld");
} }
private void doSuccessfulTest(String commandFilename, String expectedXmlFilename) private void doSuccessfulTest(String commandFilename) throws Exception {
throws Exception {
setEppInput(commandFilename); setEppInput(commandFilename);
// Replace the ROID in the xml file with the one generated in our test. // Replace the ROID in the xml file with the one generated in our test.
@ -125,8 +127,8 @@ class DomainTransferCancelFlowTest
assertTransactionalFlow(true); assertTransactionalFlow(true);
DateTime originalExpirationTime = domain.getRegistrationExpirationTime(); DateTime originalExpirationTime = domain.getRegistrationExpirationTime();
ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods(); ImmutableSet<GracePeriod> originalGracePeriods = domain.getGracePeriods();
TransferData originalTransferData = domain.getTransferData(); DomainTransferData originalTransferData = domain.getTransferData();
runFlowAssertResponse(loadFile(expectedXmlFilename)); runFlowAssertResponse(loadFile("domain_transfer_cancel_response.xml"));
// Transfer should have been cancelled. Verify correct fields were set. // Transfer should have been cancelled. Verify correct fields were set.
domain = reloadResourceByForeignKey(); domain = reloadResourceByForeignKey();
@ -199,31 +201,29 @@ class DomainTransferCancelFlowTest
runFlow(); runFlow();
} }
@Test @TestOfyAndSql
void testDryRun() throws Exception { void testDryRun() throws Exception {
setEppInput("domain_transfer_cancel.xml"); setEppInput("domain_transfer_cancel.xml");
eppLoader.replaceAll("JD1234-REP", contact.getRepoId()); eppLoader.replaceAll("JD1234-REP", contact.getRepoId());
dryRunFlowAssertResponse(loadFile("domain_transfer_cancel_response.xml")); dryRunFlowAssertResponse(loadFile("domain_transfer_cancel_response.xml"));
} }
@Test @TestOfyAndSql
void testSuccess() throws Exception { 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 { void testSuccess_domainAuthInfo() throws Exception {
doSuccessfulTest( doSuccessfulTest("domain_transfer_cancel_domain_authinfo.xml");
"domain_transfer_cancel_domain_authinfo.xml", "domain_transfer_cancel_response.xml");
} }
@Test @TestOfyAndSql
void testSuccess_contactAuthInfo() throws Exception { void testSuccess_contactAuthInfo() throws Exception {
doSuccessfulTest( doSuccessfulTest("domain_transfer_cancel_contact_authinfo.xml");
"domain_transfer_cancel_contact_authinfo.xml", "domain_transfer_cancel_response.xml");
} }
@Test @TestOfyAndSql
void testFailure_badContactPassword() { void testFailure_badContactPassword() {
// Change the contact's password so it does not match the password in the file. // Change the contact's password so it does not match the password in the file.
contact = contact =
@ -239,7 +239,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_badDomainPassword() { void testFailure_badDomainPassword() {
// Change the domain's password so it does not match the password in the file. // Change the domain's password so it does not match the password in the file.
domain = domain =
@ -255,7 +255,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_neverBeenTransferred() { void testFailure_neverBeenTransferred() {
changeTransferStatus(null); changeTransferStatus(null);
EppException thrown = EppException thrown =
@ -264,7 +264,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_clientApproved() { void testFailure_clientApproved() {
changeTransferStatus(TransferStatus.CLIENT_APPROVED); changeTransferStatus(TransferStatus.CLIENT_APPROVED);
EppException thrown = EppException thrown =
@ -273,7 +273,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_clientRejected() { void testFailure_clientRejected() {
changeTransferStatus(TransferStatus.CLIENT_REJECTED); changeTransferStatus(TransferStatus.CLIENT_REJECTED);
EppException thrown = EppException thrown =
@ -282,7 +282,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_clientCancelled() { void testFailure_clientCancelled() {
changeTransferStatus(TransferStatus.CLIENT_CANCELLED); changeTransferStatus(TransferStatus.CLIENT_CANCELLED);
EppException thrown = EppException thrown =
@ -291,7 +291,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_serverApproved() { void testFailure_serverApproved() {
changeTransferStatus(TransferStatus.SERVER_APPROVED); changeTransferStatus(TransferStatus.SERVER_APPROVED);
EppException thrown = EppException thrown =
@ -300,7 +300,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_serverCancelled() { void testFailure_serverCancelled() {
changeTransferStatus(TransferStatus.SERVER_CANCELLED); changeTransferStatus(TransferStatus.SERVER_CANCELLED);
EppException thrown = EppException thrown =
@ -309,7 +309,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_sponsoringClient() { void testFailure_sponsoringClient() {
setClientIdForFlow("TheRegistrar"); setClientIdForFlow("TheRegistrar");
EppException thrown = EppException thrown =
@ -318,7 +318,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_unrelatedClient() { void testFailure_unrelatedClient() {
setClientIdForFlow("ClientZ"); setClientIdForFlow("ClientZ");
EppException thrown = EppException thrown =
@ -327,7 +327,7 @@ class DomainTransferCancelFlowTest
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testFailure_deletedDomain() throws Exception { void testFailure_deletedDomain() throws Exception {
domain = domain =
persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build()); persistResource(domain.asBuilder().setDeletionTime(clock.nowUtc().minusDays(1)).build());
@ -337,7 +337,7 @@ class DomainTransferCancelFlowTest
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @TestOfyAndSql
void testFailure_nonexistentDomain() throws Exception { void testFailure_nonexistentDomain() throws Exception {
deleteTestDomain(domain, clock.nowUtc()); deleteTestDomain(domain, clock.nowUtc());
ResourceDoesNotExistException thrown = ResourceDoesNotExistException thrown =
@ -346,20 +346,18 @@ class DomainTransferCancelFlowTest
assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand())); assertThat(thrown).hasMessageThat().contains(String.format("(%s)", getUniqueIdFromCommand()));
} }
@Test @TestOfyAndSql
void testFailure_notAuthorizedForTld() { void testFailure_notAuthorizedForTld() {
persistResource( persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build());
EppException thrown = EppException thrown =
assertThrows( assertThrows(
NotAuthorizedForTldException.class, NotAuthorizedForTldException.class,
() -> () -> doSuccessfulTest("domain_transfer_cancel.xml"));
doSuccessfulTest(
"domain_transfer_cancel.xml", "domain_transfer_cancel_response.xml"));
assertAboutEppExceptions().that(thrown).marshalsToXml(); assertAboutEppExceptions().that(thrown).marshalsToXml();
} }
@Test @TestOfyAndSql
void testSuccess_superuserNotAuthorizedForTld() throws Exception { void testSuccess_superuserNotAuthorizedForTld() throws Exception {
persistResource( persistResource(
loadRegistrar("NewRegistrar").asBuilder().setAllowedTlds(ImmutableSet.of()).build()); 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 // 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. // entering pending delete phase. So it's already handled in that test case.
@Test @TestOfyAndSql
void testIcannActivityReportField_getsLogged() throws Exception { void testIcannActivityReportField_getsLogged() throws Exception {
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlow(); runFlow();
@ -379,7 +377,7 @@ class DomainTransferCancelFlowTest
assertTldsFieldLogged("tld"); assertTldsFieldLogged("tld");
} }
@Test @TestOfyAndSql
void testIcannTransactionRecord_noRecordsToCancel() throws Exception { void testIcannTransactionRecord_noRecordsToCancel() throws Exception {
clock.advanceOneMilli(); clock.advanceOneMilli();
runFlow(); runFlow();
@ -388,7 +386,7 @@ class DomainTransferCancelFlowTest
assertThat(persistedEntry.getDomainTransactionRecords()).isEmpty(); assertThat(persistedEntry.getDomainTransactionRecords()).isEmpty();
} }
@Test @TestOfyAndSql
void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception { void testIcannTransactionRecord_cancelsPreviousRecords() throws Exception {
clock.advanceOneMilli(); clock.advanceOneMilli();
persistResource( persistResource(
@ -403,7 +401,7 @@ class DomainTransferCancelFlowTest
DomainTransactionRecord notCancellableRecord = DomainTransactionRecord notCancellableRecord =
DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), RESTORED_DOMAINS, 5); DomainTransactionRecord.create("tld", clock.nowUtc().plusDays(1), RESTORED_DOMAINS, 5);
persistResource( persistResource(
new HistoryEntry.Builder() new DomainHistory.Builder()
.setType(DOMAIN_TRANSFER_REQUEST) .setType(DOMAIN_TRANSFER_REQUEST)
.setParent(domain) .setParent(domain)
.setModificationTime(clock.nowUtc().minusDays(4)) .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.DesignatedContact;
import google.registry.model.domain.DomainAuthInfo; import google.registry.model.domain.DomainAuthInfo;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.domain.rgp.GracePeriodStatus; import google.registry.model.domain.rgp.GracePeriodStatus;
import google.registry.model.domain.secdns.DelegationSignerData; 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.DomainTransferData;
import google.registry.model.transfer.TransferStatus; import google.registry.model.transfer.TransferStatus;
import google.registry.testing.AppEngineExtension; import google.registry.testing.AppEngineExtension;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
import google.registry.testing.TestOfyAndSql;
import google.registry.util.Idn; import google.registry.util.Idn;
import google.registry.xjc.domain.XjcDomainStatusType; import google.registry.xjc.domain.XjcDomainStatusType;
import google.registry.xjc.domain.XjcDomainStatusValueType; import google.registry.xjc.domain.XjcDomainStatusValueType;
@ -71,7 +74,6 @@ import java.io.ByteArrayOutputStream;
import org.joda.money.Money; import org.joda.money.Money;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; 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 * <p>This tests the mapping between {@link DomainBase} and {@link XjcRdeDomain} as well as some
* exceptional conditions. * exceptional conditions.
*/ */
@DualDatabaseTest
public class DomainBaseToXjcConverterTest { public class DomainBaseToXjcConverterTest {
@RegisterExtension @RegisterExtension
@ -94,11 +97,11 @@ public class DomainBaseToXjcConverterTest {
createTld("xn--q9jyb4c"); createTld("xn--q9jyb4c");
} }
@Test @TestOfyAndSql
void testConvertThick() { void testConvertThick() {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.FULL); XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.FULL);
assertThat(bean.getClID()).isEqualTo("GetTheeBack"); assertThat(bean.getClID()).isEqualTo("TheRegistrar");
assertThat( assertThat(
bean.getContacts().stream() bean.getContacts().stream()
@ -111,7 +114,7 @@ public class DomainBaseToXjcConverterTest {
// that created the domain name object. An OPTIONAL client attribute // that created the domain name object. An OPTIONAL client attribute
// is used to specify the client that performed the operation. // 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. // 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.getCrRr().getClient()).isNull();
assertThat(bean.getExDate()).isEqualTo(DateTime.parse("1930-01-01T00:00:00Z")); 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.getTrDate()).isEqualTo(DateTime.parse("1910-01-01T00:00:00Z"));
assertThat(bean.getTrnData().getTrStatus().toString()).isEqualTo("PENDING"); assertThat(bean.getTrnData().getTrStatus().toString()).isEqualTo("PENDING");
assertThat(bean.getTrnData().getReRr().getValue()).isEqualTo("gaining"); assertThat(bean.getTrnData().getReRr().getValue()).isEqualTo("NewRegistrar");
assertThat(bean.getTrnData().getAcRr().getValue()).isEqualTo("losing"); assertThat(bean.getTrnData().getAcRr().getValue()).isEqualTo("TheRegistrar");
assertThat(bean.getTrnData().getAcDate()).isEqualTo(DateTime.parse("1925-04-20T00:00:00Z")); 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().getReDate()).isEqualTo(DateTime.parse("1919-01-01T00:00:00Z"));
assertThat(bean.getTrnData().getExDate()).isEqualTo(DateTime.parse("1931-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.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(); assertThat(bean.getUpRr().getClient()).isNull();
} }
@Test @TestOfyAndSql
void testConvertThin() { void testConvertThin() {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.THIN); XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.THIN);
assertThat(bean.getRegistrant()).isNull(); assertThat(bean.getRegistrant()).isNull();
@ -183,13 +186,13 @@ public class DomainBaseToXjcConverterTest {
assertThat(bean.getSecDNS()).isNull(); assertThat(bean.getSecDNS()).isNull();
} }
@Test @TestOfyAndSql
void testMarshalThick() throws Exception { void testMarshalThick() throws Exception {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.FULL); XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.FULL);
wrapDeposit(bean).marshal(new ByteArrayOutputStream(), UTF_8); wrapDeposit(bean).marshal(new ByteArrayOutputStream(), UTF_8);
} }
@Test @TestOfyAndSql
void testMarshalThin() throws Exception { void testMarshalThin() throws Exception {
XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.THIN); XjcRdeDomain bean = DomainBaseToXjcConverter.convertDomain(makeDomainBase(clock), RdeMode.THIN);
wrapDeposit(bean).marshal(new ByteArrayOutputStream(), UTF_8); wrapDeposit(bean).marshal(new ByteArrayOutputStream(), UTF_8);
@ -214,9 +217,15 @@ public class DomainBaseToXjcConverterTest {
static DomainBase makeDomainBase(FakeClock clock) { static DomainBase makeDomainBase(FakeClock clock) {
DomainBase domain = DomainBase domain =
newDomainBase("example.xn--q9jyb4c").asBuilder().setRepoId("2-Q9JYB4C").build(); persistResource(
HistoryEntry historyEntry = newDomainBase("example.xn--q9jyb4c").asBuilder().setRepoId("2-Q9JYB4C").build());
persistResource(new HistoryEntry.Builder().setParent(domain).build()); DomainHistory domainHistory =
persistResource(
new DomainHistory.Builder()
.setModificationTime(clock.nowUtc())
.setType(HistoryEntry.Type.DOMAIN_CREATE)
.setParent(domain)
.build());
BillingEvent.OneTime billingEvent = BillingEvent.OneTime billingEvent =
persistResource( persistResource(
new BillingEvent.OneTime.Builder() new BillingEvent.OneTime.Builder()
@ -227,7 +236,7 @@ public class DomainBaseToXjcConverterTest {
.setPeriodYears(2) .setPeriodYears(2)
.setEventTime(DateTime.parse("1910-01-01T00:00:00Z")) .setEventTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setBillingTime(DateTime.parse("1910-01-01T00:00:00Z")) .setBillingTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setParent(historyEntry) .setParent(domainHistory)
.build()); .build());
domain = domain =
domain domain
@ -253,15 +262,15 @@ public class DomainBaseToXjcConverterTest {
"bird or fiend!? i shrieked upstarting", "bird or fiend!? i shrieked upstarting",
"bog@cat.みんな") "bog@cat.みんな")
.createVKey()))) .createVKey())))
.setCreationClientId("LawyerCat") .setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("GetTheeBack") .setPersistedCurrentSponsorClientId("TheRegistrar")
.setDsData( .setDsData(
ImmutableSet.of( ImmutableSet.of(
DelegationSignerData.create(123, 200, 230, base16().decode("1234567890")))) DelegationSignerData.create(123, 200, 230, base16().decode("1234567890"))))
.setDomainName(Idn.toASCII("love.みんな")) .setDomainName(Idn.toASCII("love.みんな"))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("IntoTheTempest") .setLastEppUpdateClientId("TheRegistrar")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setNameservers( .setNameservers(
ImmutableSet.of( ImmutableSet.of(
@ -288,13 +297,13 @@ public class DomainBaseToXjcConverterTest {
.setPeriodYears(2) .setPeriodYears(2)
.setEventTime(DateTime.parse("1920-01-01T00:00:00Z")) .setEventTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setBillingTime(DateTime.parse("1920-01-01T00:00:00Z")) .setBillingTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setParent(historyEntry) .setParent(domainHistory)
.build())), .build())),
GracePeriod.create( GracePeriod.create(
GracePeriodStatus.TRANSFER, GracePeriodStatus.TRANSFER,
domain.getRepoId(), domain.getRepoId(),
DateTime.parse("1920-01-01T00:00:00Z"), DateTime.parse("1920-01-01T00:00:00Z"),
"foo", "TheRegistrar",
null))) null)))
.setSubordinateHosts(ImmutableSet.of("home.by.horror.haunted")) .setSubordinateHosts(ImmutableSet.of("home.by.horror.haunted"))
.setStatusValues( .setStatusValues(
@ -312,7 +321,7 @@ public class DomainBaseToXjcConverterTest {
.setClientId("TheRegistrar") .setClientId("TheRegistrar")
.setEventTime(END_OF_TIME) .setEventTime(END_OF_TIME)
.setRecurrenceEndTime(END_OF_TIME) .setRecurrenceEndTime(END_OF_TIME)
.setParent(historyEntry) .setParent(domainHistory)
.build()) .build())
.createVKey()) .createVKey())
.setAutorenewPollMessage( .setAutorenewPollMessage(
@ -323,13 +332,13 @@ public class DomainBaseToXjcConverterTest {
.setEventTime(END_OF_TIME) .setEventTime(END_OF_TIME)
.setAutorenewEndTime(END_OF_TIME) .setAutorenewEndTime(END_OF_TIME)
.setMsg("Domain was auto-renewed.") .setMsg("Domain was auto-renewed.")
.setParent(historyEntry) .setParent(domainHistory)
.build()) .build())
.createVKey()) .createVKey())
.setTransferData( .setTransferData(
new DomainTransferData.Builder() new DomainTransferData.Builder()
.setGainingClientId("gaining") .setGainingClientId("NewRegistrar")
.setLosingClientId("losing") .setLosingClientId("TheRegistrar")
.setPendingTransferExpirationTime(DateTime.parse("1925-04-20T00:00:00Z")) .setPendingTransferExpirationTime(DateTime.parse("1925-04-20T00:00:00Z"))
.setServerApproveBillingEvent(billingEvent.createVKey()) .setServerApproveBillingEvent(billingEvent.createVKey())
.setServerApproveAutorenewEvent( .setServerApproveAutorenewEvent(
@ -341,7 +350,7 @@ public class DomainBaseToXjcConverterTest {
.setClientId("TheRegistrar") .setClientId("TheRegistrar")
.setEventTime(END_OF_TIME) .setEventTime(END_OF_TIME)
.setRecurrenceEndTime(END_OF_TIME) .setRecurrenceEndTime(END_OF_TIME)
.setParent(historyEntry) .setParent(domainHistory)
.build()) .build())
.createVKey()) .createVKey())
.setServerApproveAutorenewPollMessage( .setServerApproveAutorenewPollMessage(
@ -352,7 +361,7 @@ public class DomainBaseToXjcConverterTest {
.setEventTime(END_OF_TIME) .setEventTime(END_OF_TIME)
.setAutorenewEndTime(END_OF_TIME) .setAutorenewEndTime(END_OF_TIME)
.setMsg("Domain was auto-renewed.") .setMsg("Domain was auto-renewed.")
.setParent(historyEntry) .setParent(domainHistory)
.build()) .build())
.createVKey()) .createVKey())
.setServerApproveEntities(ImmutableSet.of(billingEvent.createVKey())) .setServerApproveEntities(ImmutableSet.of(billingEvent.createVKey()))
@ -374,8 +383,8 @@ public class DomainBaseToXjcConverterTest {
new ContactResource.Builder() new ContactResource.Builder()
.setContactId(id) .setContactId(id)
.setEmailAddress(email) .setEmailAddress(email)
.setPersistedCurrentSponsorClientId("GetTheeBack") .setPersistedCurrentSponsorClientId("TheRegistrar")
.setCreationClientId("GetTheeBack") .setCreationClientId("TheRegistrar")
.setCreationTimeForTest(END_OF_TIME) .setCreationTimeForTest(END_OF_TIME)
.setInternationalizedPostalInfo( .setInternationalizedPostalInfo(
new PostalInfo.Builder() new PostalInfo.Builder()
@ -403,13 +412,13 @@ public class DomainBaseToXjcConverterTest {
clock.advanceOneMilli(); clock.advanceOneMilli();
return persistEppResource( return persistEppResource(
new HostResource.Builder() new HostResource.Builder()
.setCreationClientId("LawyerCat") .setCreationClientId("TheRegistrar")
.setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z")) .setCreationTimeForTest(DateTime.parse("1900-01-01T00:00:00Z"))
.setPersistedCurrentSponsorClientId("BusinessCat") .setPersistedCurrentSponsorClientId("TheRegistrar")
.setHostName(Idn.toASCII(fqhn)) .setHostName(Idn.toASCII(fqhn))
.setInetAddresses(ImmutableSet.of(InetAddresses.forString(ip))) .setInetAddresses(ImmutableSet.of(InetAddresses.forString(ip)))
.setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z")) .setLastTransferTime(DateTime.parse("1910-01-01T00:00:00Z"))
.setLastEppUpdateClientId("CeilingCat") .setLastEppUpdateClientId("TheRegistrar")
.setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z")) .setLastEppUpdateTime(DateTime.parse("1920-01-01T00:00:00Z"))
.setRepoId(repoId) .setRepoId(repoId)
.setStatusValues(ImmutableSet.of(StatusValue.OK)) .setStatusValues(ImmutableSet.of(StatusValue.OK))

View file

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

View file

@ -36,7 +36,9 @@ import google.registry.model.domain.DomainBase;
import google.registry.model.domain.secdns.DelegationSignerData; import google.registry.model.domain.secdns.DelegationSignerData;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.FakeClock; import google.registry.testing.FakeClock;
import google.registry.testing.TestOfyAndSql;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import java.nio.file.Files; import java.nio.file.Files;
@ -46,9 +48,9 @@ import org.joda.time.DateTime;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link GenerateDnsReportCommand}. */ /** Unit tests for {@link GenerateDnsReportCommand}. */
@DualDatabaseTest
class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportCommand> { class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportCommand> {
private final DateTime now = DateTime.now(UTC); private final DateTime now = DateTime.now(UTC);
@ -158,7 +160,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
persistActiveDomain("should-be-ignored.example"); persistActiveDomain("should-be-ignored.example");
} }
@Test @TestOfyAndSql
void testSuccess() throws Exception { void testSuccess() throws Exception {
runCommand("--output=" + output, "--tld=xn--q9jyb4c"); runCommand("--output=" + output, "--tld=xn--q9jyb4c");
Iterable<?> output = (Iterable<?>) getOutputAsJson(); Iterable<?> output = (Iterable<?>) getOutputAsJson();
@ -166,7 +168,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
assertThat(output).containsAtLeast(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT); assertThat(output).containsAtLeast(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
} }
@Test @TestOfyAndSql
void testSuccess_skipDeletedDomain() throws Exception { void testSuccess_skipDeletedDomain() throws Exception {
persistResource(domain1.asBuilder().setDeletionTime(now).build()); persistResource(domain1.asBuilder().setDeletionTime(now).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c"); runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -174,7 +176,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT); .containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
} }
@Test @TestOfyAndSql
void testSuccess_skipDeletedNameserver() throws Exception { void testSuccess_skipDeletedNameserver() throws Exception {
persistResource(nameserver1.asBuilder().setDeletionTime(now).build()); persistResource(nameserver1.asBuilder().setDeletionTime(now).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c"); runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -183,7 +185,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
assertThat(output).containsAtLeast(DOMAIN2_OUTPUT, NAMESERVER2_OUTPUT); assertThat(output).containsAtLeast(DOMAIN2_OUTPUT, NAMESERVER2_OUTPUT);
} }
@Test @TestOfyAndSql
void testSuccess_skipClientHoldDomain() throws Exception { void testSuccess_skipClientHoldDomain() throws Exception {
persistResource(domain1.asBuilder().addStatusValue(StatusValue.CLIENT_HOLD).build()); persistResource(domain1.asBuilder().addStatusValue(StatusValue.CLIENT_HOLD).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c"); runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -191,7 +193,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT); .containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
} }
@Test @TestOfyAndSql
void testSuccess_skipServerHoldDomain() throws Exception { void testSuccess_skipServerHoldDomain() throws Exception {
persistResource(domain1.asBuilder().addStatusValue(StatusValue.SERVER_HOLD).build()); persistResource(domain1.asBuilder().addStatusValue(StatusValue.SERVER_HOLD).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c"); runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -199,7 +201,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT); .containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
} }
@Test @TestOfyAndSql
void testSuccess_skipPendingDeleteDomain() throws Exception { void testSuccess_skipPendingDeleteDomain() throws Exception {
persistResource( persistResource(
domain1 domain1
@ -212,7 +214,7 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT); .containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
} }
@Test @TestOfyAndSql
void testSuccess_skipDomainsWithoutNameservers() throws Exception { void testSuccess_skipDomainsWithoutNameservers() throws Exception {
persistResource(domain1.asBuilder().setNameservers(ImmutableSet.of()).build()); persistResource(domain1.asBuilder().setNameservers(ImmutableSet.of()).build());
runCommand("--output=" + output, "--tld=xn--q9jyb4c"); runCommand("--output=" + output, "--tld=xn--q9jyb4c");
@ -220,12 +222,12 @@ class GenerateDnsReportCommandTest extends CommandTestCase<GenerateDnsReportComm
.containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT); .containsExactly(DOMAIN2_OUTPUT, NAMESERVER1_OUTPUT, NAMESERVER2_OUTPUT);
} }
@Test @TestOfyAndSql
void testFailure_tldDoesNotExist() { void testFailure_tldDoesNotExist() {
assertThrows(IllegalArgumentException.class, () -> runCommand("--tld=foobar")); assertThrows(IllegalArgumentException.class, () -> runCommand("--tld=foobar"));
} }
@Test @TestOfyAndSql
void testFailure_missingTldParameter() { void testFailure_missingTldParameter() {
assertThrows(ParameterException.class, () -> runCommand("")); 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.contact.ContactResource;
import google.registry.model.domain.DesignatedContact; import google.registry.model.domain.DesignatedContact;
import google.registry.model.domain.DomainBase; import google.registry.model.domain.DomainBase;
import google.registry.model.domain.DomainHistory;
import google.registry.model.domain.GracePeriod; import google.registry.model.domain.GracePeriod;
import google.registry.model.eppcommon.StatusValue; import google.registry.model.eppcommon.StatusValue;
import google.registry.model.host.HostResource; import google.registry.model.host.HostResource;
import google.registry.model.ofy.Ofy; import google.registry.model.ofy.Ofy;
import google.registry.model.reporting.HistoryEntry; import google.registry.model.reporting.HistoryEntry;
import google.registry.persistence.VKey; import google.registry.persistence.VKey;
import google.registry.testing.DualDatabaseTest;
import google.registry.testing.InjectExtension; import google.registry.testing.InjectExtension;
import google.registry.testing.TestOfyAndSql;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.api.extension.RegisterExtension;
/** Unit tests for {@link UpdateDomainCommand}. */ /** Unit tests for {@link UpdateDomainCommand}. */
@DualDatabaseTest
class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand> { class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand> {
private DomainBase domain; private DomainBase domain;
@ -62,7 +65,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
domain = persistActiveDomain("example.tld"); domain = persistActiveDomain("example.tld");
} }
@Test @TestOfyAndSql
void testSuccess_complete() throws Exception { void testSuccess_complete() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
@ -82,7 +85,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_complete.xml"); eppVerifier.verifySent("domain_update_complete.xml");
} }
@Test @TestOfyAndSql
void testSuccess_completeWithSquareBrackets() throws Exception { void testSuccess_completeWithSquareBrackets() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
@ -102,7 +105,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_complete.xml"); eppVerifier.verifySent("domain_update_complete.xml");
} }
@Test @TestOfyAndSql
void testSuccess_multipleDomains() throws Exception { void testSuccess_multipleDomains() throws Exception {
createTld("abc"); createTld("abc");
persistActiveDomain("example.abc"); persistActiveDomain("example.abc");
@ -127,12 +130,12 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
.verifySent("domain_update_complete_abc.xml"); .verifySent("domain_update_complete_abc.xml");
} }
@Test @TestOfyAndSql
void testSuccess_multipleDomains_setNameservers() throws Exception { void testSuccess_multipleDomains_setNameservers() throws Exception {
runTest_multipleDomains_setNameservers("-n ns1.foo.fake,ns2.foo.fake"); runTest_multipleDomains_setNameservers("-n ns1.foo.fake,ns2.foo.fake");
} }
@Test @TestOfyAndSql
void testSuccess_multipleDomains_setNameserversWithSquareBrackets() throws Exception { void testSuccess_multipleDomains_setNameserversWithSquareBrackets() throws Exception {
runTest_multipleDomains_setNameservers("-n ns[1-2].foo.fake"); 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")); ImmutableMap.of("DOMAIN", "example.tld", "REMOVEHOST", "baz.bar.tld"));
} }
@Test @TestOfyAndSql
void testSuccess_add() throws Exception { void testSuccess_add() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
@ -175,7 +178,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_add.xml"); eppVerifier.verifySent("domain_update_add.xml");
} }
@Test @TestOfyAndSql
void testSuccess_remove() throws Exception { void testSuccess_remove() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
@ -188,14 +191,14 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_remove.xml"); eppVerifier.verifySent("domain_update_remove.xml");
} }
@Test @TestOfyAndSql
void testSuccess_change() throws Exception { void testSuccess_change() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR", "example.tld"); "--client=NewRegistrar", "--registrant=crr-admin", "--password=2fooBAR", "example.tld");
eppVerifier.verifySent("domain_update_change.xml"); eppVerifier.verifySent("domain_update_change.xml");
} }
@Test @TestOfyAndSql
void testSuccess_setNameservers() throws Exception { void testSuccess_setNameservers() throws Exception {
HostResource host1 = persistActiveHost("ns1.zdns.google"); HostResource host1 = persistActiveHost("ns1.zdns.google");
HostResource host2 = persistActiveHost("ns2.zdns.google"); HostResource host2 = persistActiveHost("ns2.zdns.google");
@ -208,37 +211,28 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_set_nameservers.xml"); eppVerifier.verifySent("domain_update_set_nameservers.xml");
} }
@Test @TestOfyAndSql
void testSuccess_setContacts() throws Exception { void testSuccess_setContacts() throws Exception {
ContactResource adminContact1 = persistResource(newContactResource("crr-admin1")); ContactResource adminContact = persistResource(newContactResource("crr-admin1"));
ContactResource adminContact2 = persistResource(newContactResource("crr-admin2")); ContactResource techContact = persistResource(newContactResource("crr-tech1"));
ContactResource techContact1 = persistResource(newContactResource("crr-tech1")); VKey<ContactResource> adminContactKey = adminContact.createVKey();
ContactResource techContact2 = persistResource(newContactResource("crr-tech2")); VKey<ContactResource> techContactKey = techContact.createVKey();
VKey<ContactResource> adminResourceKey1 = adminContact1.createVKey();
VKey<ContactResource> adminResourceKey2 = adminContact2.createVKey();
VKey<ContactResource> techResourceKey1 = techContact1.createVKey();
VKey<ContactResource> techResourceKey2 = techContact2.createVKey();
persistResource( persistResource(
newDomainBase("example.tld") newDomainBase("example.tld")
.asBuilder() .asBuilder()
.setContacts( .setContacts(
ImmutableSet.of( ImmutableSet.of(
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey1), DesignatedContact.create(DesignatedContact.Type.ADMIN, adminContactKey),
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey2), DesignatedContact.create(DesignatedContact.Type.TECH, techContactKey)))
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey1),
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey2)))
.build()); .build());
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar", "--admins=crr-admin3", "--techs=crr-tech3", "example.tld");
"--admins=crr-admin2,crr-admin3",
"--techs=crr-tech2,crr-tech3",
"example.tld");
eppVerifier.verifySent("domain_update_set_contacts.xml"); eppVerifier.verifySent("domain_update_set_contacts.xml");
} }
@Test @TestOfyAndSql
void testSuccess_setStatuses() throws Exception { void testSuccess_setStatuses() throws Exception {
HostResource host = persistActiveHost("ns1.zdns.google"); HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey()); ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey());
@ -256,14 +250,14 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_set_statuses.xml"); eppVerifier.verifySent("domain_update_set_statuses.xml");
} }
@Test @TestOfyAndSql
void testSuccess_setDsRecords() throws Exception { void testSuccess_setDsRecords() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--ds_records=1 2 3 abcd,4 5 6 EF01", "example.tld"); "--client=NewRegistrar", "--ds_records=1 2 3 abcd,4 5 6 EF01", "example.tld");
eppVerifier.verifySent("domain_update_set_ds_records.xml"); eppVerifier.verifySent("domain_update_set_ds_records.xml");
} }
@Test @TestOfyAndSql
void testSuccess_setDsRecords_withUnneededClear() throws Exception { void testSuccess_setDsRecords_withUnneededClear() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
@ -273,7 +267,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_set_ds_records.xml"); eppVerifier.verifySent("domain_update_set_ds_records.xml");
} }
@Test @TestOfyAndSql
void testSuccess_clearDsRecords() throws Exception { void testSuccess_clearDsRecords() throws Exception {
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
@ -282,14 +276,14 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
eppVerifier.verifySent("domain_update_clear_ds_records.xml"); eppVerifier.verifySent("domain_update_clear_ds_records.xml");
} }
@Test @TestOfyAndSql
void testSuccess_enableAutorenew() throws Exception { void testSuccess_enableAutorenew() throws Exception {
runCommandForced("--client=NewRegistrar", "--autorenews=true", "example.tld"); runCommandForced("--client=NewRegistrar", "--autorenews=true", "example.tld");
eppVerifier.verifySent( eppVerifier.verifySent(
"domain_update_set_autorenew.xml", ImmutableMap.of("AUTORENEWS", "true")); "domain_update_set_autorenew.xml", ImmutableMap.of("AUTORENEWS", "true"));
} }
@Test @TestOfyAndSql
void testSuccess_disableAutorenew() throws Exception { void testSuccess_disableAutorenew() throws Exception {
runCommandForced("--client=NewRegistrar", "--autorenews=false", "example.tld"); runCommandForced("--client=NewRegistrar", "--autorenews=false", "example.tld");
eppVerifier.verifySent( eppVerifier.verifySent(
@ -297,11 +291,15 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(getStderrAsString()).doesNotContain("autorenew grace period"); assertThat(getStderrAsString()).doesNotContain("autorenew grace period");
} }
@Test @TestOfyAndSql
void testSuccess_disableAutorenew_inAutorenewGracePeriod() throws Exception { void testSuccess_disableAutorenew_inAutorenewGracePeriod() throws Exception {
HistoryEntry createHistoryEntry = HistoryEntry createHistoryEntry =
persistResource( 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 = BillingEvent.Recurring autorenewBillingEvent =
persistResource( persistResource(
new BillingEvent.Recurring.Builder() new BillingEvent.Recurring.Builder()
@ -335,40 +333,34 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(stdErr).contains("example.tld"); assertThat(stdErr).contains("example.tld");
} }
@Test @TestOfyAndSql
void testSuccess_canUpdatePendingDeleteDomain_whenSuperuserPassesOverrideFlag() throws Exception { void testSuccess_canUpdatePendingDeleteDomain_whenSuperuserPassesOverrideFlag() throws Exception {
ContactResource adminContact1 = persistResource(newContactResource("crr-admin1")); ContactResource adminContact = persistResource(newContactResource("crr-admin1"));
ContactResource adminContact2 = persistResource(newContactResource("crr-admin2")); ContactResource techContact = persistResource(newContactResource("crr-tech1"));
ContactResource techContact1 = persistResource(newContactResource("crr-tech1")); VKey<ContactResource> adminContactKey = adminContact.createVKey();
ContactResource techContact2 = persistResource(newContactResource("crr-tech2")); VKey<ContactResource> techContactKey = techContact.createVKey();
VKey<ContactResource> adminResourceKey1 = adminContact1.createVKey();
VKey<ContactResource> adminResourceKey2 = adminContact2.createVKey();
VKey<ContactResource> techResourceKey1 = techContact1.createVKey();
VKey<ContactResource> techResourceKey2 = techContact2.createVKey();
persistResource( persistResource(
newDomainBase("example.tld") newDomainBase("example.tld")
.asBuilder() .asBuilder()
.setContacts( .setContacts(
ImmutableSet.of( ImmutableSet.of(
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey1), DesignatedContact.create(DesignatedContact.Type.ADMIN, adminContactKey),
DesignatedContact.create(DesignatedContact.Type.ADMIN, adminResourceKey2), DesignatedContact.create(DesignatedContact.Type.TECH, techContactKey)))
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey1),
DesignatedContact.create(DesignatedContact.Type.TECH, techResourceKey2)))
.setStatusValues(ImmutableSet.of(PENDING_DELETE)) .setStatusValues(ImmutableSet.of(PENDING_DELETE))
.build()); .build());
runCommandForced( runCommandForced(
"--client=NewRegistrar", "--client=NewRegistrar",
"--admins=crr-admin2,crr-admin3", "--admins=crr-admin3",
"--techs=crr-tech2,crr-tech3", "--techs=crr-tech3",
"--superuser", "--superuser",
"--force_in_pending_delete", "--force_in_pending_delete",
"example.tld"); "example.tld");
eppVerifier.expectSuperuser().verifySent("domain_update_set_contacts.xml"); eppVerifier.expectSuperuser().verifySent("domain_update_set_contacts.xml");
} }
@Test @TestOfyAndSql
void testFailure_cantUpdateRegistryLockedDomainEvenAsSuperuser() { void testFailure_cantUpdateRegistryLockedDomainEvenAsSuperuser() {
HostResource host = persistActiveHost("ns1.zdns.google"); HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey()); 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."); .contains("The domain 'example.tld' has status SERVER_UPDATE_PROHIBITED.");
} }
@Test @TestOfyAndSql
void testFailure_cantUpdatePendingDeleteDomainEvenAsSuperuser_withoutPassingOverrideFlag() { void testFailure_cantUpdatePendingDeleteDomainEvenAsSuperuser_withoutPassingOverrideFlag() {
HostResource host = persistActiveHost("ns1.zdns.google"); HostResource host = persistActiveHost("ns1.zdns.google");
ImmutableSet<VKey<HostResource>> nameservers = ImmutableSet.of(host.createVKey()); 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."); assertThat(e).hasMessageThat().contains("The domain 'example.tld' has status PENDING_DELETE.");
} }
@Test @TestOfyAndSql
void testFailure_duplicateDomains() { void testFailure_duplicateDomains() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -431,7 +423,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("Duplicate arguments found"); assertThat(thrown).hasMessageThat().contains("Duplicate arguments found");
} }
@Test @TestOfyAndSql
void testFailure_missingDomain() { void testFailure_missingDomain() {
ParameterException thrown = ParameterException thrown =
assertThrows( assertThrows(
@ -442,7 +434,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("Main parameters are required"); assertThat(thrown).hasMessageThat().contains("Main parameters are required");
} }
@Test @TestOfyAndSql
void testFailure_missingClientId() { void testFailure_missingClientId() {
ParameterException thrown = ParameterException thrown =
assertThrows( assertThrows(
@ -451,7 +443,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("--client"); assertThat(thrown).hasMessageThat().contains("--client");
} }
@Test @TestOfyAndSql
void testFailure_addTooManyNameServers() { void testFailure_addTooManyNameServers() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -470,7 +462,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
assertThat(thrown).hasMessageThat().contains("You can add at most 13 nameservers"); assertThat(thrown).hasMessageThat().contains("You can add at most 13 nameservers");
} }
@Test @TestOfyAndSql
void testFailure_providedNameserversAndAddNameservers() { void testFailure_providedNameserversAndAddNameservers() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -488,7 +480,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_nameservers and remove_nameservers flags."); + "you cannot use the add_nameservers and remove_nameservers flags.");
} }
@Test @TestOfyAndSql
void testFailure_providedNameserversAndRemoveNameservers() { void testFailure_providedNameserversAndRemoveNameservers() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -506,7 +498,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_nameservers and remove_nameservers flags."); + "you cannot use the add_nameservers and remove_nameservers flags.");
} }
@Test @TestOfyAndSql
void testFailure_providedAdminsAndAddAdmins() { void testFailure_providedAdminsAndAddAdmins() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -524,7 +516,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_admins and remove_admins flags."); + "you cannot use the add_admins and remove_admins flags.");
} }
@Test @TestOfyAndSql
void testFailure_providedAdminsAndRemoveAdmins() { void testFailure_providedAdminsAndRemoveAdmins() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -542,7 +534,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_admins and remove_admins flags."); + "you cannot use the add_admins and remove_admins flags.");
} }
@Test @TestOfyAndSql
void testFailure_providedTechsAndAddTechs() { void testFailure_providedTechsAndAddTechs() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( 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."); "If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
} }
@Test @TestOfyAndSql
void testFailure_providedTechsAndRemoveTechs() { void testFailure_providedTechsAndRemoveTechs() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( 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."); "If you provide the techs flag, you cannot use the add_techs and remove_techs flags.");
} }
@Test @TestOfyAndSql
void testFailure_providedStatusesAndAddStatuses() { void testFailure_providedStatusesAndAddStatuses() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -594,7 +586,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_statuses and remove_statuses flags."); + "you cannot use the add_statuses and remove_statuses flags.");
} }
@Test @TestOfyAndSql
void testFailure_providedStatusesAndRemoveStatuses() { void testFailure_providedStatusesAndRemoveStatuses() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -612,7 +604,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_statuses and remove_statuses flags."); + "you cannot use the add_statuses and remove_statuses flags.");
} }
@Test @TestOfyAndSql
void testFailure_provideDsRecordsAndAddDsRecords() { void testFailure_provideDsRecordsAndAddDsRecords() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -630,7 +622,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_ds_records and remove_ds_records flags."); + "you cannot use the add_ds_records and remove_ds_records flags.");
} }
@Test @TestOfyAndSql
void testFailure_provideDsRecordsAndRemoveDsRecords() { void testFailure_provideDsRecordsAndRemoveDsRecords() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -648,7 +640,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_ds_records and remove_ds_records flags."); + "you cannot use the add_ds_records and remove_ds_records flags.");
} }
@Test @TestOfyAndSql
void testFailure_clearDsRecordsAndAddDsRecords() { void testFailure_clearDsRecordsAndAddDsRecords() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(
@ -666,7 +658,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
+ "you cannot use the add_ds_records and remove_ds_records flags."); + "you cannot use the add_ds_records and remove_ds_records flags.");
} }
@Test @TestOfyAndSql
void testFailure_clearDsRecordsAndRemoveDsRecords() { void testFailure_clearDsRecordsAndRemoveDsRecords() {
IllegalArgumentException thrown = IllegalArgumentException thrown =
assertThrows( assertThrows(

View file

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