mirror of
https://github.com/google/nomulus.git
synced 2025-08-16 14:34:05 +02:00
Create a DnsRefreshRequest entity backed by the corresponding table (#1941)
Also adds a DnsUtils class to deal with adding, polling, and removing DNS refresh requests (only adding is implemented for now). The class also takes care of choosing which mechanism to use (pull queue vs. SQL) based on the current time and the database migration schedule map.
This commit is contained in:
parent
8ce47b9e0e
commit
3d809e762b
38 changed files with 760 additions and 231 deletions
|
@ -27,14 +27,14 @@ import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
|
|||
import static google.registry.testing.DatabaseHelper.persistDomainAsDeleted;
|
||||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.testing.DatabaseHelper.persistSimpleResource;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.config.RegistryEnvironment;
|
||||
import google.registry.dns.DnsQueue;
|
||||
import google.registry.dns.DnsUtils;
|
||||
import google.registry.model.ImmutableObject;
|
||||
import google.registry.model.billing.BillingEvent;
|
||||
import google.registry.model.billing.BillingEvent.Reason;
|
||||
|
@ -47,9 +47,8 @@ import google.registry.model.tld.Registry.TldType;
|
|||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.DnsUtilsHelper;
|
||||
import google.registry.testing.SystemPropertyExtension;
|
||||
import google.registry.testing.TaskQueueExtension;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import org.joda.money.Money;
|
||||
|
@ -68,13 +67,14 @@ class DeleteProberDataActionTest {
|
|||
final JpaIntegrationTestExtension jpa =
|
||||
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
|
||||
|
||||
@RegisterExtension TaskQueueExtension taskQueue = new TaskQueueExtension();
|
||||
|
||||
@RegisterExtension
|
||||
final SystemPropertyExtension systemPropertyExtension = new SystemPropertyExtension();
|
||||
|
||||
private DeleteProberDataAction action;
|
||||
|
||||
private final DnsUtils dnsUtils = mock(DnsUtils.class);
|
||||
private final DnsUtilsHelper dnsUtilsHelper = new DnsUtilsHelper(dnsUtils);
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
// Entities in these two should not be touched.
|
||||
|
@ -99,7 +99,7 @@ class DeleteProberDataActionTest {
|
|||
|
||||
private void resetAction() {
|
||||
action = new DeleteProberDataAction();
|
||||
action.dnsQueue = DnsQueue.createForTesting(new FakeClock());
|
||||
action.dnsUtils = dnsUtils;
|
||||
action.isDryRun = false;
|
||||
action.tlds = ImmutableSet.of();
|
||||
action.registryAdminRegistrarId = "TheRegistrar";
|
||||
|
@ -201,7 +201,7 @@ class DeleteProberDataActionTest {
|
|||
DateTime timeAfterDeletion = DateTime.now(UTC);
|
||||
assertThat(loadByForeignKey(Domain.class, "blah.ib-any.test", timeAfterDeletion)).isEmpty();
|
||||
assertThat(loadByEntity(domain).getDeletionTime()).isLessThan(timeAfterDeletion);
|
||||
assertDnsTasksEnqueued("blah.ib-any.test");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("blah.ib-any.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -218,7 +218,7 @@ class DeleteProberDataActionTest {
|
|||
action.run();
|
||||
assertThat(loadByForeignKey(Domain.class, "blah.ib-any.test", timeAfterDeletion)).isEmpty();
|
||||
assertThat(loadByEntity(domain).getDeletionTime()).isLessThan(timeAfterDeletion);
|
||||
assertDnsTasksEnqueued("blah.ib-any.test");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("blah.ib-any.test");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
170
core/src/test/java/google/registry/dns/DnsUtilsTest.java
Normal file
170
core/src/test/java/google/registry/dns/DnsUtilsTest.java
Normal file
|
@ -0,0 +1,170 @@
|
|||
// Copyright 2023 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.dns;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.persistence.transaction.TransactionManagerFactory.tm;
|
||||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.loadAllOf;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Ordering;
|
||||
import google.registry.dns.DnsConstants.TargetType;
|
||||
import google.registry.model.common.DatabaseMigrationStateSchedule;
|
||||
import google.registry.model.common.DatabaseMigrationStateSchedule.MigrationState;
|
||||
import google.registry.model.common.DnsRefreshRequest;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link DnsUtils}. */
|
||||
public class DnsUtilsTest {
|
||||
|
||||
private static final String tld = "tld";
|
||||
private static final String domainName = "test.tld";
|
||||
private static final String hostName = "ns1.test.tld";
|
||||
|
||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||
private final DnsUtils dnsUtils = new DnsUtils(dnsQueue);
|
||||
|
||||
FakeClock clock = new FakeClock(DateTime.parse("2020-02-02T01:23:45Z"));
|
||||
|
||||
@RegisterExtension
|
||||
JpaIntegrationTestExtension jpa =
|
||||
new JpaTestExtensions.Builder().withClock(clock).buildIntegrationTestExtension();
|
||||
|
||||
@BeforeAll
|
||||
static void beforeAll() {
|
||||
DatabaseMigrationStateSchedule.useUncachedForTest();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
createTld(tld);
|
||||
when(dnsQueue.getClock()).thenReturn(clock);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_hostRefresh_pullQueue() {
|
||||
dnsUtils.requestHostDnsRefresh(hostName);
|
||||
verify(dnsQueue).addHostRefreshTask(hostName);
|
||||
assertThat(loadAllOf(DnsRefreshRequest.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_domainRefresh_pullQueue() {
|
||||
dnsUtils.requestDomainDnsRefresh(domainName);
|
||||
verify(dnsQueue).addDomainRefreshTask(domainName, Duration.ZERO);
|
||||
assertThat(loadAllOf(DnsRefreshRequest.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_domainRefreshWithDelay_pullQueue() {
|
||||
dnsUtils.requestDomainDnsRefresh(domainName, Duration.standardMinutes(3));
|
||||
verify(dnsQueue).addDomainRefreshTask(domainName, Duration.standardMinutes(3));
|
||||
assertThat(loadAllOf(DnsRefreshRequest.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_hostRefresh_unmanagedHost() {
|
||||
String unmanagedHostName = "ns1.another.example";
|
||||
Assertions.assertThrows(
|
||||
IllegalArgumentException.class, () -> dnsUtils.requestHostDnsRefresh(unmanagedHostName));
|
||||
verify(dnsQueue, never()).addHostRefreshTask(anyString());
|
||||
assertThat(loadAllOf(DnsRefreshRequest.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_domainRefresh_unmanagedDomain() {
|
||||
String unmanagedDomainName = "another.example";
|
||||
Assertions.assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> dnsUtils.requestDomainDnsRefresh(unmanagedDomainName));
|
||||
verify(dnsQueue, never()).addDomainRefreshTask(anyString(), any(Duration.class));
|
||||
assertThat(loadAllOf(DnsRefreshRequest.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_hostRefresh() {
|
||||
useDnsSql();
|
||||
dnsUtils.requestHostDnsRefresh(hostName);
|
||||
verify(dnsQueue, never()).addHostRefreshTask(anyString());
|
||||
DnsRefreshRequest request = Iterables.getOnlyElement(loadAllOf(DnsRefreshRequest.class));
|
||||
assertRequest(request, TargetType.HOST, hostName, tld, clock.nowUtc());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_domainRefresh() {
|
||||
useDnsSql();
|
||||
dnsUtils.requestDomainDnsRefresh(domainName);
|
||||
verify(dnsQueue, never()).addDomainRefreshTask(anyString(), any(Duration.class));
|
||||
DnsRefreshRequest request = Iterables.getOnlyElement(loadAllOf(DnsRefreshRequest.class));
|
||||
assertRequest(request, TargetType.DOMAIN, domainName, tld, clock.nowUtc());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_domainRefreshWithDelay() {
|
||||
useDnsSql();
|
||||
dnsUtils.requestDomainDnsRefresh(domainName, Duration.standardMinutes(3));
|
||||
verify(dnsQueue, never()).addDomainRefreshTask(anyString(), any(Duration.class));
|
||||
DnsRefreshRequest request = Iterables.getOnlyElement(loadAllOf(DnsRefreshRequest.class));
|
||||
assertRequest(request, TargetType.DOMAIN, domainName, tld, clock.nowUtc().plusMinutes(3));
|
||||
}
|
||||
|
||||
private static void assertRequest(
|
||||
DnsRefreshRequest request, TargetType type, String name, String tld, DateTime requestTime) {
|
||||
assertThat(request.getType()).isEqualTo(type);
|
||||
assertThat(request.getName()).isEqualTo(name);
|
||||
assertThat(request.getTld()).isEqualTo(tld);
|
||||
assertThat(request.getRequestTime()).isEqualTo(requestTime);
|
||||
}
|
||||
|
||||
private void useDnsSql() {
|
||||
DateTime currentTime = clock.nowUtc();
|
||||
clock.setTo(START_OF_TIME);
|
||||
tm().transact(
|
||||
() ->
|
||||
DatabaseMigrationStateSchedule.set(
|
||||
new ImmutableSortedMap.Builder<DateTime, MigrationState>(Ordering.natural())
|
||||
.put(START_OF_TIME, MigrationState.DATASTORE_ONLY)
|
||||
.put(START_OF_TIME.plusMillis(1), MigrationState.DATASTORE_PRIMARY)
|
||||
.put(START_OF_TIME.plusMillis(2), MigrationState.DATASTORE_PRIMARY_NO_ASYNC)
|
||||
.put(
|
||||
START_OF_TIME.plusMillis(3), MigrationState.DATASTORE_PRIMARY_READ_ONLY)
|
||||
.put(START_OF_TIME.plusMillis(4), MigrationState.SQL_PRIMARY_READ_ONLY)
|
||||
.put(START_OF_TIME.plusMillis(5), MigrationState.SQL_PRIMARY)
|
||||
.put(START_OF_TIME.plusMillis(6), MigrationState.SQL_ONLY)
|
||||
.put(START_OF_TIME.plusMillis(7), MigrationState.SEQUENCE_BASED_ALLOCATE_ID)
|
||||
.put(START_OF_TIME.plusMillis(8), MigrationState.NORDN_SQL)
|
||||
.put(START_OF_TIME.plusMillis(9), MigrationState.DNS_SQL)
|
||||
.build()));
|
||||
clock.setTo(currentTime);
|
||||
}
|
||||
}
|
|
@ -54,6 +54,7 @@ import google.registry.request.HttpException.ServiceUnavailableException;
|
|||
import google.registry.request.lock.LockHandler;
|
||||
import google.registry.testing.CloudTasksHelper;
|
||||
import google.registry.testing.CloudTasksHelper.TaskMatcher;
|
||||
import google.registry.testing.DnsUtilsHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeLockHandler;
|
||||
import google.registry.testing.FakeResponse;
|
||||
|
@ -82,7 +83,8 @@ public class PublishDnsUpdatesActionTest {
|
|||
private final FakeLockHandler lockHandler = new FakeLockHandler(true);
|
||||
private final DnsWriter dnsWriter = mock(DnsWriter.class);
|
||||
private final DnsMetrics dnsMetrics = mock(DnsMetrics.class);
|
||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||
private final DnsUtils dnsUtils = mock(DnsUtils.class);
|
||||
private final DnsUtilsHelper dnsUtilsHelper = new DnsUtilsHelper(dnsUtils);
|
||||
private final CloudTasksHelper cloudTasksHelper = new CloudTasksHelper();
|
||||
private PublishDnsUpdatesAction action;
|
||||
private InternetAddress outgoingRegistry;
|
||||
|
@ -162,7 +164,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
outgoingRegistry,
|
||||
Optional.ofNullable(retryCount),
|
||||
Optional.empty(),
|
||||
dnsQueue,
|
||||
dnsUtils,
|
||||
new DnsWriterProxy(ImmutableMap.of("correctWriter", dnsWriter)),
|
||||
dnsMetrics,
|
||||
lockHandler,
|
||||
|
@ -196,7 +198,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||
}
|
||||
|
||||
|
@ -223,7 +225,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||
}
|
||||
|
||||
|
@ -276,7 +278,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -496,7 +498,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -526,7 +528,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -554,7 +556,7 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -580,9 +582,9 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verify(dnsQueue).addDomainRefreshTask("example.com");
|
||||
verify(dnsQueue).addHostRefreshTask("ns1.example.com");
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.com");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.com");
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -608,9 +610,9 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verify(dnsQueue).addDomainRefreshTask("example.com");
|
||||
verify(dnsQueue).addHostRefreshTask("ns1.example.com");
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.com");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.com");
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -632,11 +634,11 @@ public class PublishDnsUpdatesActionTest {
|
|||
Duration.standardHours(2),
|
||||
Duration.standardHours(1));
|
||||
verifyNoMoreInteractions(dnsMetrics);
|
||||
verify(dnsQueue).addDomainRefreshTask("example.com");
|
||||
verify(dnsQueue).addDomainRefreshTask("example2.com");
|
||||
verify(dnsQueue).addHostRefreshTask("ns1.example.com");
|
||||
verify(dnsQueue).addHostRefreshTask("ns2.example.com");
|
||||
verify(dnsQueue).addHostRefreshTask("ns1.example2.com");
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.com");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example2.com");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.com");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns2.example.com");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example2.com");
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -388,21 +388,6 @@ public class ReadDnsQueueActionTest {
|
|||
ImmutableMultimap.of("com", "comWriter", "example", "exampleWriter"));
|
||||
}
|
||||
|
||||
@RetryingTest(4)
|
||||
void testSuccess_zone_getsIgnored() {
|
||||
dnsQueue.addHostRefreshTask("ns1.domain.com");
|
||||
dnsQueue.addDomainRefreshTask("domain.net");
|
||||
dnsQueue.addZoneRefreshTask("example");
|
||||
|
||||
run();
|
||||
|
||||
TaskQueueHelper.assertNoTasksEnqueued(DNS_PULL_QUEUE_NAME);
|
||||
cloudTasksHelper.assertTasksEnqueued(
|
||||
DNS_PUBLISH_PUSH_QUEUE_NAME,
|
||||
new TaskMatcher().url(PublishDnsUpdatesAction.PATH).param("domains", "domain.net"),
|
||||
new TaskMatcher().url(PublishDnsUpdatesAction.PATH).param("hosts", "ns1.domain.com"));
|
||||
}
|
||||
|
||||
private static String makeCommaSeparatedRange(int from, int to, String format) {
|
||||
return IntStream.range(from, to)
|
||||
.mapToObj(i -> String.format(format, i))
|
||||
|
|
|
@ -21,8 +21,6 @@ import static google.registry.testing.DatabaseHelper.persistActiveHost;
|
|||
import static google.registry.testing.DatabaseHelper.persistActiveSubordinateHost;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import google.registry.dns.DnsConstants.TargetType;
|
||||
import google.registry.model.domain.Domain;
|
||||
|
@ -30,6 +28,7 @@ import google.registry.persistence.transaction.JpaTestExtensions;
|
|||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import google.registry.request.HttpException.BadRequestException;
|
||||
import google.registry.request.HttpException.NotFoundException;
|
||||
import google.registry.testing.DnsUtilsHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -42,11 +41,12 @@ public class RefreshDnsActionTest {
|
|||
final JpaIntegrationTestExtension jpa =
|
||||
new JpaTestExtensions.Builder().buildIntegrationTestExtension();
|
||||
|
||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||
private final DnsUtils dnsUtils = mock(DnsUtils.class);
|
||||
private final DnsUtilsHelper dnsUtilsHelper = new DnsUtilsHelper(dnsUtils);
|
||||
private final FakeClock clock = new FakeClock();
|
||||
|
||||
private void run(TargetType type, String name) {
|
||||
new RefreshDnsAction(name, type, clock, dnsQueue).run();
|
||||
new RefreshDnsAction(name, type, clock, dnsUtils).run();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
@ -59,8 +59,8 @@ public class RefreshDnsActionTest {
|
|||
Domain domain = persistActiveDomain("example.xn--q9jyb4c");
|
||||
persistActiveSubordinateHost("ns1.example.xn--q9jyb4c", domain);
|
||||
run(TargetType.HOST, "ns1.example.xn--q9jyb4c");
|
||||
verify(dnsQueue).addHostRefreshTask("ns1.example.xn--q9jyb4c");
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.xn--q9jyb4c");
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -74,7 +74,7 @@ public class RefreshDnsActionTest {
|
|||
try {
|
||||
run(TargetType.HOST, "ns1.example.xn--q9jyb4c");
|
||||
} finally {
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
});
|
||||
assertThat(thrown)
|
||||
|
@ -86,8 +86,8 @@ public class RefreshDnsActionTest {
|
|||
void testSuccess_domain() {
|
||||
persistActiveDomain("example.xn--q9jyb4c");
|
||||
run(TargetType.DOMAIN, "example.xn--q9jyb4c");
|
||||
verify(dnsQueue).addDomainRefreshTask("example.xn--q9jyb4c");
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.xn--q9jyb4c");
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,14 +24,13 @@ import static google.registry.testing.DatabaseHelper.persistResource;
|
|||
import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.model.eppcommon.StatusValue;
|
||||
import google.registry.model.host.Host;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import google.registry.testing.DnsUtilsHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -43,7 +42,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
|
|||
public class RefreshDnsOnHostRenameActionTest {
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("2015-01-15T11:22:33Z"));
|
||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||
private final DnsUtils dnsUtils = mock(DnsUtils.class);
|
||||
private final DnsUtilsHelper dnsUtilsHelper = new DnsUtilsHelper(dnsUtils);
|
||||
private final FakeResponse response = new FakeResponse();
|
||||
|
||||
@RegisterExtension
|
||||
|
@ -53,14 +53,7 @@ public class RefreshDnsOnHostRenameActionTest {
|
|||
private RefreshDnsOnHostRenameAction action;
|
||||
|
||||
private void createAction(String hostKey) {
|
||||
action = new RefreshDnsOnHostRenameAction(hostKey, response, dnsQueue);
|
||||
}
|
||||
|
||||
private void assertDnsTasksEnqueued(String... domains) {
|
||||
for (String domain : domains) {
|
||||
verify(dnsQueue).addDomainRefreshTask(domain);
|
||||
}
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
action = new RefreshDnsOnHostRenameAction(hostKey, response, dnsUtils);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
@ -82,7 +75,7 @@ public class RefreshDnsOnHostRenameActionTest {
|
|||
persistDomainAsDeleted(newDomain("deleted.tld", host), clock.nowUtc().minusDays(1));
|
||||
createAction(host.createVKey().stringify());
|
||||
action.run();
|
||||
assertDnsTasksEnqueued("example.tld", "otherexample.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld", "otherexample.tld");
|
||||
assertThat(response.getStatus()).isEqualTo(SC_OK);
|
||||
}
|
||||
|
||||
|
@ -90,7 +83,7 @@ public class RefreshDnsOnHostRenameActionTest {
|
|||
void testFailure_nonexistentHost() {
|
||||
createAction("kind:Host@sql:rO0ABXQABGJsYWg");
|
||||
action.run();
|
||||
assertDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||
assertThat(response.getPayload())
|
||||
.isEqualTo("Host to refresh does not exist: VKey<Host>(sql:blah)");
|
||||
|
@ -102,7 +95,7 @@ public class RefreshDnsOnHostRenameActionTest {
|
|||
persistResource(newDomain("example.tld", host));
|
||||
createAction(host.createVKey().stringify());
|
||||
action.run();
|
||||
assertDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
assertThat(response.getStatus()).isEqualTo(SC_NO_CONTENT);
|
||||
assertThat(response.getPayload())
|
||||
.isEqualTo("Host to refresh is already deleted: ns1.example.tld");
|
||||
|
|
|
@ -24,6 +24,7 @@ import google.registry.batch.CloudTasksUtils;
|
|||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.config.RegistryConfig.ConfigModule.TmchCaMode;
|
||||
import google.registry.dns.DnsQueue;
|
||||
import google.registry.dns.DnsUtils;
|
||||
import google.registry.flows.custom.CustomLogicFactory;
|
||||
import google.registry.flows.custom.TestCustomLogicFactory;
|
||||
import google.registry.flows.domain.DomainFlowTmchUtils;
|
||||
|
@ -31,6 +32,7 @@ import google.registry.monitoring.whitebox.EppMetric;
|
|||
import google.registry.request.RequestScope;
|
||||
import google.registry.request.lock.LockHandler;
|
||||
import google.registry.testing.CloudTasksHelper;
|
||||
import google.registry.testing.DnsUtilsHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeLockHandler;
|
||||
import google.registry.testing.FakeSleeper;
|
||||
|
@ -59,11 +61,16 @@ public interface EppTestComponent {
|
|||
private FakeLockHandler lockHandler;
|
||||
private Sleeper sleeper;
|
||||
private CloudTasksHelper cloudTasksHelper;
|
||||
private DnsUtilsHelper dnsUtilsHelper;
|
||||
|
||||
public CloudTasksHelper getCloudTasksHelper() {
|
||||
return cloudTasksHelper;
|
||||
}
|
||||
|
||||
public DnsUtilsHelper getDnsUtilsHelper() {
|
||||
return dnsUtilsHelper;
|
||||
}
|
||||
|
||||
public EppMetric.Builder getMetricBuilder() {
|
||||
return metricBuilder;
|
||||
}
|
||||
|
@ -82,6 +89,7 @@ public interface EppTestComponent {
|
|||
instance.metricBuilder = EppMetric.builderForRequest(clock);
|
||||
instance.lockHandler = new FakeLockHandler(true);
|
||||
instance.cloudTasksHelper = cloudTasksHelper;
|
||||
instance.dnsUtilsHelper = new DnsUtilsHelper();
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
@ -95,6 +103,11 @@ public interface EppTestComponent {
|
|||
return cloudTasksHelper.getTestCloudTasksUtils();
|
||||
}
|
||||
|
||||
@Provides
|
||||
DnsUtils provideDnsUtils() {
|
||||
return dnsUtilsHelper.getDnsUtils();
|
||||
}
|
||||
|
||||
@Provides
|
||||
Clock provideClock() {
|
||||
return clock;
|
||||
|
|
|
@ -45,6 +45,7 @@ import google.registry.persistence.transaction.JpaTestExtensions;
|
|||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import google.registry.testing.CloudTasksHelper;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.DnsUtilsHelper;
|
||||
import google.registry.testing.EppLoader;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeHttpSession;
|
||||
|
@ -84,6 +85,7 @@ public abstract class FlowTestCase<F extends Flow> {
|
|||
protected TransportCredentials credentials = new PasswordOnlyTransportCredentials();
|
||||
protected EppRequestSource eppRequestSource = EppRequestSource.UNIT_TEST;
|
||||
protected CloudTasksHelper cloudTasksHelper;
|
||||
protected DnsUtilsHelper dnsUtilsHelper;
|
||||
|
||||
private EppMetric.Builder eppMetricBuilder;
|
||||
|
||||
|
@ -216,6 +218,7 @@ public abstract class FlowTestCase<F extends Flow> {
|
|||
|
||||
FakesAndMocksModule fakesAndMocksModule = FakesAndMocksModule.create(clock);
|
||||
cloudTasksHelper = fakesAndMocksModule.getCloudTasksHelper();
|
||||
dnsUtilsHelper = fakesAndMocksModule.getDnsUtilsHelper();
|
||||
// Run the flow.
|
||||
return DaggerEppTestComponent.builder()
|
||||
.fakesAndMocksModule(fakesAndMocksModule)
|
||||
|
|
|
@ -54,8 +54,6 @@ import static google.registry.testing.DatabaseHelper.persistReservedList;
|
|||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.testing.DomainSubject.assertAboutDomains;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static google.registry.tmch.LordnTaskUtils.QUEUE_CLAIMS;
|
||||
|
@ -393,7 +391,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
GracePeriod.create(
|
||||
GracePeriodStatus.ADD, domain.getRepoId(), billingTime, "TheRegistrar", null),
|
||||
createBillingEvent));
|
||||
assertDnsTasksEnqueued(getUniqueIdFromCommand());
|
||||
dnsUtilsHelper.assertDomainDnsRequests(getUniqueIdFromCommand());
|
||||
}
|
||||
|
||||
private void assertNoLordn() throws Exception {
|
||||
|
@ -415,7 +413,9 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
.and()
|
||||
.hasLaunchNotice(null);
|
||||
if (DatabaseMigrationStateSchedule.getValueAtTime(clock.nowUtc())
|
||||
.equals(MigrationState.NORDN_SQL)) {
|
||||
.equals(MigrationState.NORDN_SQL)
|
||||
|| DatabaseMigrationStateSchedule.getValueAtTime(clock.nowUtc())
|
||||
.equals(MigrationState.DNS_SQL)) {
|
||||
assertAboutDomains().that(reloadResourceByForeignKey()).hasLordnPhase(LordnPhase.SUNRISE);
|
||||
} else {
|
||||
String expectedPayload =
|
||||
|
@ -441,8 +441,10 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
"tmch",
|
||||
DateTime.parse("2010-08-16T09:00:00.0Z"),
|
||||
DateTime.parse("2009-08-16T09:00:00.0Z")));
|
||||
if (DatabaseMigrationStateSchedule.getValueAtTime(clock.nowUtc())
|
||||
.equals(MigrationState.NORDN_SQL)) {
|
||||
if ((DatabaseMigrationStateSchedule.getValueAtTime(clock.nowUtc())
|
||||
.equals(MigrationState.NORDN_SQL)
|
||||
|| DatabaseMigrationStateSchedule.getValueAtTime(clock.nowUtc())
|
||||
.equals(MigrationState.DNS_SQL))) {
|
||||
assertAboutDomains().that(reloadResourceByForeignKey()).hasLordnPhase(LordnPhase.CLAIMS);
|
||||
} else {
|
||||
TaskMatcher task =
|
||||
|
@ -944,7 +946,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
persistContactsAndHosts("net");
|
||||
runFlowAssertResponse(loadFile("domain_create_response_idn_minna.xml"));
|
||||
assertSuccessfulCreate("xn--q9jyb4c", ImmutableSet.of());
|
||||
assertDnsTasksEnqueued("xn--abc-873b2e7eb1k8a4lpjvv.xn--q9jyb4c");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("xn--abc-873b2e7eb1k8a4lpjvv.xn--q9jyb4c");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -953,7 +955,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
persistContactsAndHosts();
|
||||
runFlowAssertResponse(
|
||||
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "example.tld")));
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -966,7 +968,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
assertAboutDomains()
|
||||
.that(reloadResourceByForeignKey())
|
||||
.hasRegistrationExpirationTime(clock.nowUtc().plusYears(1));
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -988,7 +990,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
persistContactsAndHosts();
|
||||
runFlowAssertResponse(loadFile("domain_create_response_claims.xml"));
|
||||
assertSuccessfulCreate("tld", ImmutableSet.of());
|
||||
assertDnsTasksEnqueued("example-one.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example-one.tld");
|
||||
assertClaimsLordn();
|
||||
}
|
||||
|
||||
|
@ -1021,7 +1023,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
persistContactsAndHosts();
|
||||
runFlowAssertResponse(loadFile("domain_create_response_claims.xml"));
|
||||
assertSuccessfulCreate("tld", ImmutableSet.of(RESERVED), allocationToken);
|
||||
assertDnsTasksEnqueued("example-one.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example-one.tld");
|
||||
assertClaimsLordn();
|
||||
assertAllocationTokenWasRedeemed("abcDEF23456");
|
||||
}
|
||||
|
@ -1034,7 +1036,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
runFlowAssertResponse(
|
||||
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "example.tld")));
|
||||
assertSuccessfulCreate("tld", ImmutableSet.of());
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1442,7 +1444,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
persistContactsAndHosts();
|
||||
runFlowAssertResponse(loadFile("domain_create_response_claims.xml"));
|
||||
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT), allocationToken);
|
||||
assertDnsTasksEnqueued("example-one.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example-one.tld");
|
||||
assertClaimsLordn();
|
||||
assertAllocationTokenWasRedeemed("abcDEF23456");
|
||||
}
|
||||
|
@ -1526,7 +1528,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
"EXPIRATION_TIME",
|
||||
SMD_VALID_TIME.plusYears(2).toString())));
|
||||
assertSuccessfulCreate("tld", ImmutableSet.of(ANCHOR_TENANT, SUNRISE), allocationToken);
|
||||
assertDnsTasksEnqueued("test-validate.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("test-validate.tld");
|
||||
assertSunriseLordn("test-validate.tld");
|
||||
assertAllocationTokenWasRedeemed("abcDEF23456");
|
||||
}
|
||||
|
@ -2128,7 +2130,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
assertSunriseLordn("test-and-validate.tld");
|
||||
|
||||
// Check for SERVER_HOLD status, no DNS tasks enqueued, and collision poll message.
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
Domain domain = reloadResourceByForeignKey();
|
||||
assertThat(domain.getStatusValues()).contains(SERVER_HOLD);
|
||||
assertPollMessagesWithCollisionOneTime(domain);
|
||||
|
@ -2145,7 +2147,7 @@ class DomainCreateFlowTest extends ResourceFlowTestCase<DomainCreateFlow, Domain
|
|||
loadFile("domain_create_response.xml", ImmutableMap.of("DOMAIN", "badcrash.tld")));
|
||||
|
||||
// Check for SERVER_HOLD status, no DNS tasks enqueued, and collision poll message.
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
Domain domain = reloadResourceByForeignKey();
|
||||
assertThat(domain.getStatusValues()).contains(SERVER_HOLD);
|
||||
assertPollMessagesWithCollisionOneTime(domain);
|
||||
|
|
|
@ -52,7 +52,6 @@ import static google.registry.testing.DatabaseHelper.persistResource;
|
|||
import static google.registry.testing.DomainSubject.assertAboutDomains;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
|
@ -101,20 +100,16 @@ import google.registry.model.transfer.TransferResponse;
|
|||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.testing.CloudTasksHelper.TaskMatcher;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.TaskQueueExtension;
|
||||
import java.util.Map;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link DomainDeleteFlow}. */
|
||||
class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain> {
|
||||
|
||||
@RegisterExtension final TaskQueueExtension taskQueue = new TaskQueueExtension();
|
||||
|
||||
private Domain domain;
|
||||
private DomainHistory earlierHistoryEntry;
|
||||
|
||||
|
@ -362,7 +357,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
|||
// The add grace period is for a billable action, so it should trigger a cancellation.
|
||||
assertAutorenewClosedAndCancellationCreatedFor(
|
||||
graceBillingEvent, getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE, DomainHistory.class));
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
// There should be no poll messages. The previous autorenew poll message should now be deleted.
|
||||
assertThat(getPollMessages("TheRegistrar")).isEmpty();
|
||||
}
|
||||
|
@ -752,7 +747,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
|||
.build());
|
||||
DateTime eventTime = clock.nowUtc();
|
||||
runFlowAssertResponse(loadFile("generic_success_response.xml"));
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
assertAutorenewClosedAndCancellationCreatedFor(
|
||||
graceBillingEvent,
|
||||
getOnlyHistoryEntryOfType(domain, DOMAIN_DELETE, DomainHistory.class),
|
||||
|
@ -770,7 +765,7 @@ class DomainDeleteFlowTest extends ResourceFlowTestCase<DomainDeleteFlow, Domain
|
|||
.build());
|
||||
clock.advanceOneMilli();
|
||||
runFlowAssertResponse(loadFile("domain_delete_response_pending.xml"));
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
assertOnlyBillingEventIsClosedAutorenew("TheRegistrar");
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import static google.registry.testing.DatabaseHelper.persistReservedList;
|
|||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.testing.DomainSubject.assertAboutDomains;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.EUR;
|
||||
|
@ -75,20 +74,16 @@ import google.registry.model.reporting.DomainTransactionRecord.TransactionReport
|
|||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.model.tld.Registry;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.TaskQueueExtension;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link DomainRestoreRequestFlow}. */
|
||||
class DomainRestoreRequestFlowTest extends ResourceFlowTestCase<DomainRestoreRequestFlow, Domain> {
|
||||
|
||||
@RegisterExtension final TaskQueueExtension taskQueue = new TaskQueueExtension();
|
||||
|
||||
private static final ImmutableMap<String, String> FEE_06_MAP =
|
||||
ImmutableMap.of("FEE_VERSION", "0.6", "FEE_NS", "fee", "CURRENCY", "USD");
|
||||
private static final ImmutableMap<String, String> FEE_11_MAP =
|
||||
|
@ -192,7 +187,7 @@ class DomainRestoreRequestFlowTest extends ResourceFlowTestCase<DomainRestoreReq
|
|||
.and()
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertThat(domain.getGracePeriods()).isEmpty();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
// The poll message for the delete should now be gone. The only poll message should be the new
|
||||
// autorenew poll message.
|
||||
assertPollMessages(
|
||||
|
@ -261,7 +256,7 @@ class DomainRestoreRequestFlowTest extends ResourceFlowTestCase<DomainRestoreReq
|
|||
.and()
|
||||
.hasLastEppUpdateRegistrarId("TheRegistrar");
|
||||
assertThat(domain.getGracePeriods()).isEmpty();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
// The poll message for the delete should now be gone. The only poll message should be the new
|
||||
// autorenew poll message.
|
||||
assertPollMessages(
|
||||
|
|
|
@ -46,8 +46,6 @@ import static google.registry.testing.DatabaseHelper.persistResource;
|
|||
import static google.registry.testing.DomainSubject.assertAboutDomains;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.money.CurrencyUnit.USD;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
@ -106,19 +104,15 @@ import google.registry.model.poll.PollMessage;
|
|||
import google.registry.model.tld.Registry;
|
||||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.TaskQueueExtension;
|
||||
import java.util.Optional;
|
||||
import org.joda.money.Money;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link DomainUpdateFlow}. */
|
||||
class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain> {
|
||||
|
||||
@RegisterExtension final TaskQueueExtension taskQueue = new TaskQueueExtension();
|
||||
|
||||
private static final DomainDsData SOME_DSDATA =
|
||||
DomainDsData.create(
|
||||
1,
|
||||
|
@ -222,7 +216,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
.and()
|
||||
.hasNoAutorenewEndTime();
|
||||
assertNoBillingEvents();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
assertLastHistoryContainsResource(reloadResourceByForeignKey());
|
||||
}
|
||||
|
||||
|
@ -351,7 +345,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
assertThat(domain.getContacts()).hasSize(3);
|
||||
assertThat(loadByKey(domain.getRegistrant()).getContactId()).isEqualTo("max_test_7");
|
||||
assertNoBillingEvents();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -502,9 +496,9 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
.map(ds -> ds.cloneWithDomainRepoId(resource.getRepoId()))
|
||||
.collect(toImmutableSet()));
|
||||
if (dnsTaskEnqueued) {
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
} else {
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1765,7 +1759,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
.setStatusValues(ImmutableSet.of(StatusValue.CLIENT_TRANSFER_PROHIBITED))
|
||||
.build());
|
||||
runFlowAsSuperuser();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1781,7 +1775,7 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
.setStatusValues(ImmutableSet.of(StatusValue.SERVER_HOLD))
|
||||
.build());
|
||||
runFlowAsSuperuser();
|
||||
assertDnsTasksEnqueued("example.tld");
|
||||
dnsUtilsHelper.assertDomainDnsRequests("example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1797,6 +1791,6 @@ class DomainUpdateFlowTest extends ResourceFlowTestCase<DomainUpdateFlow, Domain
|
|||
.setStatusValues(ImmutableSet.of(StatusValue.PENDING_DELETE, StatusValue.SERVER_HOLD))
|
||||
.build());
|
||||
runFlowAsSuperuser();
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@ import static google.registry.testing.DatabaseHelper.persistDeletedHost;
|
|||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
import static google.registry.testing.HostSubject.assertAboutHosts;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
@ -54,16 +52,12 @@ import google.registry.model.eppcommon.StatusValue;
|
|||
import google.registry.model.host.Host;
|
||||
import google.registry.model.reporting.HistoryEntry;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.TaskQueueExtension;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link HostCreateFlow}. */
|
||||
class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Host> {
|
||||
|
||||
@RegisterExtension TaskQueueExtension taskQueue = new TaskQueueExtension();
|
||||
|
||||
private void setEppHostCreateInput(String hostName, String hostAddrs) {
|
||||
setEppInput(
|
||||
"host_create.xml",
|
||||
|
@ -122,7 +116,7 @@ class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Host> {
|
|||
void testSuccess_externalNeverExisted() throws Exception {
|
||||
doSuccessfulTest();
|
||||
assertAboutHosts().that(reloadResourceByForeignKey()).hasSuperordinateDomain(null);
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -133,7 +127,7 @@ class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Host> {
|
|||
loadByForeignKey(Domain.class, "example.tld", clock.nowUtc()).get();
|
||||
assertAboutHosts().that(host).hasSuperordinateDomain(superordinateDomain.createVKey());
|
||||
assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
|
||||
assertDnsTasksEnqueued("ns1.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -150,7 +144,7 @@ class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Host> {
|
|||
persistDeletedHost(getUniqueIdFromCommand(), clock.nowUtc().minusDays(1));
|
||||
doSuccessfulTest();
|
||||
assertAboutHosts().that(reloadResourceByForeignKey()).hasSuperordinateDomain(null);
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -162,7 +156,7 @@ class HostCreateFlowTest extends ResourceFlowTestCase<HostCreateFlow, Host> {
|
|||
loadByForeignKey(Domain.class, "example.tld", clock.nowUtc()).get();
|
||||
assertAboutHosts().that(host).hasSuperordinateDomain(superordinateDomain.createVKey());
|
||||
assertThat(superordinateDomain.getSubordinateHosts()).containsExactly("ns1.example.tld");
|
||||
assertDnsTasksEnqueued("ns1.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,8 +24,6 @@ import static google.registry.testing.DatabaseHelper.persistDeletedHost;
|
|||
import static google.registry.testing.DatabaseHelper.persistResource;
|
||||
import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptions;
|
||||
import static google.registry.testing.HostSubject.assertAboutHosts;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
@ -48,17 +46,13 @@ import google.registry.model.tld.Registry;
|
|||
import google.registry.model.transfer.DomainTransferData;
|
||||
import google.registry.model.transfer.TransferStatus;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.TaskQueueExtension;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link HostDeleteFlow}. */
|
||||
class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Host> {
|
||||
|
||||
@RegisterExtension TaskQueueExtension taskQueue = new TaskQueueExtension();
|
||||
|
||||
@BeforeEach
|
||||
void initFlowTest() {
|
||||
setEppInput("host_delete.xml", ImmutableMap.of("HOSTNAME", "ns1.example.tld"));
|
||||
|
@ -320,10 +314,10 @@ class HostDeleteFlowTest extends ResourceFlowTestCase<HostDeleteFlow, Host> {
|
|||
.hasType(Type.HOST_DELETE);
|
||||
assertNoBillingEvents();
|
||||
if (isSubordinate) {
|
||||
assertDnsTasksEnqueued(deletedHost.getHostName());
|
||||
dnsUtilsHelper.assertHostDnsRequests(deletedHost.getHostName());
|
||||
assertThat(loadByKey(deletedHost.getSuperordinateDomain()).getSubordinateHosts()).isEmpty();
|
||||
} else {
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
assertLastHistoryContainsResource(deletedHost);
|
||||
}
|
||||
|
|
|
@ -35,8 +35,6 @@ import static google.registry.testing.EppExceptionSubject.assertAboutEppExceptio
|
|||
import static google.registry.testing.GenericEppResourceSubject.assertAboutEppResources;
|
||||
import static google.registry.testing.HistoryEntrySubject.assertAboutHistoryEntries;
|
||||
import static google.registry.testing.HostSubject.assertAboutHosts;
|
||||
import static google.registry.testing.TaskQueueHelper.assertDnsTasksEnqueued;
|
||||
import static google.registry.testing.TaskQueueHelper.assertNoDnsTasksEnqueued;
|
||||
import static google.registry.util.DateTimeUtils.END_OF_TIME;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
@ -81,17 +79,13 @@ import google.registry.model.transfer.TransferStatus;
|
|||
import google.registry.persistence.VKey;
|
||||
import google.registry.testing.CloudTasksHelper.TaskMatcher;
|
||||
import google.registry.testing.DatabaseHelper;
|
||||
import google.registry.testing.TaskQueueExtension;
|
||||
import javax.annotation.Nullable;
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
/** Unit tests for {@link HostUpdateFlow}. */
|
||||
class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
||||
|
||||
@RegisterExtension TaskQueueExtension taskQueue = new TaskQueueExtension();
|
||||
|
||||
private void setEppHostUpdateInput(
|
||||
String oldHostName, String newHostName, String ipOrStatusToAdd, String ipOrStatusToRem) {
|
||||
setEppInput(
|
||||
|
@ -189,7 +183,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
persistActiveSubordinateHost(oldHostName(), persistActiveDomain("example.tld"));
|
||||
Host renamedHost = doSuccessfulTest();
|
||||
assertThat(renamedHost.isSubordinate()).isTrue();
|
||||
assertDnsTasksEnqueued("ns1.example.tld", "ns2.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.tld", "ns2.example.tld");
|
||||
VKey<Host> oldVKeyAfterRename = ForeignKeyUtils.load(Host.class, oldHostName(), clock.nowUtc());
|
||||
assertThat(oldVKeyAfterRename).isNull();
|
||||
}
|
||||
|
@ -238,7 +232,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
.and()
|
||||
.hasOnlyOneHistoryEntryWhich()
|
||||
.hasType(HistoryEntry.Type.HOST_UPDATE);
|
||||
assertDnsTasksEnqueued("ns1.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -264,7 +258,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
.and()
|
||||
.hasOnlyOneHistoryEntryWhich()
|
||||
.hasType(HistoryEntry.Type.HOST_UPDATE);
|
||||
assertDnsTasksEnqueued("ns1.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -298,7 +292,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
.hasLastTransferTime(oneDayAgo);
|
||||
Domain reloadedDomain = loadByEntity(domain).cloneProjectedAtTime(now);
|
||||
assertThat(reloadedDomain.getSubordinateHosts()).containsExactly("ns2.example.tld");
|
||||
assertDnsTasksEnqueued("ns1.example.tld", "ns2.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.tld", "ns2.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -333,7 +327,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
assertThat(loadByEntity(foo).cloneProjectedAtTime(now).getSubordinateHosts()).isEmpty();
|
||||
assertThat(loadByEntity(example).cloneProjectedAtTime(now).getSubordinateHosts())
|
||||
.containsExactly("ns2.example.tld");
|
||||
assertDnsTasksEnqueued("ns2.foo.tld", "ns2.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns2.foo.tld", "ns2.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -370,7 +364,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
assertThat(reloadedFooDomain.getSubordinateHosts()).isEmpty();
|
||||
Domain reloadedTldDomain = loadByEntity(tldDomain).cloneProjectedAtTime(now);
|
||||
assertThat(reloadedTldDomain.getSubordinateHosts()).containsExactly("ns2.example.tld");
|
||||
assertDnsTasksEnqueued("ns1.example.foo", "ns2.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.foo", "ns2.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -413,7 +407,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
assertThat(renamedHost.getLastTransferTime()).isEqualTo(oneDayAgo);
|
||||
Domain reloadedDomain = loadByEntity(domain).cloneProjectedAtTime(clock.nowUtc());
|
||||
assertThat(reloadedDomain.getSubordinateHosts()).isEmpty();
|
||||
assertDnsTasksEnqueued("ns1.example.foo");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns1.example.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -425,7 +419,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
persistActiveHost(oldHostName());
|
||||
assertThat(domain.getSubordinateHosts()).isEmpty();
|
||||
assertThrows(CannotRenameExternalHostException.class, this::runFlow);
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -449,7 +443,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
.hasLastTransferTime(null);
|
||||
assertThat(loadByEntity(domain).cloneProjectedAtTime(now).getSubordinateHosts())
|
||||
.containsExactly("ns2.example.tld");
|
||||
assertDnsTasksEnqueued("ns2.example.tld");
|
||||
dnsUtilsHelper.assertHostDnsRequests("ns2.example.tld");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -474,7 +468,7 @@ class HostUpdateFlowTest extends ResourceFlowTestCase<HostUpdateFlow, Host> {
|
|||
.hasPersistedCurrentSponsorRegistrarId("TheRegistrar")
|
||||
.and()
|
||||
.hasLastTransferTime(null);
|
||||
assertNoDnsTasksEnqueued();
|
||||
dnsUtilsHelper.assertNoMoreDnsRequests();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
// Copyright 2023 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.model.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.model.ImmutableObjectSubject.assertAboutImmutableObjects;
|
||||
import static google.registry.testing.DatabaseHelper.insertInDb;
|
||||
import static google.registry.testing.DatabaseHelper.loadAllOf;
|
||||
import static google.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import google.registry.dns.DnsConstants.TargetType;
|
||||
import google.registry.model.EntityTestCase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Unit tests for {@link DnsRefreshRequest}. */
|
||||
public class DnsRefreshRequestTest extends EntityTestCase {
|
||||
|
||||
DnsRefreshRequestTest() {
|
||||
super(JpaEntityCoverageCheck.ENABLED);
|
||||
}
|
||||
|
||||
private final DnsRefreshRequest request =
|
||||
new DnsRefreshRequest(TargetType.DOMAIN, "test.example", "example", fakeClock.nowUtc());
|
||||
|
||||
@Test
|
||||
void testPersistence() {
|
||||
assertThat(request.getLastProcessTime()).isEqualTo(START_OF_TIME);
|
||||
fakeClock.advanceOneMilli();
|
||||
insertInDb(request);
|
||||
fakeClock.advanceOneMilli();
|
||||
ImmutableList<DnsRefreshRequest> requests = loadAllOf(DnsRefreshRequest.class);
|
||||
assertThat(requests.size()).isEqualTo(1);
|
||||
assertThat(requests.get(0)).isEqualTo(request);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullValues() {
|
||||
// type
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> new DnsRefreshRequest(null, "test.example", "example", fakeClock.nowUtc()));
|
||||
// name
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> new DnsRefreshRequest(TargetType.DOMAIN, null, "example", fakeClock.nowUtc()));
|
||||
// tld
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> new DnsRefreshRequest(TargetType.DOMAIN, "test.example", null, fakeClock.nowUtc()));
|
||||
// request time
|
||||
assertThrows(
|
||||
NullPointerException.class,
|
||||
() -> new DnsRefreshRequest(TargetType.DOMAIN, "test.example", "example", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateProcessTime() {
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> request.updateProcessTime(fakeClock.nowUtc())))
|
||||
.hasMessageThat()
|
||||
.contains("must be later than request time");
|
||||
|
||||
fakeClock.advanceOneMilli();
|
||||
fakeClock.advanceOneMilli();
|
||||
|
||||
DnsRefreshRequest newRequest = request.updateProcessTime(fakeClock.nowUtc());
|
||||
assertAboutImmutableObjects().that(newRequest).isEqualExceptFields(request, "lastProcessTime");
|
||||
assertThat(newRequest.getLastProcessTime()).isEqualTo(fakeClock.nowUtc());
|
||||
|
||||
assertThat(
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> newRequest.updateProcessTime(fakeClock.nowUtc().minusMillis(1))))
|
||||
.hasMessageThat()
|
||||
.contains("must be later than the old one");
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assert_;
|
|||
|
||||
import google.registry.model.billing.BillingEventTest;
|
||||
import google.registry.model.common.CursorTest;
|
||||
import google.registry.model.common.DnsRefreshRequestTest;
|
||||
import google.registry.model.console.UserTest;
|
||||
import google.registry.model.contact.ContactTest;
|
||||
import google.registry.model.domain.DomainSqlTest;
|
||||
|
@ -85,6 +86,7 @@ import org.junit.runner.RunWith;
|
|||
ContactHistoryTest.class,
|
||||
ContactTest.class,
|
||||
CursorTest.class,
|
||||
DnsRefreshRequestTest.class,
|
||||
DomainSqlTest.class,
|
||||
DomainHistoryTest.class,
|
||||
HostHistoryTest.class,
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
// Copyright 2023 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.testing;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import google.registry.dns.DnsUtils;
|
||||
import google.registry.model.annotations.DeleteAfterMigration;
|
||||
import org.joda.time.Duration;
|
||||
|
||||
/**
|
||||
* Test helper for {@link DnsUtils}.
|
||||
*
|
||||
* <p>This is a temporary test class that is only used during DNS pull queue migration. Once we are
|
||||
* no longer using the pull queue method, we can just assert on the inserted SQL entry instead in
|
||||
* {@link DatabaseHelper}.
|
||||
*/
|
||||
@DeleteAfterMigration
|
||||
public class DnsUtilsHelper {
|
||||
|
||||
private final DnsUtils dnsUtils;
|
||||
|
||||
public DnsUtilsHelper() {
|
||||
dnsUtils = mock(DnsUtils.class);
|
||||
}
|
||||
|
||||
public DnsUtilsHelper(DnsUtils dnsUtils) {
|
||||
this.dnsUtils = dnsUtils;
|
||||
}
|
||||
|
||||
public DnsUtils getDnsUtils() {
|
||||
return dnsUtils;
|
||||
}
|
||||
|
||||
public void assertDomainDnsRequests(String... domainNames) {
|
||||
for (String domainName : domainNames) {
|
||||
verify(dnsUtils).requestDomainDnsRefresh(domainName);
|
||||
}
|
||||
}
|
||||
|
||||
public void assertDomainDnsRequestWithDelay(String domainName, Duration delay) {
|
||||
verify(dnsUtils).requestDomainDnsRefresh(domainName, delay);
|
||||
}
|
||||
|
||||
public void assertNoDomainDnsRequestWithDelay(String domainName, Duration delay) {
|
||||
verify(dnsUtils, never()).requestDomainDnsRefresh(domainName, delay);
|
||||
}
|
||||
|
||||
public void assertHostDnsRequests(String... hostNames) {
|
||||
for (String hostName : hostNames) {
|
||||
verify(dnsUtils).requestHostDnsRefresh(hostName);
|
||||
}
|
||||
}
|
||||
|
||||
public void assertNoMoreDnsRequests() {
|
||||
verifyNoMoreInteractions(dnsUtils);
|
||||
}
|
||||
}
|
|
@ -18,21 +18,18 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import static google.registry.testing.DatabaseHelper.createTld;
|
||||
import static google.registry.testing.DatabaseHelper.persistActiveDomain;
|
||||
import static google.registry.testing.DatabaseHelper.persistDeletedDomain;
|
||||
import static org.joda.time.Duration.standardMinutes;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import google.registry.dns.DnsQueue;
|
||||
import google.registry.dns.DnsUtils;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions;
|
||||
import google.registry.persistence.transaction.JpaTestExtensions.JpaIntegrationTestExtension;
|
||||
import google.registry.testing.DnsUtilsHelper;
|
||||
import google.registry.testing.FakeClock;
|
||||
import google.registry.testing.FakeResponse;
|
||||
import java.util.Random;
|
||||
|
@ -42,14 +39,13 @@ import org.joda.time.Duration;
|
|||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
/** Unit tests for {@link RefreshDnsForAllDomainsAction}. */
|
||||
public class RefreshDnsForAllDomainsActionTest {
|
||||
|
||||
private final FakeClock clock = new FakeClock(DateTime.parse("2020-02-02T02:02:02Z"));
|
||||
private final DnsQueue dnsQueue = mock(DnsQueue.class);
|
||||
private final DnsUtils dnsUtils = mock(DnsUtils.class);
|
||||
private final DnsUtilsHelper dnsUtilsHelper = new DnsUtilsHelper(dnsUtils);
|
||||
private RefreshDnsForAllDomainsAction action;
|
||||
private final FakeResponse response = new FakeResponse();
|
||||
|
||||
|
@ -64,27 +60,26 @@ public class RefreshDnsForAllDomainsActionTest {
|
|||
action.random = new Random();
|
||||
action.random.setSeed(123L);
|
||||
action.clock = clock;
|
||||
action.dnsQueue = dnsQueue;
|
||||
action.dnsUtils = dnsUtils;
|
||||
action.response = response;
|
||||
|
||||
createTld("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_runAction_errorEnqueuingToDnsQueue() throws Exception {
|
||||
void test_runAction_errorRequestDnsRefresh() throws Exception {
|
||||
persistActiveDomain("foo.bar");
|
||||
persistActiveDomain("baz.bar");
|
||||
persistActiveDomain("low.bar");
|
||||
action.tlds = ImmutableSet.of("bar");
|
||||
doThrow(new RuntimeException("Error enqueuing task."))
|
||||
.when(dnsQueue)
|
||||
.addDomainRefreshTask(eq("baz.bar"), any(Duration.class));
|
||||
.when(dnsUtils)
|
||||
.requestDomainDnsRefresh(eq("baz.bar"), any(Duration.class));
|
||||
action.run();
|
||||
InOrder inOrder = inOrder(dnsQueue);
|
||||
inOrder.verify(dnsQueue).addDomainRefreshTask("low.bar", Duration.ZERO);
|
||||
inOrder.verify(dnsQueue).addDomainRefreshTask("baz.bar", Duration.ZERO);
|
||||
inOrder.verify(dnsQueue).addDomainRefreshTask("foo.bar", Duration.ZERO);
|
||||
verifyNoMoreInteractions(dnsQueue);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("low.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("baz.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("foo.bar", Duration.ZERO);
|
||||
verifyNoMoreInteractions(dnsUtils);
|
||||
assertThat(response.getStatus()).isEqualTo(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
@ -94,8 +89,8 @@ public class RefreshDnsForAllDomainsActionTest {
|
|||
persistActiveDomain("low.bar");
|
||||
action.tlds = ImmutableSet.of("bar");
|
||||
action.run();
|
||||
verify(dnsQueue).addDomainRefreshTask("foo.bar", Duration.ZERO);
|
||||
verify(dnsQueue).addDomainRefreshTask("low.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("foo.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("low.bar", Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -105,10 +100,8 @@ public class RefreshDnsForAllDomainsActionTest {
|
|||
action.tlds = ImmutableSet.of("bar");
|
||||
action.smearMinutes = 1000;
|
||||
action.run();
|
||||
ArgumentCaptor<Duration> captor = ArgumentCaptor.forClass(Duration.class);
|
||||
verify(dnsQueue).addDomainRefreshTask(eq("foo.bar"), captor.capture());
|
||||
verify(dnsQueue).addDomainRefreshTask(eq("low.bar"), captor.capture());
|
||||
assertThat(captor.getAllValues()).containsExactly(standardMinutes(450), standardMinutes(782));
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("foo.bar", Duration.standardMinutes(450));
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("low.bar", Duration.standardMinutes(782));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -117,8 +110,8 @@ public class RefreshDnsForAllDomainsActionTest {
|
|||
persistDeletedDomain("deleted.bar", clock.nowUtc().minusYears(1));
|
||||
action.tlds = ImmutableSet.of("bar");
|
||||
action.run();
|
||||
verify(dnsQueue).addDomainRefreshTask("foo.bar", Duration.ZERO);
|
||||
verify(dnsQueue, never()).addDomainRefreshTask("deleted.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("foo.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertNoDomainDnsRequestWithDelay("deleted.bar", Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -129,9 +122,9 @@ public class RefreshDnsForAllDomainsActionTest {
|
|||
persistActiveDomain("ignore.baz");
|
||||
action.tlds = ImmutableSet.of("bar");
|
||||
action.run();
|
||||
verify(dnsQueue).addDomainRefreshTask("foo.bar", Duration.ZERO);
|
||||
verify(dnsQueue).addDomainRefreshTask("low.bar", Duration.ZERO);
|
||||
verify(dnsQueue, never()).addDomainRefreshTask("ignore.baz", Duration.ZERO);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("foo.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertDomainDnsRequestWithDelay("low.bar", Duration.ZERO);
|
||||
dnsUtilsHelper.assertNoDomainDnsRequestWithDelay("ignore.baz", Duration.ZERO);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue