diff --git a/core/src/main/java/google/registry/config/CredentialModule.java b/core/src/main/java/google/registry/config/CredentialModule.java index bee6f0fdf..7b6c0e6e6 100644 --- a/core/src/main/java/google/registry/config/CredentialModule.java +++ b/core/src/main/java/google/registry/config/CredentialModule.java @@ -144,7 +144,6 @@ public abstract class CredentialModule { Duration tokenRefreshDelay, Clock clock) { GoogleCredentials signer = credentialsBundle.getGoogleCredentials(); - checkArgument( signer instanceof ServiceAccountSigner, "Expecting a ServiceAccountSigner, found %s.", diff --git a/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java b/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java index 093834868..b59750206 100644 --- a/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java +++ b/core/src/main/java/google/registry/ui/server/console/ConsoleUsersAction.java @@ -165,7 +165,7 @@ public class ConsoleUsersAction extends ConsoleApiAction { User updatedUser = updateUserRegistrarRoles(email, registrarId, null); // User has no registrars assigned - if (updatedUser.getUserRoles().getRegistrarRoles().size() == 0) { + if (updatedUser.getUserRoles().getRegistrarRoles().isEmpty()) { try { directory.users().delete(email).execute(); } catch (IOException e) { diff --git a/core/src/test/java/google/registry/module/frontend/FrontendTestComponent.java b/core/src/test/java/google/registry/module/frontend/FrontendTestComponent.java new file mode 100644 index 000000000..0a0256bcc --- /dev/null +++ b/core/src/test/java/google/registry/module/frontend/FrontendTestComponent.java @@ -0,0 +1,60 @@ +// 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.module.frontend; + +import dagger.Component; +import google.registry.config.CloudTasksUtilsModule; +import google.registry.config.CredentialModule; +import google.registry.config.RegistryConfig; +import google.registry.flows.ServerTridProviderModule; +import google.registry.flows.custom.CustomLogicFactoryModule; +import google.registry.groups.GmailModule; +import google.registry.groups.GroupsModule; +import google.registry.groups.GroupssettingsModule; +import google.registry.keyring.KeyringModule; +import google.registry.keyring.api.KeyModule; +import google.registry.monitoring.whitebox.StackdriverModule; +import google.registry.privileges.secretmanager.SecretManagerModule; +import google.registry.request.Modules; +import google.registry.request.auth.AuthModule; +import google.registry.ui.ConsoleDebug; +import google.registry.util.UtilsModule; +import jakarta.inject.Singleton; + +@Singleton +@Component( + modules = { + AuthModule.class, + CloudTasksUtilsModule.class, + RegistryConfig.ConfigModule.class, + ConsoleDebug.ConsoleConfigModule.class, + CredentialModule.class, + CustomLogicFactoryModule.class, + CloudTasksUtilsModule.class, + FrontendRequestComponent.FrontendRequestComponentModule.class, + GmailModule.class, + GroupsModule.class, + GroupssettingsModule.class, + MockDirectoryModule.class, + Modules.GsonModule.class, + KeyModule.class, + KeyringModule.class, + Modules.NetHttpTransportModule.class, + SecretManagerModule.class, + ServerTridProviderModule.class, + StackdriverModule.class, + UtilsModule.class + }) +interface FrontendTestComponent extends FrontendComponent {} diff --git a/core/src/test/java/google/registry/module/frontend/FrontendTestServlet.java b/core/src/test/java/google/registry/module/frontend/FrontendTestServlet.java new file mode 100644 index 000000000..dea6429b0 --- /dev/null +++ b/core/src/test/java/google/registry/module/frontend/FrontendTestServlet.java @@ -0,0 +1,30 @@ +// 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.module.frontend; + +import com.google.monitoring.metrics.MetricReporter; +import dagger.Lazy; +import google.registry.module.ServletBase; + +public class FrontendTestServlet extends ServletBase { + + private static final FrontendTestComponent component = DaggerFrontendTestComponent.create(); + private static final FrontendRequestHandler requestHandler = component.requestHandler(); + private static final Lazy metricReporter = component.metricReporter(); + + public FrontendTestServlet() { + super(requestHandler, metricReporter); + } +} diff --git a/core/src/test/java/google/registry/module/frontend/MockDirectoryModule.java b/core/src/test/java/google/registry/module/frontend/MockDirectoryModule.java new file mode 100644 index 000000000..859569217 --- /dev/null +++ b/core/src/test/java/google/registry/module/frontend/MockDirectoryModule.java @@ -0,0 +1,45 @@ +// 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.module.frontend; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.google.api.services.directory.Directory; +import com.google.api.services.directory.model.User; +import dagger.Module; +import dagger.Provides; +import java.io.IOException; + +@Module +public class MockDirectoryModule { + @Provides + static Directory provideDirectory() { + Directory directory = mock(Directory.class); + Directory.Users users = mock(Directory.Users.class); + Directory.Users.Insert insert = mock(Directory.Users.Insert.class); + Directory.Users.Delete delete = mock(Directory.Users.Delete.class); + when(directory.users()).thenReturn(users); + try { + when(users.insert(any(User.class))).thenReturn(insert); + when(users.delete(anyString())).thenReturn(delete); + } catch (IOException e) { + throw new RuntimeException(e); + } + return directory; + } +} diff --git a/core/src/test/java/google/registry/server/Fixture.java b/core/src/test/java/google/registry/server/Fixture.java index c92e5b14c..4f5a040da 100644 --- a/core/src/test/java/google/registry/server/Fixture.java +++ b/core/src/test/java/google/registry/server/Fixture.java @@ -26,8 +26,12 @@ import static google.registry.testing.DatabaseHelper.persistResource; import static org.joda.money.CurrencyUnit.USD; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import google.registry.model.OteStatsTestHelper; +import google.registry.model.console.RegistrarRole; +import google.registry.model.console.User; +import google.registry.model.console.UserRoles; import google.registry.model.contact.Contact; import google.registry.model.contact.ContactAddress; import google.registry.model.contact.PostalInfo; @@ -166,6 +170,30 @@ public enum Fixture { .asBuilder() .setAllowedTlds(ImmutableSet.of("example", "xn--q9jyb4c")) .build()); + + persistResource( + new User.Builder() + .setEmailAddress("primary@registry.example") + .setRegistryLockEmailAddress("primary@theregistrar.com") + .setUserRoles( + new UserRoles.Builder() + .setRegistrarRoles( + ImmutableMap.of("TheRegistrar", RegistrarRole.PRIMARY_CONTACT)) + .build()) + .setRegistryLockPassword("registryLockPassword") + .build()); + persistResource( + new User.Builder() + .setEmailAddress("accountmanager@registry.example") + .setRegistryLockEmailAddress("accountmanager@theregistrar.com") + .setUserRoles( + new UserRoles.Builder() + .setRegistrarRoles( + ImmutableMap.of( + "TheRegistrar", RegistrarRole.ACCOUNT_MANAGER_WITH_REGISTRY_LOCK)) + .build()) + .setRegistryLockPassword("registryLockPassword") + .build()); } }; diff --git a/core/src/test/java/google/registry/server/RegistryTestServer.java b/core/src/test/java/google/registry/server/RegistryTestServer.java index c59db4d4a..bf2a5b6bc 100644 --- a/core/src/test/java/google/registry/server/RegistryTestServer.java +++ b/core/src/test/java/google/registry/server/RegistryTestServer.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.net.HostAndPort; import google.registry.module.backend.BackendServlet; import google.registry.module.frontend.FrontendServlet; +import google.registry.module.frontend.FrontendTestServlet; import java.net.URL; import java.nio.file.Path; @@ -49,7 +50,7 @@ public final class RegistryTestServer { route("/whois/*", FrontendServlet.class), route("/rdap/*", FrontendServlet.class), route("/check", FrontendServlet.class), - route("/console-api/*", FrontendServlet.class), + route("/console-api/*", FrontendTestServlet.class), // Proxy Services route("/_dr/epp", FrontendServlet.class), diff --git a/core/src/test/java/google/registry/server/RegistryTestServerMain.java b/core/src/test/java/google/registry/server/RegistryTestServerMain.java index 3b67eed0e..437667918 100644 --- a/core/src/test/java/google/registry/server/RegistryTestServerMain.java +++ b/core/src/test/java/google/registry/server/RegistryTestServerMain.java @@ -26,6 +26,7 @@ import google.registry.persistence.transaction.JpaTestExtensions; import google.registry.persistence.transaction.JpaTransactionManagerExtension; import google.registry.request.auth.AuthResult; import google.registry.request.auth.OidcTokenAuthenticationMechanism; +import google.registry.testing.DatabaseHelper; import google.registry.tools.params.HostAndPortParameter; import google.registry.ui.ConsoleDebug; import java.util.List; @@ -106,47 +107,48 @@ public final class RegistryTestServerMain { System.out.printf( """ - CHARLESTON ROAD REGISTRY SHARED REGISTRATION SYSTEM - ICANN-GTLD-AGB-20120604 + CHARLESTON ROAD REGISTRY SHARED REGISTRATION SYSTEM + ICANN-GTLD-AGB-20120604 - %s ▓█████▄ ▒█████ ███▄ ▄███▓ ▄▄▄ ██▓ ███▄ █ - ▒██▀ ██▌▒██▒ ██▒▓██▒▀█▀ ██▒▒████▄ ▓██▒ ██ ▀█ █ - ░██ █▌▒██░ ██▒▓██ ▓██░▒██ ▀█▄ ▒██▒▓██ ▀█ ██▒ - ░▓█▄ ▌▒██ ██░▒██ ▒██ ░██▄▄▄▄██ ░██░▓██▒ ▐▌██▒ - ░▒████▓ ░ ████▓▒░▒██▒ ░██▒ ▓█ ▓██▒░██░▒██░ ▓██░ - ▒▒▓ ▒ ░ ▒░▒░▒░ ░ ▒░ ░ ░ ▒▒ ▓▒█░░▓ ░ ▒░ ▒ ▒ - ░ ▒ ▒ ░ ▒ ▒░ ░ ░ ░ ▒ ▒▒ ░ ▒ ░░ ░░ ░ ▒░ - ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒ ▒ ░ ░ ░ ░ - ░ ░ ░ ░ ░ ░ ░ ░ - ░ - %s ██▀███ ▓█████ ▄████ ██▓ ██████ ▄▄▄█████▓ ██▀███ ▓██ ██▓ - ▓██ ▒ ██▒▓█ ▀ ██▒ ▀█▒▓██▒▒██ ▒ ▓ ██▒ ▓▒▓██ ▒ ██▒▒██ ██▒ - ▓██ ░▄█ ▒▒███ ▒██░▄▄▄░▒██▒░ ▓██▄ ▒ ▓██░ ▒░▓██ ░▄█ ▒ ▒██ ██░ - ▒██▀▀█▄ ▒▓█ ▄ ░▓█ ██▓░██░ ▒ ██▒░ ▓██▓ ░ ▒██▀▀█▄ ░ ▐██▓░ - ░██▓ ▒██▒░▒████▒░▒▓███▀▒░██░▒██████▒▒ ▒██▒ ░ ░██▓ ▒██▒ ░ ██▒▓░ - ░ ▒▓ ░▒▓░░░ ▒░ ░ ░▒ ▒ ░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░ ░ ▒▓ ░▒▓░ ██▒▒▒ - ░▒ ░ ▒░ ░ ░ ░ ░ ░ ▒ ░░ ░▒ ░ ░ ░ ░▒ ░ ▒░▓██ ░▒░ - ░░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░░ ░ ▒ ▒ ░░ - ░ ░ ░ ░ ░ ░ ░ ░ ░ - ░ ░ - %s(✿◕ ‿◕ )ノ%s - """, +%s ▓█████▄ ▒█████ ███▄ ▄███▓ ▄▄▄ ██▓ ███▄ █ + ▒██▀ ██▌▒██▒ ██▒▓██▒▀█▀ ██▒▒████▄ ▓██▒ ██ ▀█ █ + ░██ █▌▒██░ ██▒▓██ ▓██░▒██ ▀█▄ ▒██▒▓██ ▀█ ██▒ + ░▓█▄ ▌▒██ ██░▒██ ▒██ ░██▄▄▄▄██ ░██░▓██▒ ▐▌██▒ + ░▒████▓ ░ ████▓▒░▒██▒ ░██▒ ▓█ ▓██▒░██░▒██░ ▓██░ + ▒▒▓ ▒ ░ ▒░▒░▒░ ░ ▒░ ░ ░ ▒▒ ▓▒█░░▓ ░ ▒░ ▒ ▒ + ░ ▒ ▒ ░ ▒ ▒░ ░ ░ ░ ▒ ▒▒ ░ ▒ ░░ ░░ ░ ▒░ + ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒ ▒ ░ ░ ░ ░ + ░ ░ ░ ░ ░ ░ ░ ░ + ░ +%s ██▀███ ▓█████ ▄████ ██▓ ██████ ▄▄▄█████▓ ██▀███ ▓██ ██▓ + ▓██ ▒ ██▒▓█ ▀ ██▒ ▀█▒▓██▒▒██ ▒ ▓ ██▒ ▓▒▓██ ▒ ██▒▒██ ██▒ + ▓██ ░▄█ ▒▒███ ▒██░▄▄▄░▒██▒░ ▓██▄ ▒ ▓██░ ▒░▓██ ░▄█ ▒ ▒██ ██░ + ▒██▀▀█▄ ▒▓█ ▄ ░▓█ ██▓░██░ ▒ ██▒░ ▓██▓ ░ ▒██▀▀█▄ ░ ▐██▓░ + ░██▓ ▒██▒░▒████▒░▒▓███▀▒░██░▒██████▒▒ ▒██▒ ░ ░██▓ ▒██▒ ░ ██▒▓░ + ░ ▒▓ ░▒▓░░░ ▒░ ░ ░▒ ▒ ░▓ ▒ ▒▓▒ ▒ ░ ▒ ░░ ░ ▒▓ ░▒▓░ ██▒▒▒ + ░▒ ░ ▒░ ░ ░ ░ ░ ░ ▒ ░░ ░▒ ░ ░ ░ ░▒ ░ ▒░▓██ ░▒░ + ░░ ░ ░ ░ ░ ░ ▒ ░░ ░ ░ ░ ░░ ░ ▒ ▒ ░░ + ░ ░ ░ ░ ░ ░ ░ ░ ░ + ░ ░ +%s(✿◕ ‿◕ )ノ%s +""", LIGHT_PURPLE, ORANGE, PINK, RESET); final RegistryTestServer server = new RegistryTestServer(address); System.out.printf("%sLoading SQL fixtures setting User for authentication...%s\n", BLUE, RESET); + new JpaTestExtensions.Builder().buildIntegrationTestExtension().beforeEach(null); + JpaTransactionManagerExtension.loadInitialData(); UserRoles userRoles = new UserRoles.Builder().setIsAdmin(loginIsAdmin).setGlobalRole(GlobalRole.FTE).build(); User user = - new User.Builder() - .setEmailAddress(loginEmail) - .setUserRoles(userRoles) - .setRegistryLockPassword("registryLockPassword") - .build(); + DatabaseHelper.persistResource( + new User.Builder() + .setEmailAddress(loginEmail) + .setUserRoles(userRoles) + .setRegistryLockPassword("registryLockPassword") + .build()); OidcTokenAuthenticationMechanism.setAuthResultForTesting(AuthResult.createUser(user)); - new JpaTestExtensions.Builder().buildIntegrationTestExtension().beforeEach(null); - JpaTransactionManagerExtension.loadInitialData(); System.out.printf("%sLoading fixtures...%s\n", BLUE, RESET); for (Fixture fixture : fixtures) { fixture.load(); diff --git a/core/src/test/java/google/registry/server/TestServer.java b/core/src/test/java/google/registry/server/TestServer.java index 31033505c..2e457b4da 100644 --- a/core/src/test/java/google/registry/server/TestServer.java +++ b/core/src/test/java/google/registry/server/TestServer.java @@ -153,9 +153,9 @@ public final class TestServer { private ServletContextHandler createHandler( Map runfiles, ImmutableList routes) { ServletContextHandler context = new ServletContextHandler(CONTEXT_PATH, WebAppContext.SESSIONS); - ServletHolder holder; context.setContextPath(CONTEXT_PATH); context.addServlet(HealthzServlet.class, "/healthz"); + ServletHolder holder; for (Map.Entry runfile : runfiles.entrySet()) { holder = context.addServlet(StaticResourceServlet.class, runfile.getKey()); StaticResourceServlet.configureServletHolder(holder, runfile.getKey(), runfile.getValue());