From 660058c297665bebcbee679b642b5da3138312ca Mon Sep 17 00:00:00 2001 From: Jesse Glick Date: Tue, 14 Mar 2017 15:09:53 -0400 Subject: [PATCH] Another buglet: fallback key for instances without a configured URL was by accident just 'key'. --- .../java/hudson/cli/ClientAuthenticationCache.java | 2 +- .../java/hudson/cli/ClientAuthenticationCacheTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/cli/ClientAuthenticationCache.java b/core/src/main/java/hudson/cli/ClientAuthenticationCache.java index 7ff2e3a29dc5..f66fc78c9796 100644 --- a/core/src/main/java/hudson/cli/ClientAuthenticationCache.java +++ b/core/src/main/java/hudson/cli/ClientAuthenticationCache.java @@ -113,7 +113,7 @@ public Authentication get() { String getPropertyKey() { String url = Jenkins.getInstance().getRootUrl(); if (url!=null) return url; - return Secret.fromString("key").toString(); + return Secret.fromString("key").getEncryptedValue(); } /** diff --git a/test/src/test/java/hudson/cli/ClientAuthenticationCacheTest.java b/test/src/test/java/hudson/cli/ClientAuthenticationCacheTest.java index 86ecbbdd20b2..4e1d6153805c 100644 --- a/test/src/test/java/hudson/cli/ClientAuthenticationCacheTest.java +++ b/test/src/test/java/hudson/cli/ClientAuthenticationCacheTest.java @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.List; import javax.annotation.CheckForNull; +import jenkins.model.JenkinsLocationConfiguration; import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.TeeOutputStream; import static org.hamcrest.Matchers.containsString; @@ -102,6 +103,15 @@ public void overHttp() throws Exception { } } + @Test + public void getPropertyKey() throws Exception { + ClientAuthenticationCache cache = new ClientAuthenticationCache(null); + assertEquals(r.getURL().toString(), cache.getPropertyKey()); + JenkinsLocationConfiguration.get().setUrl(null); + String key = cache.getPropertyKey(); + assertTrue(key, Secret.decrypt(key) != null); + } + private void assertCLI(int code, @CheckForNull String output, File jar, String... args) throws Exception { List commands = Lists.newArrayList("java", "-jar", jar.getAbsolutePath(), "-s", r.getURL().toString(), "-noKeyAuth"); commands.addAll(Arrays.asList(args));