Skip to content

Commit

Permalink
SONAR-7598 Hide sensitive properties in scanner report for global pro…
Browse files Browse the repository at this point in the history
…perties
  • Loading branch information
henryju committed May 10, 2016
1 parent 9391fdf commit 2060793
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Expand Up @@ -115,8 +115,8 @@ private void writeEnvVariables(BufferedWriter fileWriter) throws IOException {
private void writeGlobalSettings(BufferedWriter fileWriter) throws IOException { private void writeGlobalSettings(BufferedWriter fileWriter) throws IOException {
fileWriter.append("Global properties:\n"); fileWriter.append("Global properties:\n");
Map<String, String> props = globalRepositories.globalSettings(); Map<String, String> props = globalRepositories.globalSettings();
for (String env : new TreeSet<>(props.keySet())) { for (String prop : new TreeSet<>(props.keySet())) {
fileWriter.append(String.format(KEY_VALUE_FORMAT, env, props.get(env))).append('\n'); dumpPropIfNotSensitive(fileWriter, prop, props.get(prop));
} }
} }


Expand All @@ -133,13 +133,17 @@ public void dumpModuleSettings(ProjectDefinition moduleDefinition) {
if (isSystemProp(prop) || isEnvVariable(prop) || !isSqProp(prop)) { if (isSystemProp(prop) || isEnvVariable(prop) || !isSqProp(prop)) {
continue; continue;
} }
fileWriter.append(String.format(KEY_VALUE_FORMAT, prop, sensitive(prop) ? "******" : moduleSpecificProps.get(prop))).append('\n'); dumpPropIfNotSensitive(fileWriter, prop, moduleSpecificProps.get(prop));
} }
} catch (IOException e) { } catch (IOException e) {
throw new IllegalStateException("Unable to write analysis log", e); throw new IllegalStateException("Unable to write analysis log", e);
} }
} }


private static void dumpPropIfNotSensitive(BufferedWriter fileWriter, String prop, String value) throws IOException {
fileWriter.append(String.format(KEY_VALUE_FORMAT, prop, sensitive(prop) ? "******" : value)).append('\n');
}

/** /**
* Only keep props that are not in parent * Only keep props that are not in parent
*/ */
Expand Down
Expand Up @@ -181,7 +181,7 @@ public void shouldNotDumpEnvTwice() throws Exception {
} }


@Test @Test
public void shouldNotDumpSensitiveProperties() throws Exception { public void shouldNotDumpSensitiveModuleProperties() throws Exception {
ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder()); ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
publisher.init(writer); publisher.init(writer);


Expand All @@ -201,6 +201,20 @@ public void shouldNotDumpSensitiveProperties() throws Exception {
"sonar.projectKey=foo"); "sonar.projectKey=foo");
} }


// SONAR-7598
@Test
public void shouldNotDumpSensitiveGlobalProperties() throws Exception {
ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
when(globalRepositories.globalSettings()).thenReturn(ImmutableMap.of("sonar.login", "my_token", "sonar.password", "azerty", "sonar.cpp.license.secured", "AZERTY"));

publisher.init(writer);

assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog())).containsSequence(
"sonar.cpp.license.secured=******",
"sonar.login=******",
"sonar.password=******");
}

// SONAR-7371 // SONAR-7371
@Test @Test
public void dontDumpParentProps() throws Exception { public void dontDumpParentProps() throws Exception {
Expand Down

0 comments on commit 2060793

Please sign in to comment.