Add activeOrDeletedSince parameter to RefreshDnsForAllDomainsAction (#2556)

This commit is contained in:
Juan Celhay
2024-09-17 16:02:25 +00:00
committed by GitHub
parent b07769bdee
commit 7ee541e1b1
4 changed files with 115 additions and 7 deletions
@@ -56,7 +56,12 @@ public class RefreshDnsForAllDomainsActionTest {
createTld("bar");
action =
new RefreshDnsForAllDomainsAction(
response, ImmutableSet.of("bar"), Optional.of(10), Optional.empty(), new Random());
response,
ImmutableSet.of("bar"),
Optional.of(10),
Optional.empty(),
Optional.empty(),
new Random());
}
@Test
@@ -75,7 +80,12 @@ public class RefreshDnsForAllDomainsActionTest {
// Set batch size to 1 since each batch will be enqueud at the same time
action =
new RefreshDnsForAllDomainsAction(
response, ImmutableSet.of("bar"), Optional.of(1), Optional.of(7), new Random());
response,
ImmutableSet.of("bar"),
Optional.of(1),
Optional.of(7),
Optional.empty(),
new Random());
tm().transact(() -> action.refreshBatch(Optional.empty(), Duration.standardMinutes(1000)));
tm().transact(() -> action.refreshBatch(Optional.empty(), Duration.standardMinutes(1000)));
ImmutableList<DnsRefreshRequest> refreshRequests =
@@ -98,6 +108,28 @@ public class RefreshDnsForAllDomainsActionTest {
assertNoDnsRequestsExcept("foo.bar");
}
@Test
void test_runAction_refreshesDeletedDomain_whenActiveOrDeletedSinceIsProvided() throws Exception {
action =
new RefreshDnsForAllDomainsAction(
response,
ImmutableSet.of("bar"),
Optional.of(1),
Optional.of(7),
Optional.of(clock.nowUtc().minusYears(3)),
new Random());
persistActiveDomain("foo.bar");
persistDeletedDomain("deleted1.bar", clock.nowUtc().minusYears(1));
persistDeletedDomain("deleted3.bar", clock.nowUtc().minusYears(3));
persistDeletedDomain("deleted5.bar", clock.nowUtc().minusYears(5));
action.run();
assertDomainDnsRequestWithRequestTime("foo.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("deleted1.bar", clock.nowUtc());
assertDomainDnsRequestWithRequestTime("deleted3.bar", clock.nowUtc());
assertNoDnsRequestsExcept("foo.bar", "deleted1.bar", "deleted3.bar");
}
@Test
void test_runAction_ignoresDomainsOnOtherTlds() throws Exception {
createTld("baz");
@@ -0,0 +1,59 @@
// Copyright 2017 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.server;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import google.registry.request.HttpException.BadRequestException;
import jakarta.servlet.http.HttpServletRequest;
import java.util.Optional;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Test;
/** Unit tests for {@link ToolsServerModule}. */
public class ToolsServerModuleTest {
private final HttpServletRequest request = mock(HttpServletRequest.class);
@Test
void test_provideDeletionTime() throws Exception {
when(request.getParameter("activeOrDeletedSince")).thenReturn("1991-07-01T00:00:00Z");
DateTime expected = DateTime.parse("1991-07-01T00:00:00Z");
Optional<DateTime> dateTimeParam = ToolsServerModule.provideDeletionTime(request);
assertThat(dateTimeParam).isEqualTo(Optional.of(expected));
}
@Test
void test_doesNotprovideDeletionTimeOnEmptyParam() throws Exception {
when(request.getParameter("activeOrDeletedSince")).thenReturn("");
assertThat(ToolsServerModule.provideDeletionTime(request)).isEqualTo(Optional.empty());
}
@Test
void test_provideDeletionTime_incorrectDateFormat_throwsBadRequestException() throws Exception {
when(request.getParameter("activeOrDeletedSince")).thenReturn("error404?");
BadRequestException thrown =
assertThrows(
BadRequestException.class, () -> ToolsServerModule.provideDeletionTime(request));
assertThat(thrown).hasMessageThat().contains("Bad ISO 8601 timestamp: activeOrDeletedSince");
}
}