From 88aa13d1a4312a61ba04911d5f32fe8b039b7917 Mon Sep 17 00:00:00 2001 From: mcilwain Date: Mon, 28 Jan 2019 14:17:10 -0800 Subject: [PATCH] Log a warning when MarksDB password isn't configured ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=231287550 --- .../registry/tmch/LordnRequestInitializer.java | 13 +++++++++++-- .../google/registry/tmch/NordnUploadActionTest.java | 6 +++--- .../google/registry/tmch/NordnVerifyActionTest.java | 6 +++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/java/google/registry/tmch/LordnRequestInitializer.java b/java/google/registry/tmch/LordnRequestInitializer.java index 272ed8f4b..768e05143 100644 --- a/java/google/registry/tmch/LordnRequestInitializer.java +++ b/java/google/registry/tmch/LordnRequestInitializer.java @@ -18,6 +18,7 @@ import static com.google.common.base.Verify.verifyNotNull; import static google.registry.util.UrlFetchUtils.setAuthorizationHeader; import com.google.appengine.api.urlfetch.HTTPRequest; +import com.google.common.flogger.FluentLogger; import google.registry.keyring.api.KeyModule.Key; import google.registry.model.registry.Registry; import java.util.Optional; @@ -26,8 +27,14 @@ import javax.inject.Inject; /** Helper class for setting the authorization header on a MarksDB LORDN request. */ final class LordnRequestInitializer { - @Inject @Key("marksdbLordnPassword") Optional marksdbLordnPassword; - @Inject LordnRequestInitializer() {} + private static final FluentLogger logger = FluentLogger.forEnclosingClass(); + + private final Optional marksdbLordnPassword; + + @Inject + LordnRequestInitializer(@Key("marksdbLordnPassword") Optional marksdbLordnPassword) { + this.marksdbLordnPassword = marksdbLordnPassword; + } /** Initializes a URL fetch request for talking to the MarksDB server. */ void initialize(HTTPRequest request, String tld) { @@ -41,6 +48,8 @@ final class LordnRequestInitializer { "lordnUsername is not set for %s.", Registry.get(tld).getTld()); return Optional.of(String.format("%s:%s", lordnUsername, marksdbLordnPassword.get())); } else { + logger.atWarning().log( + "Cannot set credentials for LORDN request because password isn't configured."); return Optional.empty(); } } diff --git a/javatests/google/registry/tmch/NordnUploadActionTest.java b/javatests/google/registry/tmch/NordnUploadActionTest.java index dfd7bbe6f..86534e690 100644 --- a/javatests/google/registry/tmch/NordnUploadActionTest.java +++ b/javatests/google/registry/tmch/NordnUploadActionTest.java @@ -104,7 +104,8 @@ public class NordnUploadActionTest { @Captor private ArgumentCaptor httpRequestCaptor; private final FakeClock clock = new FakeClock(DateTime.parse("2010-05-01T10:11:12Z")); - private final LordnRequestInitializer lordnRequestInitializer = new LordnRequestInitializer(); + private final LordnRequestInitializer lordnRequestInitializer = + new LordnRequestInitializer(Optional.of("attack")); private final NordnUploadAction action = new NordnUploadAction(); @Before @@ -117,7 +118,6 @@ public class NordnUploadActionTest { persistResource(loadRegistrar("TheRegistrar").asBuilder().setIanaIdentifier(99999L).build()); createTld("tld"); persistResource(Registry.get("tld").asBuilder().setLordnUsername("lolcat").build()); - lordnRequestInitializer.marksdbLordnPassword = Optional.of("attack"); action.clock = clock; action.fetchService = fetchService; action.lordnRequestInitializer = lordnRequestInitializer; @@ -210,7 +210,7 @@ public class NordnUploadActionTest { @Test public void testRun_noPassword_doesntSendAuthorizationHeader() throws Exception { - lordnRequestInitializer.marksdbLordnPassword = Optional.empty(); + action.lordnRequestInitializer = new LordnRequestInitializer(Optional.empty()); persistClaimsModeDomain(); action.run(); assertThat(getHeaderFirst(getCapturedHttpRequest(), AUTHORIZATION)).isEmpty(); diff --git a/javatests/google/registry/tmch/NordnVerifyActionTest.java b/javatests/google/registry/tmch/NordnVerifyActionTest.java index 641fb0427..face2ff5e 100644 --- a/javatests/google/registry/tmch/NordnVerifyActionTest.java +++ b/javatests/google/registry/tmch/NordnVerifyActionTest.java @@ -87,7 +87,8 @@ public class NordnVerifyActionTest { @Captor private ArgumentCaptor httpRequestCaptor; private final FakeResponse response = new FakeResponse(); - private final LordnRequestInitializer lordnRequestInitializer = new LordnRequestInitializer(); + private final LordnRequestInitializer lordnRequestInitializer = + new LordnRequestInitializer(Optional.of("attack")); private final NordnVerifyAction action = new NordnVerifyAction(); @Before @@ -97,7 +98,6 @@ public class NordnVerifyActionTest { when(fetchService.fetch(any(HTTPRequest.class))).thenReturn(httpResponse); createTld("gtld"); persistResource(Registry.get("gtld").asBuilder().setLordnUsername("lolcat").build()); - lordnRequestInitializer.marksdbLordnPassword = Optional.of("attack"); action.tld = "gtld"; action.fetchService = fetchService; action.lordnRequestInitializer = lordnRequestInitializer; @@ -125,7 +125,7 @@ public class NordnVerifyActionTest { @Test public void testSuccess_noLordnPassword_doesntSetAuthorizationHeader() throws Exception { - lordnRequestInitializer.marksdbLordnPassword = Optional.empty(); + action.lordnRequestInitializer = new LordnRequestInitializer(Optional.empty()); action.run(); assertThat(getHeaderFirst(getCapturedHttpRequest(), AUTHORIZATION)).isEmpty(); }