mirror of
https://github.com/google/nomulus
synced 2026-10-01 04:05:49 +00:00
Remove the concept of a GAE service endpoint (#2869)
We don't need to support the mix of GAE and GKE any more so we can get rid of the GaeService bits and unify everything under one constant service. This also allows us to reduce the number of services down to four (FE, BE, PUBAPI, console) which is nice.
This commit is contained in:
@@ -32,8 +32,7 @@ import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import google.registry.batch.CloudTasksUtils.SerializableCloudTasksClient;
|
||||
import google.registry.request.Action;
|
||||
import google.registry.request.Action.GaeService;
|
||||
import google.registry.request.Action.GkeService;
|
||||
import google.registry.request.Action.Service;
|
||||
import google.registry.request.auth.Auth;
|
||||
import google.registry.testing.CloudTasksHelper.FakeGoogleCredentialsBundle;
|
||||
import google.registry.testing.FakeClock;
|
||||
@@ -87,13 +86,13 @@ public class CloudTasksUtilsTest {
|
||||
void testFailure_illegalPath() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> cloudTasksUtils.createTask("the/path", GET, GkeService.BACKEND, params));
|
||||
() -> cloudTasksUtils.createTask("the/path", GET, Service.BACKEND, params));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> cloudTasksUtils.createTask(null, GET, GkeService.BACKEND, params));
|
||||
() -> cloudTasksUtils.createTask(null, GET, Service.BACKEND, params));
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> cloudTasksUtils.createTask("", GET, GkeService.BACKEND, params));
|
||||
() -> cloudTasksUtils.createTask("", GET, Service.BACKEND, params));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,24 +125,14 @@ public class CloudTasksUtilsTest {
|
||||
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");
|
||||
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
|
||||
verifyOidcToken(task);
|
||||
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);
|
||||
void testSuccess_createTasks_WithPathAndService() {
|
||||
Task task = cloudTasksUtils.createTask("/the/path", GET, Service.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");
|
||||
@@ -169,7 +158,7 @@ public class CloudTasksUtilsTest {
|
||||
void testSuccess_createPostTasks() {
|
||||
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().getUrl()).isEqualTo("https://backend.registry.test/the/path");
|
||||
assertThat(task.getHttpRequest().getHeadersMap().get("Content-Type"))
|
||||
.isEqualTo("application/x-www-form-urlencoded");
|
||||
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8))
|
||||
@@ -182,7 +171,7 @@ public class CloudTasksUtilsTest {
|
||||
void testSuccess_createGetTasks_withNullParams() {
|
||||
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");
|
||||
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.registry.test/the/path");
|
||||
verifyOidcToken(task);
|
||||
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
|
||||
}
|
||||
@@ -191,7 +180,7 @@ public class CloudTasksUtilsTest {
|
||||
void testSuccess_createPostTasks_withNullParams() {
|
||||
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().getUrl()).isEqualTo("https://backend.registry.test/the/path");
|
||||
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEmpty();
|
||||
verifyOidcToken(task);
|
||||
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
|
||||
@@ -201,7 +190,7 @@ public class CloudTasksUtilsTest {
|
||||
void testSuccess_createGetTasks_withEmptyParams() {
|
||||
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");
|
||||
assertThat(task.getHttpRequest().getUrl()).isEqualTo("https://backend.registry.test/the/path");
|
||||
verifyOidcToken(task);
|
||||
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
|
||||
}
|
||||
@@ -210,7 +199,7 @@ public class CloudTasksUtilsTest {
|
||||
void testSuccess_createPostTasks_withEmptyParams() {
|
||||
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().getUrl()).isEqualTo("https://backend.registry.test/the/path");
|
||||
assertThat(task.getHttpRequest().getBody().toString(StandardCharsets.UTF_8)).isEmpty();
|
||||
verifyOidcToken(task);
|
||||
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
|
||||
@@ -223,7 +212,7 @@ public class CloudTasksUtilsTest {
|
||||
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");
|
||||
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
|
||||
verifyOidcToken(task);
|
||||
|
||||
assertThat(task.getScheduleTime().getSeconds()).isNotEqualTo(0);
|
||||
@@ -241,7 +230,7 @@ public class CloudTasksUtilsTest {
|
||||
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");
|
||||
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
|
||||
verifyOidcToken(task);
|
||||
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
|
||||
}
|
||||
@@ -251,7 +240,7 @@ public class CloudTasksUtilsTest {
|
||||
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");
|
||||
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
|
||||
verifyOidcToken(task);
|
||||
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
|
||||
}
|
||||
@@ -263,7 +252,7 @@ public class CloudTasksUtilsTest {
|
||||
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");
|
||||
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
|
||||
verifyOidcToken(task);
|
||||
assertThat(Instant.ofEpochSecond(task.getScheduleTime().getSeconds()))
|
||||
.isEqualTo(Instant.ofEpochMilli(clock.nowUtc().plusMinutes(10).getMillis()));
|
||||
@@ -274,14 +263,13 @@ public class CloudTasksUtilsTest {
|
||||
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");
|
||||
.isEqualTo("https://backend.registry.test/the/path?key1=val1&key2=val2&key1=val3");
|
||||
verifyOidcToken(task);
|
||||
assertThat(task.getScheduleTime().getSeconds()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Action(
|
||||
service = GaeService.BACKEND,
|
||||
gkeService = GkeService.BACKEND,
|
||||
service = Service.BACKEND,
|
||||
path = "/the/path",
|
||||
method = {GET, POST},
|
||||
auth = Auth.AUTH_ADMIN)
|
||||
@@ -292,8 +280,7 @@ public class CloudTasksUtilsTest {
|
||||
}
|
||||
|
||||
@Action(
|
||||
service = GaeService.TOOLS,
|
||||
gkeService = GkeService.BACKEND,
|
||||
service = Service.BACKEND,
|
||||
path = "/other/path",
|
||||
method = {GET},
|
||||
auth = Auth.AUTH_ADMIN)
|
||||
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
// Copyright 2025 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.beam.common;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import google.registry.util.RegistryEnvironment;
|
||||
import org.apache.beam.sdk.options.PipelineOptionsFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RegistryPipelineWorkerInitializerTest {
|
||||
|
||||
@Test
|
||||
void test() {
|
||||
RegistryPipelineOptions options =
|
||||
PipelineOptionsFactory.fromArgs(
|
||||
"--registryEnvironment=ALPHA", "--isolationOverride=TRANSACTION_SERIALIZABLE")
|
||||
.withValidation()
|
||||
.as(RegistryPipelineOptions.class);
|
||||
new RegistryPipelineWorkerInitializer().beforeProcessing(options);
|
||||
assertThat(RegistryEnvironment.isOnJetty()).isTrue();
|
||||
System.clearProperty("google.registry.jetty");
|
||||
}
|
||||
}
|
||||
@@ -224,11 +224,11 @@ class TldFanoutActionTest {
|
||||
String expectedResponse =
|
||||
String.format(
|
||||
"""
|
||||
OK: Launched the following 3 tasks in queue the-queue
|
||||
- Task: '%s', tld: 'com', endpoint: 'https://backend.example.com/the/servlet'
|
||||
- Task: '%s', tld: 'net', endpoint: 'https://backend.example.com/the/servlet'
|
||||
- Task: '%s', tld: 'org', endpoint: 'https://backend.example.com/the/servlet'
|
||||
""",
|
||||
OK: Launched the following 3 tasks in queue the-queue
|
||||
- Task: '%s', tld: 'com', endpoint: 'https://backend.registry.test/the/servlet'
|
||||
- Task: '%s', tld: 'net', endpoint: 'https://backend.registry.test/the/servlet'
|
||||
- Task: '%s', tld: 'org', endpoint: 'https://backend.registry.test/the/servlet'
|
||||
""",
|
||||
taskList.get(0).getName(), taskList.get(1).getName(), taskList.get(2).getName());
|
||||
assertThat(response.getPayload()).isEqualTo(expectedResponse);
|
||||
}
|
||||
@@ -243,9 +243,9 @@ class TldFanoutActionTest {
|
||||
String expectedResponse =
|
||||
String.format(
|
||||
"""
|
||||
OK: Launched the following 1 tasks in queue the-queue
|
||||
- Task: '%s', tld: '', endpoint: 'https://backend.example.com/the/servlet'
|
||||
""",
|
||||
OK: Launched the following 1 tasks in queue the-queue
|
||||
- Task: '%s', tld: '', endpoint: 'https://backend.registry.test/the/servlet'
|
||||
""",
|
||||
taskList.get(0).getName());
|
||||
assertThat(response.getPayload()).isEqualTo(expectedResponse);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public final class OteAccountBuilderTest {
|
||||
cloudTasksHelper.assertTasksEnqueued(
|
||||
"console-user-group-update",
|
||||
new TaskMatcher()
|
||||
.service("TOOLS")
|
||||
.service("BACKEND")
|
||||
.method(HttpMethod.POST)
|
||||
.path("/_dr/admin/updateUserGroup")
|
||||
.param("userEmailAddress", emailAddress)
|
||||
|
||||
@@ -166,7 +166,7 @@ public class UserTest extends EntityTestCase {
|
||||
cloudTasksHelper.assertTasksEnqueued(
|
||||
"console-user-group-update",
|
||||
new TaskMatcher()
|
||||
.service("TOOLS")
|
||||
.service("BACKEND")
|
||||
.method(HttpMethod.POST)
|
||||
.path("/_dr/admin/updateUserGroup")
|
||||
.param("userEmailAddress", "email@example.com")
|
||||
@@ -222,7 +222,7 @@ public class UserTest extends EntityTestCase {
|
||||
cloudTasksHelper.assertTasksEnqueued(
|
||||
"console-user-group-update",
|
||||
new TaskMatcher()
|
||||
.service("TOOLS")
|
||||
.service("BACKEND")
|
||||
.method(HttpMethod.POST)
|
||||
.path("/_dr/admin/updateUserGroup")
|
||||
.param("userEmailAddress", "email@example.com")
|
||||
|
||||
@@ -30,7 +30,6 @@ 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;
|
||||
@@ -45,7 +44,7 @@ class RdapActionBaseTest extends RdapActionBaseTestCase<RdapActionBaseTest.RdapT
|
||||
|
||||
/** Dummy RdapActionBase subclass used for testing. */
|
||||
@Action(
|
||||
service = GaeService.PUBAPI,
|
||||
service = Action.Service.PUBAPI,
|
||||
path = "/rdap/test/",
|
||||
method = {GET, HEAD},
|
||||
auth = Auth.AUTH_PUBLIC)
|
||||
|
||||
@@ -31,7 +31,6 @@ 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;
|
||||
@@ -49,7 +48,7 @@ import org.junit.jupiter.api.Test;
|
||||
public final class RequestHandlerTest {
|
||||
|
||||
@Action(
|
||||
service = GaeService.DEFAULT,
|
||||
service = Action.Service.FRONTEND,
|
||||
path = "/bumblebee",
|
||||
method = {GET, POST},
|
||||
isPrefix = true,
|
||||
@@ -60,7 +59,7 @@ public final class RequestHandlerTest {
|
||||
}
|
||||
|
||||
@Action(
|
||||
service = GaeService.DEFAULT,
|
||||
service = Action.Service.FRONTEND,
|
||||
path = "/sloth",
|
||||
method = POST,
|
||||
automaticallyPrintOk = true,
|
||||
@@ -71,7 +70,7 @@ public final class RequestHandlerTest {
|
||||
}
|
||||
|
||||
@Action(
|
||||
service = GaeService.DEFAULT,
|
||||
service = Action.Service.FRONTEND,
|
||||
path = "/safe-sloth",
|
||||
method = {GET, POST},
|
||||
auth = AUTH_PUBLIC)
|
||||
@@ -80,7 +79,7 @@ public final class RequestHandlerTest {
|
||||
public void run() {}
|
||||
}
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/fail", auth = AUTH_PUBLIC)
|
||||
@Action(service = Action.Service.FRONTEND, path = "/fail", auth = AUTH_PUBLIC)
|
||||
public static final class FailTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -88,7 +87,7 @@ public final class RequestHandlerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/failAtConstruction", auth = AUTH_PUBLIC)
|
||||
@Action(service = Action.Service.FRONTEND, path = "/failAtConstruction", auth = AUTH_PUBLIC)
|
||||
public static final class FailAtConstructionTask implements Runnable {
|
||||
FailAtConstructionTask() {
|
||||
throw new ServiceUnavailableException("Fail at construction");
|
||||
@@ -113,14 +112,18 @@ public final class RequestHandlerTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/auth/none", auth = AUTH_PUBLIC, method = GET)
|
||||
@Action(service = Action.Service.FRONTEND, path = "/auth/none", auth = AUTH_PUBLIC, method = GET)
|
||||
public class AuthNoneAction extends AuthBase {
|
||||
AuthNoneAction(AuthResult authResult) {
|
||||
super(authResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/auth/adminUser", auth = AUTH_ADMIN, method = GET)
|
||||
@Action(
|
||||
service = Action.Service.FRONTEND,
|
||||
path = "/auth/adminUser",
|
||||
auth = AUTH_ADMIN,
|
||||
method = GET)
|
||||
public class AuthAdminUserAction extends AuthBase {
|
||||
AuthAdminUserAction(AuthResult authResult) {
|
||||
super(authResult);
|
||||
@@ -210,6 +213,7 @@ public final class RequestHandlerTest {
|
||||
}
|
||||
},
|
||||
requestAuthenticator);
|
||||
when(req.getServerName()).thenReturn("frontend.registry.test");
|
||||
when(rsp.getWriter()).thenReturn(new PrintWriter(httpOutput));
|
||||
handler.requestMetrics = requestMetrics;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ 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;
|
||||
@@ -42,7 +41,7 @@ public final class RouterTest {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/sloth", auth = AUTH_ADMIN)
|
||||
@Action(service = Action.Service.FRONTEND, path = "/sloth", auth = AUTH_ADMIN)
|
||||
public static final class SlothTask implements Runnable {
|
||||
@Override
|
||||
public void run() {}
|
||||
@@ -72,7 +71,7 @@ public final class RouterTest {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/prefix", isPrefix = true, auth = AUTH_ADMIN)
|
||||
@Action(service = Action.Service.FRONTEND, path = "/prefix", isPrefix = true, auth = AUTH_ADMIN)
|
||||
public static final class PrefixTask implements Runnable {
|
||||
@Override
|
||||
public void run() {}
|
||||
@@ -98,7 +97,11 @@ public final class RouterTest {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/prefix/long", isPrefix = true, auth = AUTH_ADMIN)
|
||||
@Action(
|
||||
service = Action.Service.FRONTEND,
|
||||
path = "/prefix/long",
|
||||
isPrefix = true,
|
||||
auth = AUTH_ADMIN)
|
||||
public static final class LongTask implements Runnable {
|
||||
@Override
|
||||
public void run() {}
|
||||
@@ -150,13 +153,13 @@ public final class RouterTest {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
|
||||
@Action(service = Action.Service.FRONTEND, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
|
||||
public static final class DuplicateTask1 implements Runnable {
|
||||
@Override
|
||||
public void run() {}
|
||||
}
|
||||
|
||||
@Action(service = GaeService.DEFAULT, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
|
||||
@Action(service = Action.Service.FRONTEND, path = "/samePathAsOtherTask", auth = AUTH_ADMIN)
|
||||
public static final class DuplicateTask2 implements Runnable {
|
||||
@Override
|
||||
public void run() {}
|
||||
|
||||
+1
@@ -81,6 +81,7 @@ public class OidcTokenAuthenticationMechanismTest {
|
||||
payload.setEmail(email);
|
||||
payload.setSubject(gaiaId);
|
||||
user = createAdminUser(email);
|
||||
when(request.getServerName()).thenReturn("frontend.registry.test");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -246,7 +246,7 @@ public class CloudTasksHelper implements Serializable {
|
||||
private static class MatchableTask extends ImmutableObject {
|
||||
|
||||
private static final Pattern HOSTNAME_PATTERN =
|
||||
Pattern.compile("(?<=https://)[a-z]+(?=\\.example\\.com)");
|
||||
Pattern.compile("(?<=https://)[a-z]+(?=\\.registry\\.test)");
|
||||
String taskName;
|
||||
String service;
|
||||
HttpMethod method;
|
||||
@@ -271,7 +271,7 @@ public class CloudTasksHelper implements Serializable {
|
||||
Matcher hostnameMatcher = HOSTNAME_PATTERN.matcher(url);
|
||||
assertThat(hostnameMatcher.find()).isTrue();
|
||||
service = Ascii.toLowerCase(hostnameMatcher.group());
|
||||
path = url.substring(String.format("https://%s.example.com", service).length());
|
||||
path = url.substring(String.format("https://%s.registry.test", service).length());
|
||||
method = request.getHttpMethod();
|
||||
scheduleTime = task.getScheduleTime();
|
||||
ImmutableMultimap.Builder<String, String> headerBuilder = new ImmutableMultimap.Builder<>();
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
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;
|
||||
@@ -30,7 +26,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.net.MediaType;
|
||||
import google.registry.request.Action.Service;
|
||||
import google.registry.request.Action;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
@@ -48,15 +44,16 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
command.setConnection(connection);
|
||||
when(connection.withService(any(Service.class), anyBoolean())).thenReturn(connectionForService);
|
||||
when(connection.withService(any(Action.Service.class), anyBoolean()))
|
||||
.thenReturn(connectionForService);
|
||||
}
|
||||
|
||||
@Captor ArgumentCaptor<ImmutableMap<String, String>> urlParamCaptor;
|
||||
|
||||
@Test
|
||||
void testGetInvocation() throws Exception {
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--service=TOOLS");
|
||||
verify(connection).withService(eq(TOOLS), eq(false));
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--service=BACKEND");
|
||||
verify(connection).withService(eq(Action.Service.BACKEND), eq(false));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendGetRequest(eq("/foo/bar?a=1&b=2"), eq(ImmutableMap.<String, String>of()));
|
||||
@@ -65,7 +62,7 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
@Test
|
||||
void testExplicitGetInvocation() throws Exception {
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--request=GET", "--service=BACKEND");
|
||||
verify(connection).withService(eq(BACKEND), eq(false));
|
||||
verify(connection).withService(eq(Action.Service.BACKEND), eq(false));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendGetRequest(eq("/foo/bar?a=1&b=2"), eq(ImmutableMap.<String, String>of()));
|
||||
@@ -73,8 +70,8 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
|
||||
@Test
|
||||
void testPostInvocation() throws Exception {
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--data=some data", "--service=DEFAULT");
|
||||
verify(connection).withService(eq(DEFAULT), eq(false));
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--data=some data", "--service=FRONTEND");
|
||||
verify(connection).withService(eq(Action.Service.FRONTEND), eq(false));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendPostRequest(
|
||||
@@ -89,9 +86,9 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
runCommand(
|
||||
"--path=/foo/bar?a=1&b=2",
|
||||
"--data=some data",
|
||||
"--service=DEFAULT",
|
||||
"--service=FRONTEND",
|
||||
"--content-type=application/json");
|
||||
verify(connection).withService(eq(DEFAULT), eq(false));
|
||||
verify(connection).withService(eq(Action.Service.FRONTEND), eq(false));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendPostRequest(
|
||||
@@ -110,7 +107,7 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
runCommand(
|
||||
"--path=/foo/bar?a=1&b=2",
|
||||
"--data=some data",
|
||||
"--service=DEFAULT",
|
||||
"--service=FRONTEND",
|
||||
"--content-type=bad"));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verifyNoMoreInteractions(connectionForService);
|
||||
@@ -120,7 +117,7 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
void testMultiDataPost() throws Exception {
|
||||
runCommand(
|
||||
"--path=/foo/bar?a=1&b=2", "--data=first=100", "-d", "second=200", "--service=PUBAPI");
|
||||
verify(connection).withService(eq(PUBAPI), eq(false));
|
||||
verify(connection).withService(eq(Action.Service.PUBAPI), eq(false));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendPostRequest(
|
||||
@@ -134,7 +131,7 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
void testDataDoesntSplit() throws Exception {
|
||||
runCommand(
|
||||
"--path=/foo/bar?a=1&b=2", "--data=one,two", "--service=PUBAPI");
|
||||
verify(connection).withService(eq(PUBAPI), eq(false));
|
||||
verify(connection).withService(eq(Action.Service.PUBAPI), eq(false));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendPostRequest(
|
||||
@@ -146,8 +143,8 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
|
||||
@Test
|
||||
void testExplicitPostInvocation() throws Exception {
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--request=POST", "--service=TOOLS");
|
||||
verify(connection).withService(eq(TOOLS), eq(false));
|
||||
runCommand("--path=/foo/bar?a=1&b=2", "--request=POST", "--service=PUBAPI");
|
||||
verify(connection).withService(eq(Action.Service.PUBAPI), eq(false));
|
||||
verifyNoMoreInteractions(connection);
|
||||
verify(connectionForService)
|
||||
.sendPostRequest(
|
||||
@@ -168,7 +165,7 @@ class CurlCommandTest extends CommandTestCase<CurlCommand> {
|
||||
"--path=/foo/bar?a=1&b=2",
|
||||
"--request=GET",
|
||||
"--data=inappropriate data",
|
||||
"--service=TOOLS"));
|
||||
"--service=BACKEND"));
|
||||
assertThat(thrown).hasMessageThat().contains("You may not specify a body for a get method.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ final class GcpProjectConnectionTest {
|
||||
when(lowLevelHttpResponse.getStatusCode()).thenReturn(200);
|
||||
|
||||
httpTransport = new TestHttpTransport();
|
||||
connection = new ServiceConnection(false, false, httpTransport.createRequestFactory());
|
||||
connection = new ServiceConnection(false, httpTransport.createRequestFactory());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +96,7 @@ final class GcpProjectConnectionTest {
|
||||
.isEqualTo("MyContent");
|
||||
assertThat(httpTransport.method).isEqualTo("GET");
|
||||
assertThat(httpTransport.url)
|
||||
.isEqualTo("https://tools.example.com/my/path?query&key1=value1&key2=value2");
|
||||
.isEqualTo("https://backend.registry.test/my/path?query&key1=value1&key2=value2");
|
||||
assertThat(lowLevelHttpRequest.headers).containsEntry("Cache-Control", "no-cache");
|
||||
assertThat(lowLevelHttpRequest.headers).containsEntry("x-requested-with", "RegistryTool");
|
||||
}
|
||||
@@ -112,7 +112,7 @@ final class GcpProjectConnectionTest {
|
||||
.isEqualTo("MyContent");
|
||||
assertThat(httpTransport.method).isEqualTo("POST");
|
||||
assertThat(httpTransport.url)
|
||||
.isEqualTo("https://tools.example.com/my/path?query&key1=value1&key2=value2");
|
||||
.isEqualTo("https://backend.registry.test/my/path?query&key1=value1&key2=value2");
|
||||
assertThat(lowLevelHttpRequest.getContentType()).isEqualTo("text/plain; charset=utf-8");
|
||||
assertThat(lowLevelHttpRequest.getContentString()).isEqualTo("some data");
|
||||
assertThat(lowLevelHttpRequest.headers).containsEntry("Cache-Control", "no-cache");
|
||||
@@ -129,7 +129,7 @@ final class GcpProjectConnectionTest {
|
||||
"/my/path?query", ImmutableMap.of("string", "value1", "bool", true)))
|
||||
.containsExactly("key", "value");
|
||||
assertThat(httpTransport.method).isEqualTo("POST");
|
||||
assertThat(httpTransport.url).isEqualTo("https://tools.example.com/my/path?query");
|
||||
assertThat(httpTransport.url).isEqualTo("https://backend.registry.test/my/path?query");
|
||||
assertThat(lowLevelHttpRequest.getContentType()).isEqualTo("application/json; charset=utf-8");
|
||||
assertThat(lowLevelHttpRequest.getContentString())
|
||||
.isEqualTo("{\"string\":\"value1\",\"bool\":true}");
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
package google.registry.tools;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static google.registry.request.Action.GaeService.DEFAULT;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -28,7 +26,7 @@ import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpRequestFactory;
|
||||
import com.google.api.client.http.HttpResponse;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import google.registry.request.Action.GkeService;
|
||||
import google.registry.request.Action.Service;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -38,28 +36,9 @@ public class ServiceConnectionTest {
|
||||
@Test
|
||||
void testSuccess_serverUrl_notCanary() {
|
||||
ServiceConnection connection =
|
||||
new ServiceConnection(false, false, null).withService(DEFAULT, false);
|
||||
new ServiceConnection(false, null).withService(Service.FRONTEND, false);
|
||||
String serverUrl = connection.getServer().toString();
|
||||
assertThat(serverUrl).isEqualTo("https://default.example.com"); // See default-config.yaml
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFailure_mixedService() throws Exception {
|
||||
IllegalArgumentException thrown =
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> {
|
||||
new ServiceConnection(true, false, null).withService(DEFAULT, true);
|
||||
});
|
||||
assertThat(thrown).hasMessageThat().contains("Cannot switch from GkeService to GaeService");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSuccess_serverUrl_gae_canary() {
|
||||
ServiceConnection connection =
|
||||
new ServiceConnection(false, false, null).withService(DEFAULT, true);
|
||||
String serverUrl = connection.getServer().toString();
|
||||
assertThat(serverUrl).isEqualTo("https://nomulus-dot-default.example.com");
|
||||
assertThat(serverUrl).isEqualTo("https://frontend.registry.test"); // See default-config.yaml
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +52,7 @@ public class ServiceConnectionTest {
|
||||
when(request.execute()).thenReturn(response);
|
||||
when(response.getContent()).thenReturn(ByteArrayInputStream.nullInputStream());
|
||||
ServiceConnection connection =
|
||||
new ServiceConnection(true, false, factory).withService(GkeService.PUBAPI, true);
|
||||
new ServiceConnection(false, factory).withService(Service.PUBAPI, true);
|
||||
String serverUrl = connection.getServer().toString();
|
||||
assertThat(serverUrl).isEqualTo("https://pubapi.registry.test");
|
||||
connection.sendGetRequest("/path", ImmutableMap.of());
|
||||
|
||||
@@ -135,7 +135,7 @@ class SetupOteCommandTest extends CommandTestCase<SetupOteCommand> {
|
||||
cloudTasksHelper.assertTasksEnqueued(
|
||||
"console-user-group-update",
|
||||
new TaskMatcher()
|
||||
.service("TOOLS")
|
||||
.service("BACKEND")
|
||||
.method(HttpMethod.POST)
|
||||
.path("/_dr/admin/updateUserGroup")
|
||||
.param("userEmailAddress", emailAddress)
|
||||
|
||||
Reference in New Issue
Block a user