mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'password-obfuscation' of https://github.com/jimgoog/intellij-community
This commit is contained in:
+24
-1
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.service.execution;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.intellij.execution.configurations.GeneralCommandLine;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -143,7 +144,9 @@ public class GradleExecutionHelper {
|
||||
}
|
||||
|
||||
if (!settings.getArguments().isEmpty()) {
|
||||
LOG.info("Passing command-line args to Gradle Tooling API: " + StringUtil.join(settings.getArguments(), " "));
|
||||
String loggableArgs = StringUtil.join(obfuscatePasswordParameters(settings.getArguments()), " ");
|
||||
LOG.info("Passing command-line args to Gradle Tooling API: " + loggableArgs);
|
||||
|
||||
// filter nulls and empty strings
|
||||
List<String> filteredArgs = ContainerUtil.mapNotNull(settings.getArguments(), s -> StringUtil.isEmpty(s) ? null : s);
|
||||
|
||||
@@ -575,6 +578,26 @@ public class GradleExecutionHelper {
|
||||
return result;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@NotNull
|
||||
static List<String> obfuscatePasswordParameters(@NotNull List<String> commandLineArguments) {
|
||||
List<String> replaced = new ArrayList<>(commandLineArguments.size());
|
||||
final String PASSWORD_PARAMETER_IDENTIFIER = ".password=";
|
||||
for (String option : commandLineArguments) {
|
||||
// Find parameters ending in "password", like:
|
||||
// -Pandroid.injected.signing.store.password=
|
||||
// -Pandroid.injected.signing.key.password=
|
||||
int index = option.indexOf(PASSWORD_PARAMETER_IDENTIFIER);
|
||||
if (index == -1) {
|
||||
replaced.add(option);
|
||||
}
|
||||
else {
|
||||
replaced.add(option.substring(0, index + PASSWORD_PARAMETER_IDENTIFIER.length()) + "*********");
|
||||
}
|
||||
}
|
||||
return replaced;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated to be removed in future version
|
||||
*/
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.service.execution;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class GradleExecutionHelperTest {
|
||||
|
||||
@Test
|
||||
public void testPasswordObfuscation() throws Exception {
|
||||
List<String> originalArgs = ImmutableList.of(
|
||||
"--configure-on-demand",
|
||||
"-Pandroid.injected.invoked.from.ide=true",
|
||||
"-Pandroid.injected.signing.store.password=asdfghjkl;",
|
||||
"-Pandroid.injected.signing.key.alias=testKey",
|
||||
"-Pandroid.injected.signing.key.password=blabla",
|
||||
"/tmp/asLocalRepo1004.gradle"
|
||||
);
|
||||
|
||||
List<String> obfuscatedArgs = GradleExecutionHelper.obfuscatePasswordParameters(originalArgs);
|
||||
|
||||
List<String> expectedArgs = ImmutableList.of(
|
||||
"--configure-on-demand",
|
||||
"-Pandroid.injected.invoked.from.ide=true",
|
||||
"-Pandroid.injected.signing.store.password=*********",
|
||||
"-Pandroid.injected.signing.key.alias=testKey",
|
||||
"-Pandroid.injected.signing.key.password=*********",
|
||||
"/tmp/asLocalRepo1004.gradle"
|
||||
);
|
||||
|
||||
assertEquals(obfuscatedArgs, expectedArgs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user