Connect to the correct endpoints based on runtime (#2540)

* Connect to the correct endpoints based on runtime

* Address code review comments

* Add checks for HTTP methods
This commit is contained in:
Lai Jiang
2024-09-20 18:39:54 +00:00
committed by GitHub
parent 5c35811eb9
commit 7929322e95
121 changed files with 649 additions and 488 deletions
@@ -15,6 +15,8 @@
package google.registry.batch;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.Action.Method.GET;
import static google.registry.request.Action.Method.POST;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
@@ -29,7 +31,10 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.LinkedListMultimap;
import google.registry.batch.CloudTasksUtils.SerializableCloudTasksClient;
import google.registry.request.Action.Service;
import google.registry.request.Action;
import google.registry.request.Action.GaeService;
import google.registry.request.Action.GkeService;
import google.registry.request.auth.Auth;
import google.registry.testing.CloudTasksHelper.FakeGoogleCredentialsBundle;
import google.registry.testing.FakeClock;
import google.registry.testing.FakeSleeper;
@@ -68,24 +73,13 @@ public class CloudTasksUtilsTest {
}
@Test
void testFailure_createGetTasks_withNegativeDelay() {
void testFailure_createTasks_withNegativeDelay() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() ->
cloudTasksUtils.createGetTaskWithDelay(
"/the/path", Service.BACKEND, params, Duration.standardMinutes(-10)));
assertThat(thrown).hasMessageThat().isEqualTo("Negative duration is not supported.");
}
@Test
void testFailure_createPostTasks_withNegativeDelay() {
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
() ->
cloudTasksUtils.createGetTaskWithDelay(
"/the/path", Service.BACKEND, params, Duration.standardMinutes(-10)));
cloudTasksUtils.createTaskWithDelay(
TheAction.class, GET, params, Duration.standardMinutes(-10)));
assertThat(thrown).hasMessageThat().isEqualTo("Negative duration is not supported.");
}
@@ -93,26 +87,26 @@ public class CloudTasksUtilsTest {
void testFailure_illegalPath() {
assertThrows(
IllegalArgumentException.class,
() -> cloudTasksUtils.createPostTask("the/path", Service.BACKEND, params));
() -> cloudTasksUtils.createTask("the/path", GET, GkeService.BACKEND, params));
assertThrows(
IllegalArgumentException.class,
() -> cloudTasksUtils.createPostTask(null, Service.BACKEND, params));
() -> cloudTasksUtils.createTask(null, GET, GkeService.BACKEND, params));
assertThrows(
IllegalArgumentException.class,
() -> cloudTasksUtils.createPostTask("", Service.BACKEND, params));
() -> cloudTasksUtils.createTask("", GET, GkeService.BACKEND, params));
}
@Test
void testSuccess_enqueueTask() {
Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params);
Task task = cloudTasksUtils.createTask(TheAction.class, GET, params);
cloudTasksUtils.enqueue("test-queue", task);
verify(mockClient).enqueue("project", "location", "test-queue", task);
}
@Test
void testSuccess_enqueueTasks_varargs() {
Task task1 = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params);
Task task2 = cloudTasksUtils.createGetTask("/other/path", Service.TOOLS, params);
Task task1 = cloudTasksUtils.createTask(TheAction.class, GET, params);
Task task2 = cloudTasksUtils.createTask(OtherAction.class, GET, params);
cloudTasksUtils.enqueue("test-queue", task1, task2);
verify(mockClient).enqueue("project", "location", "test-queue", task1);
verify(mockClient).enqueue("project", "location", "test-queue", task2);
@@ -120,8 +114,8 @@ public class CloudTasksUtilsTest {
@Test
void testSuccess_enqueueTasks_iterable() {
Task task1 = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params);
Task task2 = cloudTasksUtils.createGetTask("/other/path", Service.TOOLS, params);
Task task1 = cloudTasksUtils.createTask(TheAction.class, GET, params);
Task task2 = cloudTasksUtils.createTask(OtherAction.class, GET, params);
cloudTasksUtils.enqueue("test-queue", ImmutableList.of(task1, task2));
verify(mockClient).enqueue("project", "location", "test-queue", task1);
verify(mockClient).enqueue("project", "location", "test-queue", task2);
@@ -129,7 +123,7 @@ public class CloudTasksUtilsTest {
@Test
void testSuccess_createGetTasks() {
Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, params);
Task task = cloudTasksUtils.createTask(TheAction.class, GET, params);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3");
@@ -137,9 +131,43 @@ public class CloudTasksUtilsTest {
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
@Test
void testSuccess_createTasks_WithPathAndService_GAE() {
Task task = cloudTasksUtils.createTask("/the/path", GET, GaeService.BACKEND, params);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
@Test
void testSuccess_createTasks_WithPathAndService_GKE() {
Task task = cloudTasksUtils.createTask("/the/path", GET, GkeService.BACKEND, params);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
@Test
void testFailure_createTasks_notAnAction() {
assertThrows(
IllegalArgumentException.class,
() -> cloudTasksUtils.createTask(NotAnAction.class, GET, params));
}
@Test
void testFailure_methodNotAllowed() {
assertThrows(
IllegalArgumentException.class,
() -> cloudTasksUtils.createTask(OtherAction.class, POST, params));
}
@Test
void testSuccess_createPostTasks() {
Task task = cloudTasksUtils.createPostTask("/the/path", Service.BACKEND, params);
Task task = cloudTasksUtils.createTask(TheAction.class, POST, params);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type"))
@@ -152,7 +180,7 @@ public class CloudTasksUtilsTest {
@Test
void testSuccess_createGetTasks_withNullParams() {
Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, null);
Task task = cloudTasksUtils.createTask(TheAction.class, GET, null);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
verifyOidcToken(task);
@@ -161,7 +189,7 @@ public class CloudTasksUtilsTest {
@Test
void testSuccess_createPostTasks_withNullParams() {
Task task = cloudTasksUtils.createPostTask("/the/path", Service.BACKEND, null);
Task task = cloudTasksUtils.createTask(TheAction.class, POST, null);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEmpty();
@@ -171,7 +199,7 @@ public class CloudTasksUtilsTest {
@Test
void testSuccess_createGetTasks_withEmptyParams() {
Task task = cloudTasksUtils.createGetTask("/the/path", Service.BACKEND, ImmutableMultimap.of());
Task task = cloudTasksUtils.createTask(TheAction.class, GET, ImmutableMultimap.of());
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
verifyOidcToken(task);
@@ -180,8 +208,7 @@ public class CloudTasksUtilsTest {
@Test
void testSuccess_createPostTasks_withEmptyParams() {
Task task =
cloudTasksUtils.createPostTask("/the/path", Service.BACKEND, ImmutableMultimap.of());
Task task = cloudTasksUtils.createTask(TheAction.class, POST, ImmutableMultimap.of());
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEmpty();
@@ -191,15 +218,15 @@ public class CloudTasksUtilsTest {
@SuppressWarnings("ProtoTimestampGetSecondsGetNano")
@Test
void testSuccess_createGetTasks_withJitterSeconds() {
void testSuccess_createTasks_withJitterSeconds() {
Task task =
cloudTasksUtils.createGetTaskWithJitter(
"/the/path", Service.BACKEND, params, Optional.of(100));
cloudTasksUtils.createTaskWithJitter(TheAction.class, GET, params, Optional.of(100));
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0);
Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds());
Instant lowerBoundTime = Instant.ofEpochMilli(clock.nowUtc().getMillis());
Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(100).getMillis());
@@ -208,49 +235,10 @@ public class CloudTasksUtilsTest {
assertThat(upperBound.isBefore(scheduleTime)).isFalse();
}
@SuppressWarnings("ProtoTimestampGetSecondsGetNano")
@Test
void testSuccess_createPostTasks_withJitterSeconds() {
void testSuccess_createTasks_withEmptyJitterSeconds() {
Task task =
cloudTasksUtils.createPostTaskWithJitter(
"/the/path", Service.BACKEND, params, Optional.of(1));
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type"))
.isEqualTo("application/x-www-form-urlencoded");
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8))
.isEqualTo("key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0);
Instant scheduleTime = Instant.ofEpochSecond(task.getScheduleTime().getSeconds());
Instant lowerBoundTime = Instant.ofEpochMilli(clock.nowUtc().getMillis());
Instant upperBound = Instant.ofEpochMilli(clock.nowUtc().plusSeconds(1).getMillis());
assertThat(scheduleTime.isBefore(lowerBoundTime)).isFalse();
assertThat(upperBound.isBefore(scheduleTime)).isFalse();
}
@Test
void testSuccess_createPostTasks_withEmptyJitterSeconds() {
Task task =
cloudTasksUtils.createPostTaskWithJitter(
"/the/path", Service.BACKEND, params, Optional.empty());
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type"))
.isEqualTo("application/x-www-form-urlencoded");
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8))
.isEqualTo("key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
@Test
void testSuccess_createGetTasks_withEmptyJitterSeconds() {
Task task =
cloudTasksUtils.createGetTaskWithJitter(
"/the/path", Service.BACKEND, params, Optional.empty());
cloudTasksUtils.createTaskWithJitter(TheAction.class, GET, params, Optional.empty());
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3");
@@ -259,25 +247,8 @@ public class CloudTasksUtilsTest {
}
@Test
void testSuccess_createPostTasks_withZeroJitterSeconds() {
Task task =
cloudTasksUtils.createPostTaskWithJitter(
"/the/path", Service.BACKEND, params, Optional.of(0));
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type"))
.isEqualTo("application/x-www-form-urlencoded");
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8))
.isEqualTo("key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
@Test
void testSuccess_createGetTasks_withZeroJitterSeconds() {
Task task =
cloudTasksUtils.createGetTaskWithJitter(
"/the/path", Service.BACKEND, params, Optional.of(0));
void testSuccess_createTasks_withZeroJitterSeconds() {
Task task = cloudTasksUtils.createTaskWithJitter(TheAction.class, GET, params, Optional.of(0));
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3");
@@ -286,10 +257,10 @@ public class CloudTasksUtilsTest {
}
@Test
void testSuccess_createGetTasks_withDelay() {
void testSuccess_createTasks_withDelay() {
Task task =
cloudTasksUtils.createGetTaskWithDelay(
"/the/path", Service.BACKEND, params, Duration.standardMinutes(10));
cloudTasksUtils.createTaskWithDelay(
TheAction.class, GET, params, Duration.standardMinutes(10));
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3");
@@ -299,41 +270,8 @@ public class CloudTasksUtilsTest {
}
@Test
void testSuccess_createPostTasks_withDelay() {
Task task =
cloudTasksUtils.createPostTaskWithDelay(
"/the/path", Service.BACKEND, params, Duration.standardMinutes(10));
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type"))
.isEqualTo("application/x-www-form-urlencoded");
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8))
.isEqualTo("key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0);
assertThat(Instant.ofEpochSecond(task.getScheduleTime().getSeconds()))
.isEqualTo(Instant.ofEpochMilli(clock.nowUtc().plusMinutes(10).getMillis()));
}
@Test
void testSuccess_createPostTasks_withZeroDelay() {
Task task =
cloudTasksUtils.createPostTaskWithDelay(
"/the/path", Service.BACKEND, params, Duration.ZERO);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.POST);
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.example.com/the/path");
assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type"))
.isEqualTo("application/x-www-form-urlencoded");
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8))
.isEqualTo("key1=val1&key2=val2&key1=val3");
verifyOidcToken(task);
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
@Test
void testSuccess_createGetTasks_withZeroDelay() {
Task task =
cloudTasksUtils.createGetTaskWithDelay("/the/path", Service.BACKEND, params, Duration.ZERO);
void testSuccess_createTasks_withZeroDelay() {
Task task = cloudTasksUtils.createTaskWithDelay(TheAction.class, GET, params, Duration.ZERO);
assertThat(task.getHttpRequest().getHttpMethod()).isEqualTo(HttpMethod.GET);
assertThat(task.getHttpRequest().getUrl())
.isEqualTo("https://backend.example.com/the/path?key1=val1&key2=val2&key1=val3");
@@ -341,6 +279,36 @@ public class CloudTasksUtilsTest {
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
}
@Action(
service = GaeService.BACKEND,
gkeService = GkeService.BACKEND,
path = "/the/path",
method = {GET, POST},
auth = Auth.AUTH_ADMIN)
private static class TheAction implements Runnable {
@Override
public void run() {}
}
@Action(
service = GaeService.TOOLS,
gkeService = GkeService.BACKEND,
path = "/other/path",
method = {GET},
auth = Auth.AUTH_ADMIN)
private static class OtherAction implements Runnable {
@Override
public void run() {}
}
private static class NotAnAction implements Runnable {
@Override
public void run() {}
}
private static void verifyOidcToken(Task task) {
assertThat(task.getHttpRequest().getOidcToken())
.isEqualTo(
@@ -16,7 +16,7 @@ package google.registry.module.backend;
import static com.google.common.truth.Truth.assertThat;
import google.registry.request.Action;
import google.registry.request.Action.GaeService;
import google.registry.request.RouterDisplayHelper;
import google.registry.testing.GoldenFileTestHelper;
import org.junit.jupiter.api.Test;
@@ -35,7 +35,7 @@ class BackendRequestComponentTest {
void testRoutingService() {
assertThat(
RouterDisplayHelper.extractHumanReadableRoutesWithWrongService(
BackendRequestComponent.class, Action.Service.BACKEND))
BackendRequestComponent.class, GaeService.BACKEND))
.isEmpty();
}
}
@@ -16,7 +16,7 @@ package google.registry.module.bsa;
import static com.google.common.truth.Truth.assertThat;
import google.registry.request.Action.Service;
import google.registry.request.Action.GaeService;
import google.registry.request.RouterDisplayHelper;
import google.registry.testing.GoldenFileTestHelper;
import org.junit.jupiter.api.Test;
@@ -35,7 +35,7 @@ public class BsaRequestComponentTest {
void testRoutingService() {
assertThat(
RouterDisplayHelper.extractHumanReadableRoutesWithWrongService(
BsaRequestComponent.class, Service.BSA))
BsaRequestComponent.class, GaeService.BSA))
.isEmpty();
}
}
@@ -16,7 +16,7 @@ package google.registry.module.frontend;
import static com.google.common.truth.Truth.assertThat;
import google.registry.request.Action;
import google.registry.request.Action.GaeService;
import google.registry.request.RouterDisplayHelper;
import google.registry.testing.GoldenFileTestHelper;
import org.junit.jupiter.api.Test;
@@ -35,7 +35,7 @@ class FrontendRequestComponentTest {
void testRoutingService() {
assertThat(
RouterDisplayHelper.extractHumanReadableRoutesWithWrongService(
FrontendRequestComponent.class, Action.Service.DEFAULT))
FrontendRequestComponent.class, GaeService.DEFAULT))
.isEmpty();
}
}
@@ -16,7 +16,7 @@ package google.registry.module.pubapi;
import static com.google.common.truth.Truth.assertThat;
import google.registry.request.Action;
import google.registry.request.Action.GaeService;
import google.registry.request.RouterDisplayHelper;
import google.registry.testing.GoldenFileTestHelper;
import org.junit.jupiter.api.Test;
@@ -35,7 +35,7 @@ class PubApiRequestComponentTest {
void testRoutingService() {
assertThat(
RouterDisplayHelper.extractHumanReadableRoutesWithWrongService(
PubApiRequestComponent.class, Action.Service.PUBAPI))
PubApiRequestComponent.class, GaeService.PUBAPI))
.isEmpty();
}
}
@@ -16,7 +16,7 @@ package google.registry.module.tools;
import static com.google.common.truth.Truth.assertThat;
import google.registry.request.Action;
import google.registry.request.Action.GaeService;
import google.registry.request.RouterDisplayHelper;
import google.registry.testing.GoldenFileTestHelper;
import org.junit.jupiter.api.Test;
@@ -35,7 +35,7 @@ class ToolsRequestComponentTest {
void testRoutingService() {
assertThat(
RouterDisplayHelper.extractHumanReadableRoutesWithWrongService(
ToolsRequestComponent.class, Action.Service.TOOLS))
ToolsRequestComponent.class, GaeService.TOOLS))
.isEmpty();
}
}
@@ -30,6 +30,7 @@ import google.registry.rdap.RdapObjectClasses.BoilerplateType;
import google.registry.rdap.RdapObjectClasses.ReplyPayloadBase;
import google.registry.rdap.RdapSearchResults.IncompletenessWarningType;
import google.registry.request.Action;
import google.registry.request.Action.GaeService;
import google.registry.request.auth.Auth;
import java.util.Optional;
import org.junit.jupiter.api.BeforeEach;
@@ -44,7 +45,7 @@ class RdapActionBaseTest extends RdapActionBaseTestCase<RdapActionBaseTest.RdapT
/** Dummy RdapActionBase subclass used for testing. */
@Action(
service = Action.Service.PUBAPI,
service = GaeService.PUBAPI,
path = "/rdap/test/",
method = {GET, HEAD},
auth = Auth.AUTH_PUBLIC)
@@ -48,41 +48,42 @@ class RdapTestHelper {
private static JsonObject createTosNotice(String linkBase) {
return GSON.toJsonTree(
ImmutableMap.of(
"title", "RDAP Terms of Service",
"description",
ImmutableList.of(
"By querying our Domain Database, you are agreeing to comply with these terms"
+ " so please read them carefully.",
"Any information provided is 'as is' without any guarantee of accuracy.",
"Please do not misuse the Domain Database. It is intended solely for"
+ " query-based access.",
"Don't use the Domain Database to allow, enable, or otherwise support the"
+ " transmission of mass unsolicited, commercial advertising or"
+ " solicitations.",
"Don't access our Domain Database through the use of high volume, automated"
+ " electronic processes that send queries or data to the systems of any"
+ " ICANN-accredited registrar.",
"You may only use the information contained in the Domain Database for lawful"
+ " purposes.",
"Do not compile, repackage, disseminate, or otherwise use the information"
+ " contained in the Domain Database in its entirety, or in any substantial"
+ " portion, without our prior written permission.",
"We may retain certain details about queries to our Domain Database for the"
+ " purposes of detecting and preventing misuse.",
"We reserve the right to restrict or deny your access to the database if we"
+ " suspect that you have failed to comply with these terms.",
"We reserve the right to modify this agreement at any time."),
"links",
ImmutableList.of(
ImmutableMap.of(
"rel", "self",
"href", linkBase + "help/tos",
"type", "application/rdap+json"),
ImmutableMap.of(
"rel", "alternate",
"href", "https://www.registry.tld/about/rdap/tos.html",
"type", "text/html")))).getAsJsonObject();
ImmutableMap.of(
"title", "RDAP Terms of Service",
"description",
ImmutableList.of(
"By querying our Domain Database, you are agreeing to comply with these"
+ " terms so please read them carefully.",
"Any information provided is 'as is' without any guarantee of accuracy.",
"Please do not misuse the Domain Database. It is intended solely for"
+ " query-based access.",
"Don't use the Domain Database to allow, enable, or otherwise support the"
+ " transmission of mass unsolicited, commercial advertising or"
+ " solicitations.",
"Don't access our Domain Database through the use of high volume, automated"
+ " electronic processes that send queries or data to the systems of"
+ " any ICANN-accredited registrar.",
"You may only use the information contained in the Domain Database for"
+ " lawful purposes.",
"Do not compile, repackage, disseminate, or otherwise use the information"
+ " contained in the Domain Database in its entirety, or in any"
+ " substantial portion, without our prior written permission.",
"We may retain certain details about queries to our Domain Database for the"
+ " purposes of detecting and preventing misuse.",
"We reserve the right to restrict or deny your access to the database if we"
+ " suspect that you have failed to comply with these terms.",
"We reserve the right to modify this agreement at any time."),
"links",
ImmutableList.of(
ImmutableMap.of(
"rel", "self",
"href", linkBase + "help/tos",
"type", "application/rdap+json"),
ImmutableMap.of(
"rel", "alternate",
"href", "https://www.registry.tld/about/rdap/tos.html",
"type", "text/html"))))
.getAsJsonObject();
}
static void addNonDomainBoilerplateNotices(JsonObject jsonObject, String linkBase) {
@@ -31,6 +31,7 @@ import static org.mockito.Mockito.when;
import com.google.common.testing.NullPointerTester;
import google.registry.model.console.User;
import google.registry.model.console.UserRoles;
import google.registry.request.Action.GaeService;
import google.registry.request.HttpException.ServiceUnavailableException;
import google.registry.request.auth.AuthResult;
import google.registry.request.auth.AuthSettings.AuthLevel;
@@ -48,7 +49,7 @@ import org.junit.jupiter.api.Test;
public final class RequestHandlerTest {
@Action(
service = Action.Service.DEFAULT,
service = GaeService.DEFAULT,
path = "/bumblebee",
method = {GET, POST},
isPrefix = true,
@@ -59,7 +60,7 @@ public final class RequestHandlerTest {
}
@Action(
service = Action.Service.DEFAULT,
service = GaeService.DEFAULT,
path = "/sloth",
method = POST,
automaticallyPrintOk = true,
@@ -70,7 +71,7 @@ public final class RequestHandlerTest {
}
@Action(
service = Action.Service.DEFAULT,
service = GaeService.DEFAULT,
path = "/safe-sloth",
method = {GET, POST},
auth = AUTH_PUBLIC)
@@ -79,7 +80,7 @@ public final class RequestHandlerTest {
public void run() {}
}
@Action(service = Action.Service.DEFAULT, path = "/fail", auth = AUTH_PUBLIC)
@Action(service = GaeService.DEFAULT, path = "/fail", auth = AUTH_PUBLIC)
public static final class FailTask implements Runnable {
@Override
public void run() {
@@ -87,7 +88,7 @@ public final class RequestHandlerTest {
}
}
@Action(service = Action.Service.DEFAULT, path = "/failAtConstruction", auth = AUTH_PUBLIC)
@Action(service = GaeService.DEFAULT, path = "/failAtConstruction", auth = AUTH_PUBLIC)
public static final class FailAtConstructionTask implements Runnable {
FailAtConstructionTask() {
throw new ServiceUnavailableException("Fail at construction");
@@ -112,18 +113,14 @@ public final class RequestHandlerTest {
}
}
@Action(service = Action.Service.DEFAULT, path = "/auth/none", auth = AUTH_PUBLIC, method = GET)
@Action(service = GaeService.DEFAULT, path = "/auth/none", auth = AUTH_PUBLIC, method = GET)
public class AuthNoneAction extends AuthBase {
AuthNoneAction(AuthResult authResult) {
super(authResult);
}
}
@Action(
service = Action.Service.DEFAULT,
path = "/auth/adminUser",
auth = AUTH_ADMIN,
method = GET)
@Action(service = GaeService.DEFAULT, path = "/auth/adminUser", auth = AUTH_ADMIN, method = GET)
public class AuthAdminUserAction extends AuthBase {
AuthAdminUserAction(AuthResult authResult) {
super(authResult);
@@ -204,7 +201,6 @@ public final class RequestHandlerTest {
handler =
RequestHandler.create(
Component.class,
"registry.test",
() ->
new Builder() {
@Override
@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.auth.Auth.AUTH_ADMIN;
import static org.junit.jupiter.api.Assertions.assertThrows;
import google.registry.request.Action.GaeService;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.function.Function;
@@ -41,7 +42,7 @@ public final class RouterTest {
////////////////////////////////////////////////////////////////////////////////////////////////
@Action(service = Action.Service.DEFAULT, path = "/sloth", auth = AUTH_ADMIN)
@Action(service = GaeService.DEFAULT, path = "/sloth", auth = AUTH_ADMIN)
public static final class SlothTask implements Runnable {
@Override
public void run() {}
@@ -71,7 +72,7 @@ public final class RouterTest {
////////////////////////////////////////////////////////////////////////////////////////////////
@Action(service = Action.Service.DEFAULT, path = "/prefix", isPrefix = true, auth = AUTH_ADMIN)
@Action(service = GaeService.DEFAULT, path = "/prefix", isPrefix = true, auth = AUTH_ADMIN)
public static final class PrefixTask implements Runnable {
@Override
public void run() {}
@@ -97,11 +98,7 @@ public final class RouterTest {
////////////////////////////////////////////////////////////////////////////////////////////////
@Action(
service = Action.Service.DEFAULT,
path = "/prefix/long",
isPrefix = true,
auth = AUTH_ADMIN)
@Action(service = GaeService.DEFAULT, path = "/prefix/long", isPrefix = true, auth = AUTH_ADMIN)
public static final class LongTask implements Runnable {
@Override
public void run() {}
@@ -153,13 +150,13 @@ public final class RouterTest {
////////////////////////////////////////////////////////////////////////////////////////////////
@Action(service = Action.Service.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
@Action(service = GaeService.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
public static final class DuplicateTask1 implements Runnable {
@Override
public void run() {}
}
@Action(service = Action.Service.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
@Action(service = GaeService.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
public static final class DuplicateTask2 implements Runnable {
@Override
public void run() {}
@@ -15,10 +15,10 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.Action.Service.BACKEND;
import static google.registry.request.Action.Service.DEFAULT;
import static google.registry.request.Action.Service.PUBAPI;
import static google.registry.request.Action.Service.TOOLS;
import static google.registry.request.Action.GaeService.BACKEND;
import static google.registry.request.Action.GaeService.DEFAULT;
import static google.registry.request.Action.GaeService.PUBAPI;
import static google.registry.request.Action.GaeService.TOOLS;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
@@ -84,9 +84,8 @@ final class GcpProjectConnectionTest {
.thenReturn(new ByteArrayInputStream("MyContent".getBytes(UTF_8)));
when(lowLevelHttpResponse.getStatusCode()).thenReturn(200);
connection = new ServiceConnection();
httpTransport = new TestHttpTransport();
connection.requestFactory = httpTransport.createRequestFactory();
connection = new ServiceConnection(false, httpTransport.createRequestFactory());
}
@Test
@@ -15,7 +15,7 @@
package google.registry.tools;
import static com.google.common.truth.Truth.assertThat;
import static google.registry.request.Action.Service.DEFAULT;
import static google.registry.request.Action.GaeService.DEFAULT;
import org.junit.jupiter.api.Test;
@@ -24,14 +24,14 @@ public class ServiceConnectionTest {
@Test
void testServerUrl_notCanary() {
ServiceConnection connection = new ServiceConnection().withService(DEFAULT, false);
ServiceConnection connection = new ServiceConnection(false, null).withService(DEFAULT, false);
String serverUrl = connection.getServer().toString();
assertThat(serverUrl).isEqualTo("https://default.example.com"); // See default-config.yaml
}
@Test
void testServerUrl_canary() {
ServiceConnection connection = new ServiceConnection().withService(DEFAULT, true);
ServiceConnection connection = new ServiceConnection(false, null).withService(DEFAULT, true);
String serverUrl = connection.getServer().toString();
assertThat(serverUrl).isEqualTo("https://nomulus-dot-default.example.com");
}
@@ -72,7 +72,7 @@ class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase {
new TaskMatcher()
.path(SyncRegistrarsSheetAction.PATH)
.service("Backend")
.method(HttpMethod.GET));
.method(HttpMethod.POST));
assertMetric(CLIENT_ID, "update", "[OWNER]", "SUCCESS");
}