Skip to content

Commit

Permalink
Another buglet: fallback key for instances without a configured URL w…
Browse files Browse the repository at this point in the history
…as by accident just 'key'.
  • Loading branch information
jglick committed Apr 13, 2017
1 parent 02d2405 commit 660058c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/src/test/java/hudson/cli/ClientAuthenticationCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> commands = Lists.newArrayList("java", "-jar", jar.getAbsolutePath(), "-s", r.getURL().toString(), "-noKeyAuth");
commands.addAll(Arrays.asList(args));
Expand Down

0 comments on commit 660058c

Please sign in to comment.