mirror of
https://github.com/google/nomulus
synced 2026-02-10 06:50:30 +00:00
Add sanity checks to history entry construction (#1156)
* Add sanity checks to history entry construction * Add more missing setClientId() calls and delete scrap tool * Merge branch 'master' into synthetic-requestedby * Set more client IDs * Merge branch 'master' into synthetic-requestedby
This commit is contained in:
@@ -170,6 +170,7 @@ class DeleteExpiredDomainsActionTest {
|
||||
.setType(DOMAIN_CREATE)
|
||||
.setParent(pendingExpirationDomain)
|
||||
.setModificationTime(clock.nowUtc().minusMonths(9))
|
||||
.setClientId(pendingExpirationDomain.getCreationClientId())
|
||||
.build());
|
||||
BillingEvent.Recurring autorenewBillingEvent =
|
||||
persistResource(createAutorenewBillingEvent(createHistoryEntry).build());
|
||||
|
||||
@@ -279,11 +279,14 @@ class DeleteProberDataActionTest extends MapreduceTestCase<DeleteProberDataActio
|
||||
*/
|
||||
private static Set<ImmutableObject> persistDomainAndDescendants(String fqdn) {
|
||||
DomainBase domain = persistDeletedDomain(fqdn, DELETION_TIME);
|
||||
HistoryEntry historyEntry = persistSimpleResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.build());
|
||||
HistoryEntry historyEntry =
|
||||
persistSimpleResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setClientId("TheRegistrar")
|
||||
.setModificationTime(DELETION_TIME.minusYears(3))
|
||||
.build());
|
||||
BillingEvent.OneTime billingEvent = persistSimpleResource(
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setParent(historyEntry)
|
||||
|
||||
@@ -19,6 +19,7 @@ import static google.registry.model.common.Cursor.CursorType.RECURRING_BILLING;
|
||||
import static google.registry.model.domain.Period.Unit.YEARS;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_AUTORENEW;
|
||||
import static google.registry.model.reporting.HistoryEntry.Type.DOMAIN_CREATE;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.assertBillingEvents;
|
||||
import static google.registry.testing.DatabaseHelper.assertBillingEventsForResource;
|
||||
@@ -84,9 +85,20 @@ public class ExpandRecurringBillingEventsActionTest
|
||||
action.clock = clock;
|
||||
action.cursorTimeParam = Optional.empty();
|
||||
createTld("tld");
|
||||
domain = persistResource(newDomainBase("example.tld").asBuilder()
|
||||
.setCreationTimeForTest(DateTime.parse("1999-01-05T00:00:00Z")).build());
|
||||
historyEntry = persistResource(new HistoryEntry.Builder().setParent(domain).build());
|
||||
domain =
|
||||
persistResource(
|
||||
newDomainBase("example.tld")
|
||||
.asBuilder()
|
||||
.setCreationTimeForTest(DateTime.parse("1999-01-05T00:00:00Z"))
|
||||
.build());
|
||||
historyEntry =
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(DateTime.parse("1999-01-05T00:00:00Z"))
|
||||
.setParent(domain)
|
||||
.build());
|
||||
recurring =
|
||||
new BillingEvent.Recurring.Builder()
|
||||
.setParent(historyEntry)
|
||||
@@ -174,7 +186,14 @@ public class ExpandRecurringBillingEventsActionTest
|
||||
void testSuccess_expandSingleEvent_deletedDomain() throws Exception {
|
||||
DateTime deletionTime = DateTime.parse("2000-08-01T00:00:00Z");
|
||||
DomainBase deletedDomain = persistDeletedDomain("deleted.tld", deletionTime);
|
||||
historyEntry = persistResource(new HistoryEntry.Builder().setParent(deletedDomain).build());
|
||||
historyEntry =
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(deletedDomain)
|
||||
.setClientId(deletedDomain.getCreationClientId())
|
||||
.setModificationTime(deletedDomain.getCreationTime())
|
||||
.setType(DOMAIN_CREATE)
|
||||
.build());
|
||||
recurring =
|
||||
persistResource(
|
||||
new BillingEvent.Recurring.Builder()
|
||||
|
||||
@@ -100,7 +100,14 @@ public class DomainBaseUtilTest {
|
||||
.build())
|
||||
.createVKey();
|
||||
Key<HistoryEntry> historyEntryKey =
|
||||
Key.create(persistResource(new HistoryEntry.Builder().setParent(domainKey).build()));
|
||||
Key.create(
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domainKey)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setClientId("TheRegistrar")
|
||||
.setModificationTime(fakeClock.nowUtc().minusYears(1))
|
||||
.build()));
|
||||
oneTimeBillKey = Key.create(historyEntryKey, BillingEvent.OneTime.class, 1);
|
||||
recurringBillKey = VKey.from(Key.create(historyEntryKey, BillingEvent.Recurring.class, 2));
|
||||
VKey<PollMessage.Autorenew> autorenewPollKey =
|
||||
|
||||
@@ -181,6 +181,7 @@ class InitSqlPipelineTest {
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domainKey)
|
||||
.setModificationTime(fakeClock.nowUtc())
|
||||
.setClientId(registrar1.getClientId())
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.build());
|
||||
persistResource(
|
||||
|
||||
@@ -179,6 +179,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
||||
.setType(DOMAIN_CREATE)
|
||||
.setParent(domain)
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build());
|
||||
}
|
||||
|
||||
@@ -1114,6 +1115,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
||||
.setType(DOMAIN_CREATE)
|
||||
.setParent(domain)
|
||||
.setModificationTime(TIME_BEFORE_FLOW.minusDays(1))
|
||||
.setClientId("TheRegistrar")
|
||||
.setDomainTransactionRecords(ImmutableSet.of(existingRecord))
|
||||
.build());
|
||||
runFlow();
|
||||
|
||||
@@ -366,6 +366,7 @@ class DomainInfoFlowTest extends ResourceFlowTestCase<DomainInfoFlow, DomainBase
|
||||
.setParent(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build());
|
||||
BillingEvent.Recurring renewEvent =
|
||||
persistResource(
|
||||
|
||||
@@ -130,6 +130,7 @@ class DomainRenewFlowTest extends ResourceFlowTestCase<DomainRenewFlow, DomainBa
|
||||
.setParent(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build();
|
||||
BillingEvent.Recurring autorenewEvent =
|
||||
new BillingEvent.Recurring.Builder()
|
||||
|
||||
@@ -116,6 +116,7 @@ class DomainRestoreRequestFlowTest
|
||||
new HistoryEntry.Builder()
|
||||
.setType(HistoryEntry.Type.DOMAIN_DELETE)
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setClientId(domain.getCurrentSponsorClientId())
|
||||
.setParent(domain)
|
||||
.build());
|
||||
persistResource(
|
||||
|
||||
@@ -607,6 +607,7 @@ class DomainTransferApproveFlowTest
|
||||
.setType(DOMAIN_TRANSFER_REQUEST)
|
||||
.setParent(domain)
|
||||
.setModificationTime(clock.nowUtc().minusDays(4))
|
||||
.setClientId("TheRegistrar")
|
||||
.setDomainTransactionRecords(
|
||||
ImmutableSet.of(previousSuccessRecord, notCancellableRecord))
|
||||
.build());
|
||||
|
||||
@@ -406,6 +406,7 @@ class DomainTransferCancelFlowTest
|
||||
.setType(DOMAIN_TRANSFER_REQUEST)
|
||||
.setDomain(domain)
|
||||
.setModificationTime(clock.nowUtc().minusDays(4))
|
||||
.setClientId("TheRegistrar")
|
||||
.setDomainTransactionRecords(
|
||||
ImmutableSet.of(previousSuccessRecord, notCancellableRecord))
|
||||
.build());
|
||||
|
||||
@@ -371,6 +371,7 @@ class DomainTransferRejectFlowTest
|
||||
.setType(DOMAIN_TRANSFER_REQUEST)
|
||||
.setParent(domain)
|
||||
.setModificationTime(clock.nowUtc().minusDays(4))
|
||||
.setClientId("TheRegistrar")
|
||||
.setDomainTransactionRecords(
|
||||
ImmutableSet.of(previousSuccessRecord, notCancellableRecord))
|
||||
.build());
|
||||
|
||||
@@ -156,6 +156,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||
new HistoryEntry.Builder()
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.setParent(domain)
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
@@ -179,6 +180,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
||||
new HistoryEntry.Builder()
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.setParent(domain)
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
|
||||
@@ -208,12 +208,14 @@ class PollRequestFlowTest extends FlowTestCase<PollRequestFlow> {
|
||||
void testSuccess_contactDelete() throws Exception {
|
||||
// Contact delete poll messages do not have any response data, so ensure that no
|
||||
// response data block is produced in the poll message.
|
||||
HistoryEntry historyEntry = persistResource(new HistoryEntry.Builder()
|
||||
.setClientId("NewRegistrar")
|
||||
.setModificationTime(clock.nowUtc().minusDays(1))
|
||||
.setType(HistoryEntry.Type.CONTACT_DELETE)
|
||||
.setParent(contact)
|
||||
.build());
|
||||
HistoryEntry historyEntry =
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setClientId("NewRegistrar")
|
||||
.setModificationTime(clock.nowUtc().minusDays(1))
|
||||
.setType(HistoryEntry.Type.CONTACT_DELETE)
|
||||
.setParent(contact)
|
||||
.build());
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("NewRegistrar")
|
||||
@@ -229,12 +231,14 @@ class PollRequestFlowTest extends FlowTestCase<PollRequestFlow> {
|
||||
void testSuccess_hostDelete() throws Exception {
|
||||
// Host delete poll messages do not have any response data, so ensure that no
|
||||
// response data block is produced in the poll message.
|
||||
HistoryEntry historyEntry = persistResource(new HistoryEntry.Builder()
|
||||
.setClientId("NewRegistrar")
|
||||
.setModificationTime(clock.nowUtc().minusDays(1))
|
||||
.setType(HistoryEntry.Type.HOST_DELETE)
|
||||
.setParent(host)
|
||||
.build());
|
||||
HistoryEntry historyEntry =
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setClientId("NewRegistrar")
|
||||
.setModificationTime(clock.nowUtc().minusDays(1))
|
||||
.setType(HistoryEntry.Type.HOST_DELETE)
|
||||
.setParent(host)
|
||||
.build());
|
||||
persistResource(
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setClientId("NewRegistrar")
|
||||
|
||||
@@ -80,10 +80,22 @@ class ChildEntityInputTest {
|
||||
domainA = persistEppResourceInFirstBucket(newDomainBase("a.tld", contact));
|
||||
domainHistoryEntryA =
|
||||
persistResource(
|
||||
new DomainHistory.Builder().setDomain(domainA).setModificationTime(now).build());
|
||||
new DomainHistory.Builder()
|
||||
.setDomain(domainA)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setDomain(domainA)
|
||||
.setModificationTime(now)
|
||||
.setClientId(domainA.getCreationClientId())
|
||||
.build());
|
||||
contactHistoryEntry =
|
||||
persistResource(
|
||||
new ContactHistory.Builder().setContact(contact).setModificationTime(now).build());
|
||||
new ContactHistory.Builder()
|
||||
.setContact(contact)
|
||||
.setType(HistoryEntry.Type.CONTACT_CREATE)
|
||||
.setContact(contact)
|
||||
.setModificationTime(now)
|
||||
.setClientId(contact.getCreationClientId())
|
||||
.build());
|
||||
oneTimeA =
|
||||
persistResource(
|
||||
new BillingEvent.OneTime.Builder()
|
||||
@@ -113,7 +125,13 @@ class ChildEntityInputTest {
|
||||
domainB = persistEppResourceInFirstBucket(newDomainBase("b.tld"));
|
||||
domainHistoryEntryB =
|
||||
persistResource(
|
||||
new DomainHistory.Builder().setDomain(domainB).setModificationTime(now).build());
|
||||
new DomainHistory.Builder()
|
||||
.setDomain(domainB)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setDomain(domainB)
|
||||
.setModificationTime(now)
|
||||
.setClientId(domainB.getCreationClientId())
|
||||
.build());
|
||||
oneTimeB =
|
||||
persistResource(
|
||||
new BillingEvent.OneTime.Builder()
|
||||
@@ -295,8 +313,9 @@ class ChildEntityInputTest {
|
||||
persistResource(
|
||||
new DomainHistory.Builder()
|
||||
.setDomain(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(now)
|
||||
.setClientId(i + ".tld")
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build())
|
||||
.asHistoryEntry());
|
||||
persistResource(EppResourceIndex.create(getBucketKey(i), Key.create(domain)));
|
||||
|
||||
@@ -80,6 +80,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||
.setDomain(domain)
|
||||
.setModificationTime(now)
|
||||
.setRequestedByRegistrar(false)
|
||||
.setClientId("TheRegistrar")
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setXmlBytes(new byte[0])
|
||||
.build());
|
||||
@@ -89,6 +90,7 @@ public class BillingEventTest extends EntityTestCase {
|
||||
.setDomain(domain)
|
||||
.setModificationTime(now.plusDays(1))
|
||||
.setRequestedByRegistrar(false)
|
||||
.setClientId("TheRegistrar")
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setXmlBytes(new byte[0])
|
||||
.build());
|
||||
|
||||
@@ -443,7 +443,7 @@ public class DomainBaseSqlTest {
|
||||
.setModificationTime(DateTime.now(UTC))
|
||||
.setParent(Key.create(DomainBase.class, "4-COM"))
|
||||
.setDomainRepoId("4-COM")
|
||||
|
||||
.setClientId("registrar1")
|
||||
// These are non-null, but I don't think some tests set them.
|
||||
.setReason("felt like it")
|
||||
.setRequestedByRegistrar(false)
|
||||
@@ -574,7 +574,7 @@ public class DomainBaseSqlTest {
|
||||
.setModificationTime(DateTime.now(UTC))
|
||||
.setParent(Key.create(DomainBase.class, "4-COM"))
|
||||
.setDomainRepoId("4-COM")
|
||||
|
||||
.setClientId("registrar1")
|
||||
// These are non-null, but I don't think some tests set them.
|
||||
.setReason("felt like it")
|
||||
.setRequestedByRegistrar(false)
|
||||
|
||||
@@ -63,6 +63,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link DomainBase}. */
|
||||
@SuppressWarnings("WeakerAccess") // Referred to by EppInputTest.
|
||||
public class DomainBaseTest extends EntityTestCase {
|
||||
|
||||
private DomainBase domain;
|
||||
@@ -98,7 +99,13 @@ public class DomainBaseTest extends EntityTestCase {
|
||||
.createVKey();
|
||||
historyEntryKey =
|
||||
Key.create(
|
||||
persistResource(new HistoryEntry.Builder().setParent(domainKey.getOfyKey()).build()));
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domainKey.getOfyKey())
|
||||
.setModificationTime(fakeClock.nowUtc())
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setClientId("aregistrar")
|
||||
.build()));
|
||||
oneTimeBillKey = VKey.from(Key.create(historyEntryKey, BillingEvent.OneTime.class, 1));
|
||||
recurringBillKey = VKey.from(Key.create(historyEntryKey, BillingEvent.Recurring.class, 2));
|
||||
VKey<PollMessage.Autorenew> autorenewPollKey =
|
||||
@@ -112,7 +119,7 @@ public class DomainBaseTest extends EntityTestCase {
|
||||
new DomainBase.Builder()
|
||||
.setDomainName("example.com")
|
||||
.setRepoId("4-COM")
|
||||
.setCreationClientId("a registrar")
|
||||
.setCreationClientId("aregistrar")
|
||||
.setLastEppUpdateTime(fakeClock.nowUtc())
|
||||
.setLastEppUpdateClientId("AnotherRegistrar")
|
||||
.setLastTransferTime(fakeClock.nowUtc())
|
||||
@@ -356,7 +363,13 @@ public class DomainBaseTest extends EntityTestCase {
|
||||
}
|
||||
|
||||
private void doExpiredTransferTest(DateTime oldExpirationTime) {
|
||||
HistoryEntry historyEntry = new HistoryEntry.Builder().setParent(domain).build();
|
||||
HistoryEntry historyEntry =
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domain)
|
||||
.setModificationTime(fakeClock.nowUtc())
|
||||
.setClientId(domain.getCurrentSponsorClientId())
|
||||
.setType(HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST)
|
||||
.build();
|
||||
BillingEvent.OneTime transferBillingEvent =
|
||||
persistResource(
|
||||
new BillingEvent.OneTime.Builder()
|
||||
|
||||
@@ -71,8 +71,9 @@ public class OfyTest {
|
||||
createTld("tld");
|
||||
someObject =
|
||||
new HistoryEntry.Builder()
|
||||
.setClientId("client id")
|
||||
.setClientId("clientid")
|
||||
.setModificationTime(START_OF_TIME)
|
||||
.setType(HistoryEntry.Type.CONTACT_CREATE)
|
||||
.setParent(persistActiveContact("parentContact"))
|
||||
.setTrid(Trid.create("client", "server"))
|
||||
.setXmlBytes("<xml></xml>".getBytes(UTF_8))
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
package google.registry.model.reporting;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.persistence.transaction.TransactionManagerUtil.transactIfJpaTm;
|
||||
@@ -21,6 +22,7 @@ import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -33,6 +35,7 @@ import google.registry.model.reporting.DomainTransactionRecord.TransactionReport
|
||||
import google.registry.testing.DualDatabaseTest;
|
||||
import google.registry.testing.TestOfyAndSql;
|
||||
import google.registry.testing.TestOfyOnly;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
/** Unit tests for {@link HistoryEntry}. */
|
||||
@@ -87,6 +90,70 @@ class HistoryEntryTest extends EntityTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testBuilder_typeMustBeSpecified() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new HistoryEntry.Builder()
|
||||
.setId(5L)
|
||||
.setModificationTime(DateTime.parse("1985-07-12T22:30:00Z"))
|
||||
.setClientId("TheRegistrar")
|
||||
.setReason("Reason")
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("History entry type must be specified");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testBuilder_modificationTimeMustBeSpecified() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new HistoryEntry.Builder()
|
||||
.setId(5L)
|
||||
.setType(HistoryEntry.Type.CONTACT_CREATE)
|
||||
.setClientId("TheRegistrar")
|
||||
.setReason("Reason")
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Modification time must be specified");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testBuilder_registrarIdMustBeSpecified() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new HistoryEntry.Builder()
|
||||
.setId(5L)
|
||||
.setType(HistoryEntry.Type.CONTACT_CREATE)
|
||||
.setModificationTime(DateTime.parse("1985-07-12T22:30:00Z"))
|
||||
.setReason("Reason")
|
||||
.build());
|
||||
assertThat(thrown).hasMessageThat().isEqualTo("Registrar ID must be specified");
|
||||
}
|
||||
|
||||
@TestOfyAndSql
|
||||
void testBuilder_syntheticHistoryEntries_mustNotBeRequestedByRegistrar() {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() ->
|
||||
new HistoryEntry.Builder()
|
||||
.setId(5L)
|
||||
.setType(HistoryEntry.Type.SYNTHETIC)
|
||||
.setModificationTime(DateTime.parse("1985-07-12T22:30:00Z"))
|
||||
.setClientId("TheRegistrar")
|
||||
.setReason("Reason")
|
||||
.setRequestedByRegistrar(true)
|
||||
.build());
|
||||
assertThat(thrown)
|
||||
.hasMessageThat()
|
||||
.isEqualTo("Synthetic history entries cannot be requested by a registrar");
|
||||
}
|
||||
|
||||
@TestOfyOnly
|
||||
void testIndexing() throws Exception {
|
||||
verifyIndexing(domainHistory.asHistoryEntry(), "modificationTime", "clientId");
|
||||
|
||||
@@ -225,6 +225,7 @@ public class DomainBaseToXjcConverterTest {
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setDomain(domain)
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build());
|
||||
BillingEvent.OneTime billingEvent =
|
||||
persistResource(
|
||||
|
||||
@@ -66,7 +66,13 @@ final class RdeFixtures {
|
||||
.createVKey())
|
||||
.build();
|
||||
HistoryEntry historyEntry =
|
||||
persistResource(new HistoryEntry.Builder().setParent(domain).build());
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setClientId("TheRegistrar")
|
||||
.build());
|
||||
clock.advanceOneMilli();
|
||||
BillingEvent.OneTime billingEvent =
|
||||
persistResourceWithCommitLog(
|
||||
|
||||
@@ -545,6 +545,7 @@ public class DatabaseHelper {
|
||||
.setType(HistoryEntry.Type.CONTACT_TRANSFER_REQUEST)
|
||||
.setParent(persistResource(contact))
|
||||
.setModificationTime(now)
|
||||
.setClientId(contact.getCurrentSponsorClientId())
|
||||
.build()
|
||||
.toChildHistoryEntity());
|
||||
return persistResource(
|
||||
@@ -616,6 +617,7 @@ public class DatabaseHelper {
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(now)
|
||||
.setDomain(domain)
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build());
|
||||
BillingEvent.Recurring autorenewEvent =
|
||||
persistResource(
|
||||
@@ -657,6 +659,7 @@ public class DatabaseHelper {
|
||||
.setType(HistoryEntry.Type.DOMAIN_TRANSFER_REQUEST)
|
||||
.setModificationTime(tm().transact(() -> tm().getTransactionTime()))
|
||||
.setDomain(domain)
|
||||
.setClientId("TheRegistrar")
|
||||
.build());
|
||||
BillingEvent.OneTime transferBillingEvent =
|
||||
persistResource(
|
||||
@@ -1085,7 +1088,7 @@ public class DatabaseHelper {
|
||||
tm().put(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(resource)
|
||||
.setClientId(resource.getPersistedCurrentSponsorClientId())
|
||||
.setClientId(resource.getCreationClientId())
|
||||
.setType(getHistoryEntryType(resource))
|
||||
.setModificationTime(tm().getTransactionTime())
|
||||
.build()
|
||||
|
||||
@@ -62,6 +62,7 @@ public class AckPollMessagesCommandTest extends CommandTestCase<AckPollMessagesC
|
||||
new DomainHistory.Builder()
|
||||
.setModificationTime(clock.nowUtc())
|
||||
.setDomainRepoId(domain.getRepoId())
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setId(2406L)
|
||||
.build());
|
||||
|
||||
@@ -1,258 +0,0 @@
|
||||
// Copyright 2020 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.model.ofy.ObjectifyService.auditedOfy;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.loadByEntity;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.googlecode.objectify.Key;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Flag;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
import google.registry.model.domain.DomainBase;
|
||||
import google.registry.model.domain.GracePeriod;
|
||||
import google.registry.model.domain.rgp.GracePeriodStatus;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.transfer.DomainTransferData;
|
||||
import java.util.Arrays;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link DedupeRecurringBillingEventIdsCommand}. */
|
||||
class DedupeRecurringBillingEventIdsCommandTest
|
||||
extends CommandTestCase<DedupeRecurringBillingEventIdsCommand> {
|
||||
|
||||
private final DateTime now = DateTime.now(UTC);
|
||||
private DomainBase domain1;
|
||||
private DomainBase domain2;
|
||||
private HistoryEntry historyEntry1;
|
||||
private HistoryEntry historyEntry2;
|
||||
private BillingEvent.Recurring recurring1;
|
||||
private BillingEvent.Recurring recurring2;
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
createTld("tld");
|
||||
domain1 = persistActiveDomain("foo.tld");
|
||||
domain2 = persistActiveDomain("bar.tld");
|
||||
historyEntry1 =
|
||||
persistResource(
|
||||
new HistoryEntry.Builder().setParent(domain1).setModificationTime(now).build());
|
||||
historyEntry2 =
|
||||
persistResource(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domain2)
|
||||
.setModificationTime(now.plusDays(1))
|
||||
.build());
|
||||
recurring1 =
|
||||
persistResource(
|
||||
new BillingEvent.Recurring.Builder()
|
||||
.setParent(historyEntry1)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setReason(Reason.RENEW)
|
||||
.setEventTime(now.plusYears(1))
|
||||
.setRecurrenceEndTime(END_OF_TIME)
|
||||
.setClientId("a registrar")
|
||||
.setTargetId("foo.tld")
|
||||
.build());
|
||||
recurring2 =
|
||||
persistResource(
|
||||
new BillingEvent.Recurring.Builder()
|
||||
.setId(recurring1.getId())
|
||||
.setParent(historyEntry2)
|
||||
.setFlags(ImmutableSet.of(Flag.AUTO_RENEW))
|
||||
.setReason(Reason.RENEW)
|
||||
.setEventTime(now.plusYears(1))
|
||||
.setRecurrenceEndTime(END_OF_TIME)
|
||||
.setClientId("a registrar")
|
||||
.setTargetId("bar.tld")
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOnlyResaveBillingEventsCorrectly() throws Exception {
|
||||
assertThat(recurring1.getId()).isEqualTo(recurring2.getId());
|
||||
|
||||
runCommand(
|
||||
"--force",
|
||||
"--key_paths_file",
|
||||
writeToNamedTmpFile("keypath.txt", getKeyPathLiteral(recurring1, recurring2)));
|
||||
|
||||
assertNotChangeExceptUpdateTime(domain1, domain2, historyEntry1, historyEntry2);
|
||||
assertNotInDatastore(recurring1, recurring2);
|
||||
|
||||
ImmutableList<BillingEvent.Recurring> recurrings = loadAllRecurrings();
|
||||
assertThat(recurrings.size()).isEqualTo(2);
|
||||
|
||||
recurrings.forEach(
|
||||
newRecurring -> {
|
||||
if (newRecurring.getTargetId().equals("foo.tld")) {
|
||||
assertSameRecurringEntityExceptId(newRecurring, recurring1);
|
||||
} else if (newRecurring.getTargetId().equals("bar.tld")) {
|
||||
assertSameRecurringEntityExceptId(newRecurring, recurring2);
|
||||
} else {
|
||||
fail("Unknown BillingEvent.Recurring entity: " + newRecurring.createVKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResaveAssociatedDomainAndOneTimeBillingEventCorrectly() throws Exception {
|
||||
assertThat(recurring1.getId()).isEqualTo(recurring2.getId());
|
||||
GracePeriod gracePeriod =
|
||||
GracePeriod.createForRecurring(
|
||||
GracePeriodStatus.AUTO_RENEW,
|
||||
domain1.getRepoId(),
|
||||
now.plusDays(45),
|
||||
"a registrar",
|
||||
recurring1.createVKey());
|
||||
domain1 =
|
||||
persistResource(
|
||||
domain1
|
||||
.asBuilder()
|
||||
.setAutorenewBillingEvent(recurring1.createVKey())
|
||||
.setGracePeriods(ImmutableSet.of(gracePeriod))
|
||||
.setTransferData(
|
||||
new DomainTransferData.Builder()
|
||||
.setServerApproveAutorenewEvent(recurring1.createVKey())
|
||||
.setServerApproveEntities(ImmutableSet.of(recurring1.createVKey()))
|
||||
.build())
|
||||
.build());
|
||||
|
||||
BillingEvent.OneTime oneTime =
|
||||
persistResource(
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setClientId("a registrar")
|
||||
.setTargetId("foo.tld")
|
||||
.setParent(historyEntry1)
|
||||
.setReason(Reason.CREATE)
|
||||
.setFlags(ImmutableSet.of(Flag.SYNTHETIC))
|
||||
.setSyntheticCreationTime(now)
|
||||
.setPeriodYears(2)
|
||||
.setCost(Money.of(USD, 1))
|
||||
.setEventTime(now)
|
||||
.setBillingTime(now.plusDays(5))
|
||||
.setCancellationMatchingBillingEvent(recurring1.createVKey())
|
||||
.build());
|
||||
|
||||
runCommand(
|
||||
"--force",
|
||||
"--key_paths_file",
|
||||
writeToNamedTmpFile("keypath.txt", getKeyPathLiteral(recurring1, recurring2)));
|
||||
|
||||
assertNotChangeExceptUpdateTime(domain2, historyEntry1, historyEntry2);
|
||||
assertNotInDatastore(recurring1, recurring2);
|
||||
ImmutableList<BillingEvent.Recurring> recurrings = loadAllRecurrings();
|
||||
assertThat(recurrings.size()).isEqualTo(2);
|
||||
|
||||
recurrings.forEach(
|
||||
newRecurring -> {
|
||||
if (newRecurring.getTargetId().equals("foo.tld")) {
|
||||
assertSameRecurringEntityExceptId(newRecurring, recurring1);
|
||||
|
||||
BillingEvent.OneTime persistedOneTime = auditedOfy().load().entity(oneTime).now();
|
||||
assertAboutImmutableObjects()
|
||||
.that(persistedOneTime)
|
||||
.isEqualExceptFields(oneTime, "cancellationMatchingBillingEvent");
|
||||
assertThat(persistedOneTime.getCancellationMatchingBillingEvent())
|
||||
.isEqualTo(newRecurring.createVKey());
|
||||
|
||||
DomainBase persistedDomain = auditedOfy().load().entity(domain1).now();
|
||||
assertAboutImmutableObjects()
|
||||
.that(persistedDomain)
|
||||
.isEqualExceptFields(
|
||||
domain1,
|
||||
"updateTimestamp",
|
||||
"revisions",
|
||||
"gracePeriods",
|
||||
"transferData",
|
||||
"autorenewBillingEvent");
|
||||
assertThat(persistedDomain.getAutorenewBillingEvent())
|
||||
.isEqualTo(newRecurring.createVKey());
|
||||
assertThat(persistedDomain.getGracePeriods())
|
||||
.containsExactly(
|
||||
GracePeriod.createForRecurring(
|
||||
GracePeriodStatus.AUTO_RENEW,
|
||||
domain1.getRepoId(),
|
||||
now.plusDays(45),
|
||||
"a registrar",
|
||||
newRecurring.createVKey(),
|
||||
gracePeriod.getGracePeriodId()));
|
||||
assertThat(persistedDomain.getTransferData().getServerApproveAutorenewEvent())
|
||||
.isEqualTo(newRecurring.createVKey());
|
||||
assertThat(persistedDomain.getTransferData().getServerApproveEntities())
|
||||
.containsExactly(newRecurring.createVKey());
|
||||
|
||||
} else if (newRecurring.getTargetId().equals("bar.tld")) {
|
||||
assertSameRecurringEntityExceptId(newRecurring, recurring2);
|
||||
} else {
|
||||
fail("Unknown BillingEvent.Recurring entity: " + newRecurring.createVKey());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void assertNotInDatastore(ImmutableObject... entities) {
|
||||
for (ImmutableObject entity : entities) {
|
||||
assertThat(auditedOfy().load().entity(entity).now()).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertNotChangeExceptUpdateTime(ImmutableObject... entities) {
|
||||
for (ImmutableObject entity : entities) {
|
||||
assertAboutImmutableObjects()
|
||||
.that(loadByEntity(entity))
|
||||
.isEqualExceptFields(entity, "updateTimestamp", "revisions");
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertSameRecurringEntityExceptId(
|
||||
BillingEvent.Recurring recurring1, BillingEvent.Recurring recurring2) {
|
||||
assertAboutImmutableObjects().that(recurring1).isEqualExceptFields(recurring2, "id");
|
||||
}
|
||||
|
||||
private static ImmutableList<BillingEvent.Recurring> loadAllRecurrings() {
|
||||
return ImmutableList.copyOf(auditedOfy().load().type(BillingEvent.Recurring.class));
|
||||
}
|
||||
|
||||
private static String getKeyPathLiteral(Object... entities) {
|
||||
return Arrays.stream(entities)
|
||||
.map(
|
||||
entity -> {
|
||||
Key<?> key = Key.create(entity);
|
||||
return String.format(
|
||||
"\"DomainBase\", \"%s\", \"HistoryEntry\", %s, \"%s\", %s",
|
||||
key.getParent().getParent().getName(),
|
||||
key.getParent().getId(),
|
||||
key.getKind(),
|
||||
key.getId());
|
||||
})
|
||||
.reduce((k1, k2) -> k1 + "\n" + k2)
|
||||
.get();
|
||||
}
|
||||
}
|
||||
@@ -299,6 +299,7 @@ class UpdateDomainCommandTest extends EppToolCommandTestCase<UpdateDomainCommand
|
||||
.setModificationTime(fakeClock.nowUtc())
|
||||
.setType(DOMAIN_CREATE)
|
||||
.setDomain(domain)
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build());
|
||||
BillingEvent.Recurring autorenewBillingEvent =
|
||||
persistResource(
|
||||
|
||||
@@ -31,6 +31,7 @@ import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import com.google.appengine.api.datastore.Entity;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
@@ -82,47 +83,65 @@ class KillAllEppResourcesActionTest extends MapreduceTestCase<KillAllEppResource
|
||||
executeTasksUntilEmpty("mapreduce");
|
||||
}
|
||||
|
||||
private static final ImmutableMap<Class<? extends EppResource>, HistoryEntry.Type>
|
||||
HISTORY_ENTRY_CREATE_TYPES =
|
||||
ImmutableMap.of(
|
||||
DomainBase.class,
|
||||
HistoryEntry.Type.DOMAIN_CREATE,
|
||||
ContactResource.class,
|
||||
HistoryEntry.Type.CONTACT_CREATE,
|
||||
HostResource.class,
|
||||
HistoryEntry.Type.HOST_CREATE);
|
||||
|
||||
@Test
|
||||
void testKill() throws Exception {
|
||||
createTld("tld1");
|
||||
createTld("tld2");
|
||||
for (EppResource resource : asList(
|
||||
persistActiveDomain("foo.tld1"),
|
||||
persistActiveDomain("foo.tld2"),
|
||||
persistActiveContact("foo"),
|
||||
persistActiveContact("foo"),
|
||||
persistActiveHost("ns.foo.tld1"),
|
||||
persistActiveHost("ns.foo.tld2"))) {
|
||||
HistoryEntry history = new HistoryEntry.Builder().setParent(resource).build();
|
||||
for (ImmutableObject descendant : asList(
|
||||
history,
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setParent(history)
|
||||
.setClientId("")
|
||||
.setEventTime(START_OF_TIME)
|
||||
.build(),
|
||||
new PollMessage.Autorenew.Builder()
|
||||
.setParent(history)
|
||||
.setClientId("")
|
||||
.setEventTime(START_OF_TIME)
|
||||
.build(),
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setParent(history)
|
||||
.setBillingTime(START_OF_TIME)
|
||||
.setEventTime(START_OF_TIME)
|
||||
.setClientId("")
|
||||
.setTargetId("")
|
||||
.setReason(Reason.CREATE)
|
||||
.setPeriodYears(1)
|
||||
.setCost(Money.of(CurrencyUnit.USD, 1))
|
||||
.build(),
|
||||
new BillingEvent.Recurring.Builder()
|
||||
.setParent(history)
|
||||
.setEventTime(START_OF_TIME)
|
||||
.setClientId("")
|
||||
.setTargetId("")
|
||||
.setReason(Reason.RENEW)
|
||||
.build())) {
|
||||
for (EppResource resource :
|
||||
asList(
|
||||
persistActiveDomain("foo.tld1"),
|
||||
persistActiveDomain("foo.tld2"),
|
||||
persistActiveContact("foo"),
|
||||
persistActiveContact("foo"),
|
||||
persistActiveHost("ns.foo.tld1"),
|
||||
persistActiveHost("ns.foo.tld2"))) {
|
||||
HistoryEntry history =
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(resource)
|
||||
.setClientId(resource.getCreationClientId())
|
||||
.setModificationTime(resource.getCreationTime())
|
||||
.setType(HISTORY_ENTRY_CREATE_TYPES.get(resource.getClass()))
|
||||
.build();
|
||||
for (ImmutableObject descendant :
|
||||
asList(
|
||||
history,
|
||||
new PollMessage.OneTime.Builder()
|
||||
.setParent(history)
|
||||
.setClientId("")
|
||||
.setEventTime(START_OF_TIME)
|
||||
.build(),
|
||||
new PollMessage.Autorenew.Builder()
|
||||
.setParent(history)
|
||||
.setClientId("")
|
||||
.setEventTime(START_OF_TIME)
|
||||
.build(),
|
||||
new BillingEvent.OneTime.Builder()
|
||||
.setParent(history)
|
||||
.setBillingTime(START_OF_TIME)
|
||||
.setEventTime(START_OF_TIME)
|
||||
.setClientId("")
|
||||
.setTargetId("")
|
||||
.setReason(Reason.CREATE)
|
||||
.setPeriodYears(1)
|
||||
.setCost(Money.of(CurrencyUnit.USD, 1))
|
||||
.build(),
|
||||
new BillingEvent.Recurring.Builder()
|
||||
.setParent(history)
|
||||
.setEventTime(START_OF_TIME)
|
||||
.setClientId("")
|
||||
.setTargetId("")
|
||||
.setReason(Reason.RENEW)
|
||||
.build())) {
|
||||
persistResource(descendant);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,25 @@ class ResaveAllHistoryEntriesActionTest extends MapreduceTestCase<ResaveAllHisto
|
||||
DomainBase domain = persistActiveDomain("test.tld");
|
||||
ContactResource contact = persistActiveContact("humanBeing");
|
||||
Entity domainEntry =
|
||||
auditedOfy().save().toEntity(new HistoryEntry.Builder().setParent(domain).build());
|
||||
auditedOfy()
|
||||
.save()
|
||||
.toEntity(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(domain)
|
||||
.setType(HistoryEntry.Type.DOMAIN_CREATE)
|
||||
.setModificationTime(domain.getCreationTime())
|
||||
.setClientId(domain.getCreationClientId())
|
||||
.build());
|
||||
Entity contactEntry =
|
||||
auditedOfy().save().toEntity(new HistoryEntry.Builder().setParent(contact).build());
|
||||
auditedOfy()
|
||||
.save()
|
||||
.toEntity(
|
||||
new HistoryEntry.Builder()
|
||||
.setParent(contact)
|
||||
.setType(HistoryEntry.Type.CONTACT_CREATE)
|
||||
.setClientId(contact.getCreationClientId())
|
||||
.setModificationTime(contact.getCreationTime())
|
||||
.build());
|
||||
|
||||
// Set raw properties outside the Objectify schema, which will be deleted upon re-save.
|
||||
domainEntry.setProperty("clientId", "validId");
|
||||
|
||||
Reference in New Issue
Block a user