From 661e348fcb45118b6f79386771681585c63c143f Mon Sep 17 00:00:00 2001 From: Shicong Huang Date: Wed, 26 Jun 2019 16:57:19 -0400 Subject: [PATCH] Stop provisioning RegistryEnvironment from Dagger (#140) We found that some webdriver tests failed because RegistryEnvironment was set to 'production' by other test and was carried over to the webdriver test, and it was nontrivial to fix them because the instance of RegistryEnvironment was injected into the testing web server. Also, to eliminate this problem from potential victims, we stopped provisioning RegistryEnvironment from Dagger. Instead, we just use RegistryEnvironment.get() function to get the instance, which indeed retrives the value from system property every time. If any test case needs to run the test with other environment, it can just simply use the existing SystemPropertyRule and RegistryEnvironment.${ENV}.setup to change it. --- .../batch/DeleteLoadTestDataAction.java | 4 +- .../batch/DeleteProberDataAction.java | 4 +- .../registry/config/RegistryConfig.java | 7 -- .../java/google/registry/dns/DnsMetrics.java | 6 +- .../registrar/ConsoleOteSetupAction.java | 84 +++++++++++-------- .../ConsoleRegistrarCreatorAction.java | 3 +- .../ui/server/registrar/ConsoleUiAction.java | 73 +++++++++++----- .../registrar/RegistrarSettingsAction.java | 6 +- .../batch/DeleteProberDataActionTest.java | 9 +- .../registrar/ConsoleOteSetupActionTest.java | 7 +- .../ConsoleRegistrarCreatorActionTest.java | 7 +- .../server/registrar/ConsoleUiActionTest.java | 11 ++- .../RegistrarSettingsActionTest.java | 7 +- .../RegistrarSettingsActionTestCase.java | 2 - 14 files changed, 142 insertions(+), 88 deletions(-) diff --git a/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java b/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java index 99428f015..4a80ee551 100644 --- a/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java +++ b/core/src/main/java/google/registry/batch/DeleteLoadTestDataAction.java @@ -73,7 +73,6 @@ public class DeleteLoadTestDataAction implements Runnable { @Inject MapreduceRunner mrRunner; @Inject Response response; - @Inject RegistryEnvironment registryEnvironment; @Inject DeleteLoadTestDataAction() {} @@ -84,7 +83,8 @@ public class DeleteLoadTestDataAction implements Runnable { // run on production. On other environments, data is fully wiped out occasionally anyway, so // having some broken data that isn't referred to isn't the end of the world. checkState( - registryEnvironment != PRODUCTION, "This mapreduce is not safe to run on PRODUCTION."); + !RegistryEnvironment.get().equals(PRODUCTION), + "This mapreduce is not safe to run on PRODUCTION."); mrRunner .setJobName("Delete load test data") diff --git a/core/src/main/java/google/registry/batch/DeleteProberDataAction.java b/core/src/main/java/google/registry/batch/DeleteProberDataAction.java index f35b10b67..a0ae9cf45 100644 --- a/core/src/main/java/google/registry/batch/DeleteProberDataAction.java +++ b/core/src/main/java/google/registry/batch/DeleteProberDataAction.java @@ -17,6 +17,7 @@ package google.registry.batch; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkState; import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static google.registry.config.RegistryEnvironment.PRODUCTION; import static google.registry.mapreduce.MapreduceRunner.PARAM_DRY_RUN; import static google.registry.model.ResourceTransferUtils.updateForeignKeyIndexDeletionTime; import static google.registry.model.ofy.ObjectifyService.ofy; @@ -77,7 +78,6 @@ public class DeleteProberDataAction implements Runnable { @Inject @Config("registryAdminClientId") String registryAdminClientId; @Inject MapreduceRunner mrRunner; @Inject Response response; - @Inject RegistryEnvironment registryEnvironment; @Inject DeleteProberDataAction() {} @Override @@ -96,7 +96,7 @@ public class DeleteProberDataAction implements Runnable { private ImmutableSet getProberRoidSuffixes() { checkArgument( - !RegistryEnvironment.PRODUCTION.equals(registryEnvironment) + !PRODUCTION.equals(RegistryEnvironment.get()) || tlds.stream().allMatch(tld -> tld.endsWith(".test")), "On production, can only work on TLDs that end with .test"); ImmutableSet deletableTlds = diff --git a/core/src/main/java/google/registry/config/RegistryConfig.java b/core/src/main/java/google/registry/config/RegistryConfig.java index fbddf8e17..e82a273aa 100644 --- a/core/src/main/java/google/registry/config/RegistryConfig.java +++ b/core/src/main/java/google/registry/config/RegistryConfig.java @@ -94,13 +94,6 @@ public final class RegistryConfig { @Module public static final class ConfigModule { - private static final RegistryEnvironment REGISTRY_ENVIRONMENT = RegistryEnvironment.get(); - - @Provides - public static RegistryEnvironment provideRegistryEnvironment() { - return REGISTRY_ENVIRONMENT; - } - @Provides @Config("projectId") public static String provideProjectId(RegistryConfigSettings config) { diff --git a/core/src/main/java/google/registry/dns/DnsMetrics.java b/core/src/main/java/google/registry/dns/DnsMetrics.java index bf4386090..1d4810b90 100644 --- a/core/src/main/java/google/registry/dns/DnsMetrics.java +++ b/core/src/main/java/google/registry/dns/DnsMetrics.java @@ -14,6 +14,8 @@ package google.registry.dns; +import static google.registry.config.RegistryEnvironment.PRODUCTION; + import com.google.common.collect.ImmutableSet; import com.google.monitoring.metrics.DistributionFitter; import com.google.monitoring.metrics.EventMetric; @@ -180,8 +182,6 @@ public class DnsMetrics { LABEL_DESCRIPTORS_FOR_LATENCY, EXPONENTIAL_FITTER); - @Inject RegistryEnvironment registryEnvironment; - @Inject DnsMetrics() {} @@ -225,7 +225,7 @@ public class DnsMetrics { hostsCommittedCount.incrementBy(numberOfHosts, tld, status.name(), dnsWriter); // We don't want to record the following metrics in production, as they are quite expensive - if (registryEnvironment == RegistryEnvironment.PRODUCTION) { + if (RegistryEnvironment.get().equals(PRODUCTION)) { return; } diff --git a/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java b/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java index 02ed0b235..7d7542888 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/ConsoleOteSetupAction.java @@ -17,6 +17,7 @@ package google.registry.ui.server.registrar; import static com.google.common.base.Preconditions.checkState; import static com.google.common.net.HttpHeaders.LOCATION; import static com.google.common.net.HttpHeaders.X_FRAME_OPTIONS; +import static google.registry.config.RegistryEnvironment.PRODUCTION; import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN; import static javax.servlet.http.HttpServletResponse.SC_MOVED_TEMPORARILY; @@ -70,25 +71,20 @@ import javax.servlet.http.HttpServletRequest; auth = Auth.AUTH_PUBLIC) public final class ConsoleOteSetupAction implements Runnable { - private static final int PASSWORD_LENGTH = 16; - - private static final FluentLogger logger = FluentLogger.forEnclosingClass(); - public static final String PATH = "/registrar-ote-setup"; - + @VisibleForTesting // webdriver and screenshot tests need this + public static final Supplier CSS_RENAMING_MAP_SUPPLIER = + SoyTemplateUtils.createCssRenamingMapSupplier( + Resources.getResource("google/registry/ui/css/registrar_bin.css.js"), + Resources.getResource("google/registry/ui/css/registrar_dbg.css.js")); + private static final int PASSWORD_LENGTH = 16; + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final Supplier TOFU_SUPPLIER = SoyTemplateUtils.createTofuSupplier( google.registry.ui.soy.ConsoleSoyInfo.getInstance(), google.registry.ui.soy.FormsSoyInfo.getInstance(), google.registry.ui.soy.AnalyticsSoyInfo.getInstance(), google.registry.ui.soy.registrar.OteSetupConsoleSoyInfo.getInstance()); - - @VisibleForTesting // webdriver and screenshot tests need this - public static final Supplier CSS_RENAMING_MAP_SUPPLIER = - SoyTemplateUtils.createCssRenamingMapSupplier( - Resources.getResource("google/registry/ui/css/registrar_bin.css.js"), - Resources.getResource("google/registry/ui/css/registrar_dbg.css.js")); - @Inject HttpServletRequest req; @Inject @RequestMethod Method method; @Inject Response response; @@ -96,27 +92,49 @@ public final class ConsoleOteSetupAction implements Runnable { @Inject UserService userService; @Inject XsrfTokenManager xsrfTokenManager; @Inject AuthResult authResult; - @Inject RegistryEnvironment registryEnvironment; @Inject SendEmailUtils sendEmailUtils; - @Inject @Config("logoFilename") String logoFilename; - @Inject @Config("productName") String productName; - @Inject @Config("analyticsConfig") Map analyticsConfig; - @Inject @Named("base58StringGenerator") StringGenerator passwordGenerator; - @Inject @Parameter("clientId") Optional clientId; - @Inject @Parameter("email") Optional email; - @Inject @Parameter("password") Optional optionalPassword; - @Inject ConsoleOteSetupAction() {} + @Inject + @Config("logoFilename") + String logoFilename; + + @Inject + @Config("productName") + String productName; + + @Inject + @Config("analyticsConfig") + Map analyticsConfig; + + @Inject + @Named("base58StringGenerator") + StringGenerator passwordGenerator; + + @Inject + @Parameter("clientId") + Optional clientId; + + @Inject + @Parameter("email") + Optional email; + + @Inject + @Parameter("password") + Optional optionalPassword; + + @Inject + ConsoleOteSetupAction() {} @Override public void run() { - response.setHeader(X_FRAME_OPTIONS, "SAMEORIGIN"); // Disallow iframing. - response.setHeader("X-Ui-Compatible", "IE=edge"); // Ask IE not to be silly. + response.setHeader(X_FRAME_OPTIONS, "SAMEORIGIN"); // Disallow iframing. + response.setHeader("X-Ui-Compatible", "IE=edge"); // Ask IE not to be silly. logger.atInfo().log( "User %s is accessing the OT&E setup page. Method= %s", registrarAccessor.userIdForLogging(), method); - checkState(registryEnvironment != RegistryEnvironment.PRODUCTION, "Can't create OT&E in prod"); + checkState( + !RegistryEnvironment.get().equals(PRODUCTION), "Can't create OT&E in prod"); if (!authResult.userAuthInfo().isPresent()) { response.setStatus(SC_MOVED_TEMPORARILY); String location; @@ -201,11 +219,11 @@ public final class ConsoleOteSetupAction implements Runnable { data.put("errorMessage", e.getMessage()); response.setPayload( TOFU_SUPPLIER - .get() - .newRenderer(OteSetupConsoleSoyInfo.FORM_PAGE) - .setCssRenamingMap(CSS_RENAMING_MAP_SUPPLIER.get()) - .setData(data) - .render()); + .get() + .newRenderer(OteSetupConsoleSoyInfo.FORM_PAGE) + .setCssRenamingMap(CSS_RENAMING_MAP_SUPPLIER.get()) + .setData(data) + .render()); } } @@ -223,12 +241,11 @@ public final class ConsoleOteSetupAction implements Runnable { .render()); } - private void sendExternalUpdates(ImmutableMap clientIdToTld) { if (!sendEmailUtils.hasRecipients()) { return; } - String environment = Ascii.toLowerCase(String.valueOf(registryEnvironment)); + String environment = Ascii.toLowerCase(String.valueOf(RegistryEnvironment.get())); StringBuilder builder = new StringBuilder(); builder.append( String.format( @@ -240,10 +257,7 @@ public final class ConsoleOteSetupAction implements Runnable { String.format(" Registrar %s with access to TLD %s\n", clientId, tld))); builder.append(String.format("Gave user %s web access to these Registrars\n", email.get())); sendEmailUtils.sendEmail( - String.format( - "OT&E for registrar %s created in %s", - clientId.get(), - environment), + String.format("OT&E for registrar %s created in %s", clientId.get(), environment), builder.toString()); } } diff --git a/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java b/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java index 4e423b2ac..c3071e7ae 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/ConsoleRegistrarCreatorAction.java @@ -107,7 +107,6 @@ public final class ConsoleRegistrarCreatorAction implements Runnable { @Inject UserService userService; @Inject XsrfTokenManager xsrfTokenManager; @Inject AuthResult authResult; - @Inject RegistryEnvironment registryEnvironment; @Inject SendEmailUtils sendEmailUtils; @Inject @Config("logoFilename") String logoFilename; @Inject @Config("productName") String productName; @@ -354,7 +353,7 @@ public final class ConsoleRegistrarCreatorAction implements Runnable { if (!sendEmailUtils.hasRecipients()) { return; } - String environment = Ascii.toLowerCase(String.valueOf(registryEnvironment)); + String environment = Ascii.toLowerCase(String.valueOf(RegistryEnvironment.get())); String body = String.format( "The following registrar was created in %s by %s:\n", diff --git a/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java b/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java index b5883972c..22f7604c3 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/ConsoleUiAction.java @@ -66,7 +66,7 @@ public final class ConsoleUiAction implements Runnable { google.registry.ui.soy.registrar.ConsoleSoyInfo.getInstance(), google.registry.ui.soy.AnalyticsSoyInfo.getInstance()); - @VisibleForTesting // webdriver and screenshot tests need this + @VisibleForTesting // webdriver and screenshot tests need this public static final Supplier CSS_RENAMING_MAP_SUPPLIER = SoyTemplateUtils.createCssRenamingMapSupplier( Resources.getResource("google/registry/ui/css/registrar_bin.css.js"), @@ -79,18 +79,49 @@ public final class ConsoleUiAction implements Runnable { @Inject UserService userService; @Inject XsrfTokenManager xsrfTokenManager; @Inject AuthResult authResult; - @Inject RegistryEnvironment environment; - @Inject @Config("logoFilename") String logoFilename; - @Inject @Config("productName") String productName; - @Inject @Config("integrationEmail") String integrationEmail; - @Inject @Config("supportEmail") String supportEmail; - @Inject @Config("announcementsEmail") String announcementsEmail; - @Inject @Config("supportPhoneNumber") String supportPhoneNumber; - @Inject @Config("technicalDocsUrl") String technicalDocsUrl; - @Inject @Config("registrarConsoleEnabled") boolean enabled; - @Inject @Config("analyticsConfig") Map analyticsConfig; - @Inject @Parameter(PARAM_CLIENT_ID) Optional paramClientId; - @Inject ConsoleUiAction() {} + + @Inject + @Config("logoFilename") + String logoFilename; + + @Inject + @Config("productName") + String productName; + + @Inject + @Config("integrationEmail") + String integrationEmail; + + @Inject + @Config("supportEmail") + String supportEmail; + + @Inject + @Config("announcementsEmail") + String announcementsEmail; + + @Inject + @Config("supportPhoneNumber") + String supportPhoneNumber; + + @Inject + @Config("technicalDocsUrl") + String technicalDocsUrl; + + @Inject + @Config("registrarConsoleEnabled") + boolean enabled; + + @Inject + @Config("analyticsConfig") + Map analyticsConfig; + + @Inject + @Parameter(PARAM_CLIENT_ID) + Optional paramClientId; + + @Inject + ConsoleUiAction() {} @Override public void run() { @@ -113,8 +144,8 @@ public final class ConsoleUiAction implements Runnable { } User user = authResult.userAuthInfo().get().user(); response.setContentType(MediaType.HTML_UTF_8); - response.setHeader(X_FRAME_OPTIONS, "SAMEORIGIN"); // Disallow iframing. - response.setHeader("X-Ui-Compatible", "IE=edge"); // Ask IE not to be silly. + response.setHeader(X_FRAME_OPTIONS, "SAMEORIGIN"); // Disallow iframing. + response.setHeader("X-Ui-Compatible", "IE=edge"); // Ask IE not to be silly. SoyMapData data = new SoyMapData(); data.put("logoFilename", logoFilename); data.put("productName", productName); @@ -127,7 +158,8 @@ public final class ConsoleUiAction implements Runnable { if (!enabled) { response.setStatus(SC_SERVICE_UNAVAILABLE); response.setPayload( - TOFU_SUPPLIER.get() + TOFU_SUPPLIER + .get() .newRenderer(ConsoleSoyInfo.DISABLED) .setCssRenamingMap(CSS_RENAMING_MAP_SUPPLIER.get()) .setData(data) @@ -139,7 +171,7 @@ public final class ConsoleUiAction implements Runnable { data.put("xsrfToken", xsrfTokenManager.generateToken(user.getEmail())); ImmutableSetMultimap roleMap = registrarAccessor.getAllClientIdWithRoles(); data.put("allClientIds", roleMap.keySet()); - data.put("environment", environment.toString()); + data.put("environment", RegistryEnvironment.get().toString()); // We set the initial value to the value that will show if guessClientId throws. String clientId = ""; try { @@ -161,7 +193,8 @@ public final class ConsoleUiAction implements Runnable { "User %s doesn't have access to registrar console.", authResult.userIdForLogging()); response.setStatus(SC_FORBIDDEN); response.setPayload( - TOFU_SUPPLIER.get() + TOFU_SUPPLIER + .get() .newRenderer(ConsoleSoyInfo.WHOAREYOU) .setCssRenamingMap(CSS_RENAMING_MAP_SUPPLIER.get()) .setData(data) @@ -175,7 +208,9 @@ public final class ConsoleUiAction implements Runnable { throw e; } - String payload = TOFU_SUPPLIER.get() + String payload = + TOFU_SUPPLIER + .get() .newRenderer(ConsoleSoyInfo.MAIN) .setCssRenamingMap(CSS_RENAMING_MAP_SUPPLIER.get()) .setData(data) diff --git a/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java b/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java index 36d7c5827..f63d0891d 100644 --- a/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java +++ b/core/src/main/java/google/registry/ui/server/registrar/RegistrarSettingsAction.java @@ -18,6 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.Sets.difference; +import static google.registry.config.RegistryEnvironment.PRODUCTION; import static google.registry.export.sheet.SyncRegistrarsSheetAction.enqueueRegistrarSheetSync; import static google.registry.model.ofy.ObjectifyService.ofy; import static google.registry.security.JsonResponseHelper.Status.ERROR; @@ -92,7 +93,6 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA @Inject SendEmailUtils sendEmailUtils; @Inject AuthenticatedRegistrarAccessor registrarAccessor; @Inject AuthResult authResult; - @Inject RegistryEnvironment registryEnvironment; @Inject RegistrarSettingsAction() {} @@ -334,7 +334,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA // If a REAL registrar isn't in compliance with regards to having an abuse contact set, // prevent addition of allowed TLDs until that's fixed. if (Registrar.Type.REAL.equals(initialRegistrar.getType()) - && RegistryEnvironment.PRODUCTION.equals(registryEnvironment)) { + && PRODUCTION.equals(RegistryEnvironment.get())) { checkArgumentPresent( initialRegistrar.getWhoisAbuseContact(), "Cannot add allowed TLDs if there is no WHOIS abuse contact set."); @@ -496,7 +496,7 @@ public class RegistrarSettingsAction implements Runnable, JsonActionRunner.JsonA return; } enqueueRegistrarSheetSync(appEngineServiceUtils.getCurrentVersionHostname("backend")); - String environment = Ascii.toLowerCase(String.valueOf(registryEnvironment)); + String environment = Ascii.toLowerCase(String.valueOf(RegistryEnvironment.get())); sendEmailUtils.sendEmail( String.format( "Registrar %s (%s) updated in registry %s environment", diff --git a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java index e35744d23..a499acd3f 100644 --- a/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java +++ b/core/src/test/java/google/registry/batch/DeleteProberDataActionTest.java @@ -46,12 +46,14 @@ import google.registry.model.registry.Registry; import google.registry.model.registry.Registry.TldType; import google.registry.model.reporting.HistoryEntry; import google.registry.testing.FakeResponse; +import google.registry.testing.SystemPropertyRule; import google.registry.testing.mapreduce.MapreduceTestCase; import java.util.Optional; import java.util.Set; import org.joda.money.Money; import org.joda.time.DateTime; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -62,6 +64,9 @@ public class DeleteProberDataActionTest extends MapreduceTestCaseCreate Registrar"); assertThat(response.getPayload()).contains("gtag('config', 'sampleId')"); diff --git a/core/src/test/java/google/registry/ui/server/registrar/ConsoleUiActionTest.java b/core/src/test/java/google/registry/ui/server/registrar/ConsoleUiActionTest.java index 059048444..b951198eb 100644 --- a/core/src/test/java/google/registry/ui/server/registrar/ConsoleUiActionTest.java +++ b/core/src/test/java/google/registry/ui/server/registrar/ConsoleUiActionTest.java @@ -28,7 +28,6 @@ import com.google.appengine.api.users.UserServiceFactory; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.net.MediaType; -import google.registry.config.RegistryEnvironment; import google.registry.request.auth.AuthLevel; import google.registry.request.auth.AuthResult; import google.registry.request.auth.AuthenticatedRegistrarAccessor; @@ -52,10 +51,11 @@ import org.junit.runners.JUnit4; public class ConsoleUiActionTest { @Rule - public final AppEngineRule appEngineRule = AppEngineRule.builder() - .withDatastore() - .withUserService(UserInfo.create("marla.singer@example.com", "12345")) - .build(); + public final AppEngineRule appEngineRule = + AppEngineRule.builder() + .withDatastore() + .withUserService(UserInfo.create("marla.singer@example.com", "12345")) + .build(); private final HttpServletRequest request = mock(HttpServletRequest.class); private final FakeResponse response = new FakeResponse(); @@ -79,7 +79,6 @@ public class ConsoleUiActionTest { action.xsrfTokenManager = new XsrfTokenManager(new FakeClock(), action.userService); action.paramClientId = Optional.empty(); action.authResult = AuthResult.create(AuthLevel.USER, UserAuthInfo.create(user, false)); - action.environment = RegistryEnvironment.UNITTEST; action.analyticsConfig = ImmutableMap.of("googleAnalyticsId", "sampleId"); action.registrarAccessor = diff --git a/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java b/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java index ddeaf476e..04a1058d3 100644 --- a/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java +++ b/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTest.java @@ -36,6 +36,7 @@ import google.registry.model.registrar.Registrar; import google.registry.request.auth.AuthenticatedRegistrarAccessor; import google.registry.request.auth.AuthenticatedRegistrarAccessor.Role; import google.registry.testing.CertificateSamples; +import google.registry.testing.SystemPropertyRule; import google.registry.testing.TaskQueueHelper.TaskMatcher; import google.registry.util.CidrAddressBlock; import google.registry.util.EmailMessage; @@ -44,6 +45,7 @@ import java.util.function.BiFunction; import java.util.function.Function; import org.json.simple.JSONValue; import org.json.simple.parser.ParseException; +import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -53,6 +55,9 @@ import org.mockito.ArgumentCaptor; @RunWith(JUnit4.class) public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase { + @Rule + public final SystemPropertyRule systemPropertyRule = new SystemPropertyRule(); + @Test public void testSuccess_updateRegistrarInfo_andSendsNotificationEmail() throws Exception { String expectedEmailBody = loadFile(getClass(), "update_registrar_email.txt"); @@ -393,7 +398,7 @@ public class RegistrarSettingsActionTest extends RegistrarSettingsActionTestCase @Test public void testUpdate_allowedTlds_failedWhenNoWhoisAbuseContactExists() { setUserAdmin(); - action.registryEnvironment = RegistryEnvironment.PRODUCTION; + RegistryEnvironment.PRODUCTION.setup(systemPropertyRule); Map args = Maps.newHashMap(loadRegistrar(CLIENT_ID).toJsonMap()); args.put("allowedTlds", ImmutableList.of("newtld", "currenttld")); diff --git a/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java b/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java index 05f9eae86..7d03457ba 100644 --- a/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java +++ b/core/src/test/java/google/registry/ui/server/registrar/RegistrarSettingsActionTestCase.java @@ -33,7 +33,6 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.truth.Truth; -import google.registry.config.RegistryEnvironment; import google.registry.model.ofy.Ofy; import google.registry.model.registrar.RegistrarContact; import google.registry.request.JsonActionRunner; @@ -116,7 +115,6 @@ public abstract class RegistrarSettingsActionTestCase { getGSuiteOutgoingEmailDisplayName(), ImmutableList.of("notification@test.example", "notification2@test.example"), emailService); - action.registryEnvironment = RegistryEnvironment.get(); action.registrarConsoleMetrics = new RegistrarConsoleMetrics(); action.authResult = AuthResult.create(