提交 ac3cd3eb 编写于 作者: W Wadeck Follonier 提交者: Oleg Nenashev

[JENKINS-47426] getPropertyKey is not consistent over time (#3080)

* JENKINS-47426: getPropertyKey is not consistent over time
- add passing test for the case the rootUrl is set
- add failing test for the case the rootUrl is not set yet, the propertyKey is not consistent
- add a warning message when the flow passes in the fallback mode

* - fixing the getEncryptedValue using a static memory

* - add issue annotations

* - modifications proposed by Jesse: use legacyId instead of randomId, stable over restart

* - small correction for a test case
上级 97e6e400
......@@ -38,7 +38,7 @@ public class ClientAuthenticationCache implements Serializable {
private static final HMACConfidentialKey MAC = new HMACConfidentialKey(ClientAuthenticationCache.class, "MAC");
private static final Logger LOGGER = Logger.getLogger(ClientAuthenticationCache.class.getName());
/**
* Where the store should be placed.
*/
......@@ -110,9 +110,12 @@ public class ClientAuthenticationCache implements Serializable {
*/
@VisibleForTesting
String getPropertyKey() {
String url = Jenkins.getActiveInstance().getRootUrl();
Jenkins j = Jenkins.getActiveInstance();
String url = j.getRootUrl();
if (url!=null) return url;
return Secret.fromString("key").getEncryptedValue();
LOGGER.log(Level.WARNING, "The instance is not configured using a rootUrl, the key that represents your instance will not be stable");
return j.getLegacyInstanceId();
}
/**
......
......@@ -112,7 +112,25 @@ public class ClientAuthenticationCacheTest {
assertEquals(r.getURL().toString(), cache.getPropertyKey());
JenkinsLocationConfiguration.get().setUrl(null);
String key = cache.getPropertyKey();
assertTrue(key, Secret.decrypt(key) != null);
assertEquals(r.jenkins.getLegacyInstanceId(), key);
}
@Test
@Issue("JENKINS-47426")
public void getPropertyKey_mustBeEquivalentOverTime() throws Exception {
ClientAuthenticationCache cache = new ClientAuthenticationCache(null);
String key1 = cache.getPropertyKey();
String key2 = cache.getPropertyKey();
assertEquals("Two calls to the getPropertyKey() must be equivalent over time, with rootUrl", key1, key2);
JenkinsLocationConfiguration.get().setUrl(null);
key1 = cache.getPropertyKey();
key2 = cache.getPropertyKey();
assertEquals("Two calls to the getPropertyKey() must be equivalent over time, without rootUrl", key1, key2);
}
private void assertCLI(int code, @CheckForNull String output, File jar, String... args) throws Exception {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册