diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-14 23:52:04 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-14 23:58:01 +0100 |
commit | f0e02076c17318fed53983bbff3bce5d820c06b1 (patch) | |
tree | 30c9a769af8a4ea58c6c67e2e77d0102f2ddcef3 | |
parent | 94f0a69457d1ec7f72b1603e5409ace2c6d99b81 (diff) | |
download | sonarqube-f0e02076c17318fed53983bbff3bce5d820c06b1.tar.gz sonarqube-f0e02076c17318fed53983bbff3bce5d820c06b1.zip |
SONAR-2084 default value of sonar.secretKeyPath is ~/.sonar/sonar-secret.txt
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java | 9 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java index 5392f3651f4..1b5ee8511ef 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java @@ -119,7 +119,12 @@ final class AesCipher extends Cipher { } } - private String getPathToSecretKey() { - return settings.getClearString(CoreProperties.ENCRYPTION_SECRET_KEY_FILE); + @VisibleForTesting + String getPathToSecretKey() { + String path = settings.getClearString(CoreProperties.ENCRYPTION_SECRET_KEY_FILE); + if (StringUtils.isBlank(path)) { + path = new File(FileUtils.getUserDirectoryPath(), ".sonar/sonar-secret.txt").getPath(); + } + return path; } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java index 2adf627e289..b9f429bc7dd 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java @@ -20,6 +20,7 @@ package org.sonar.api.config; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; import org.junit.Test; import org.sonar.api.CoreProperties; @@ -114,6 +115,16 @@ public class AesCipherTest { } @Test + public void testDefaultPathToSecretKey() { + AesCipher cipher = new AesCipher(new Settings()); + + String path = cipher.getPathToSecretKey(); + + assertThat(StringUtils.isNotBlank(path), is(true)); + assertThat(new File(path).getName(), is("sonar-secret.txt")); + } + + @Test public void loadSecretKeyFromFile() throws Exception { AesCipher cipher = new AesCipher(new Settings()); Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey()); |