You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2015/01/02 02:42:29 UTC
[1/3] maven-scm git commit: SCM-764 : Fix clear password displayed in
logs
Repository: maven-scm
Updated Branches:
refs/heads/master a0081dcb2 -> 98045af2d
SCM-764 : Fix clear password displayed in logs
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/9aef6c0a
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/9aef6c0a
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/9aef6c0a
Branch: refs/heads/master
Commit: 9aef6c0a2622165ef0faff7389aaeddbec15afd5
Parents: ecb37f6
Author: llebegue <lu...@lebegue.org>
Authored: Wed Oct 15 20:48:13 2014 +0200
Committer: llebegue <lu...@lebegue.org>
Committed: Wed Oct 15 20:48:39 2014 +0200
----------------------------------------------------------------------
.../gitexe/command/AnonymousCommandLine.java | 53 ++++++++++++++++++++
.../git/gitexe/command/GitCommandLineUtils.java | 32 ++++++++++--
.../GitCommandLineUtilsAddTargetTest.java | 39 ++++++++++++--
.../java/org/apache/maven/scm/ScmTestCase.java | 9 ++--
4 files changed, 122 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/9aef6c0a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java
new file mode 100644
index 0000000..d2fd786
--- /dev/null
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java
@@ -0,0 +1,53 @@
+package org.apache.maven.scm.provider.git.gitexe.command;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.codehaus.plexus.util.cli.Commandline;
+
+public class AnonymousCommandLine extends Commandline
+{
+
+ public static final String PASSWORD_PLACE_HOLDER = "********";
+
+ private Pattern passwordPattern = Pattern.compile( "^.*:(.*)@.*$" );
+
+ /**
+ * Provides an anonymous output to mask password. Considering URL of type :
+ * <<protocol>>://<<user>>:<<password>>@
+ * <<host_definition>>
+ */
+ @Override
+ public String toString()
+ {
+ String output = super.toString();
+ final Matcher passwordMatcher = passwordPattern.matcher( output );
+ if ( passwordMatcher.find() )
+ {
+ // clear password
+ final String clearPassword = passwordMatcher.group( 1 );
+ // to be replaced in output by stars
+ output = output.replace( clearPassword, PASSWORD_PLACE_HOLDER );
+ }
+ return output;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/9aef6c0a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java
index f0234b6..2599273 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtils.java
@@ -57,7 +57,7 @@ public final class GitCommandLineUtils
for ( File file : files )
{
String relativeFile = file.getPath();
-
+
final String canonicalFile = file.getCanonicalPath();
if ( canonicalFile.startsWith( canonicalWorkingDirectory ) )
{
@@ -81,15 +81,41 @@ public final class GitCommandLineUtils
}
}
+ /**
+ *
+ * @param workingDirectory
+ * @param command
+ * @return
+ */
public static Commandline getBaseGitCommandLine( File workingDirectory, String command )
{
+ return getAnonymousBaseGitCommandLine( workingDirectory, command );
+ }
+
+ /**
+ * Creates a {@link Commandline} for which the toString() do not display
+ * password.
+ *
+ * @param workingDirectory
+ * @param command
+ * @return CommandLine with anonymous output.
+ */
+ private static Commandline getAnonymousBaseGitCommandLine( File workingDirectory, String command )
+ {
if ( command == null || command.length() == 0 )
{
return null;
}
- Commandline cl = new Commandline();
+ Commandline cl = new AnonymousCommandLine();
+
+ composeCommand( workingDirectory, command, cl );
+ return cl;
+ }
+
+ private static void composeCommand( File workingDirectory, String command, Commandline cl )
+ {
cl.setExecutable( "git" );
cl.createArg().setValue( command );
@@ -98,8 +124,6 @@ public final class GitCommandLineUtils
{
cl.setWorkingDirectory( workingDirectory.getAbsolutePath() );
}
-
- return cl;
}
public static int execute( Commandline cl, StreamConsumer consumer, CommandLineUtils.StringStreamConsumer stderr,
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/9aef6c0a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtilsAddTargetTest.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtilsAddTargetTest.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtilsAddTargetTest.java
index b83f08d..6574922 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtilsAddTargetTest.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/GitCommandLineUtilsAddTargetTest.java
@@ -20,9 +20,12 @@ package org.apache.maven.scm.provider.git.gitexe.command;
*/
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import java.io.File;
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
@@ -37,7 +40,8 @@ public class GitCommandLineUtilsAddTargetTest
{
/**
- * Test of addTarget method, of class GitCommandLineUtils on Non-Windows systems.
+ * Test of addTarget method, of class GitCommandLineUtils on Non-Windows
+ * systems.
*/
@Test
public void testAddTargetNonWindows()
@@ -57,9 +61,10 @@ public class GitCommandLineUtilsAddTargetTest
{
assumeTrue( runsOnWindows() );
final File workingDir = new File( "C:\\prj" );
- // Note that the second file has a lowercase drive letter, see https://jira.codehaus.org/browse/SCM-667
- final List<File> filesToAdd =
- Arrays.asList( new File( "C:\\prj\\pom.xml" ), new File( "c:\\prj\\mod1\\pom.xml" ) );
+ // Note that the second file has a lowercase drive letter, see
+ // https://jira.codehaus.org/browse/SCM-667
+ final List<File> filesToAdd = Arrays.asList( new File( "C:\\prj\\pom.xml" ),
+ new File( "c:\\prj\\mod1\\pom.xml" ) );
final String expectedArguments = "[add, pom.xml, mod1\\pom.xml]";
check( workingDir, filesToAdd, expectedArguments );
}
@@ -73,6 +78,32 @@ public class GitCommandLineUtilsAddTargetTest
assertEquals( expectedArguments, arguments );
}
+ @Test
+ public void testPasswordAnonymous()
+ throws Exception
+ {
+
+ String commandLine = "git push https://user:password@foo.com/git/trunk refs/tags/my-tag-1";
+
+ final Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( new File( "." ), commandLine );
+
+ String[] commandLineArgs = cl.getShellCommandline();
+
+ //
+ for ( int i = 0; i < commandLineArgs.length; i++ )
+ {
+ assertFalse( MessageFormat.format( "The target log message should not contain <{0}> but it contains <{1}>",
+ AnonymousCommandLine.PASSWORD_PLACE_HOLDER, commandLineArgs[i] ),
+ commandLineArgs[i].contains( AnonymousCommandLine.PASSWORD_PLACE_HOLDER ) );
+ }
+
+ final String scmUrlFakeForTest = "https://user:".concat( AnonymousCommandLine.PASSWORD_PLACE_HOLDER ).concat(
+ "@foo.com/git/trunk" );
+
+ assertTrue( MessageFormat.format( "The target log message should contain <{0}> but it contains <{1}>",
+ scmUrlFakeForTest, cl.toString() ), cl.toString().contains( scmUrlFakeForTest ) );
+ }
+
private boolean runsOnWindows()
{
return Os.isFamily( Os.FAMILY_WINDOWS );
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/9aef6c0a/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
----------------------------------------------------------------------
diff --git a/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java b/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
index b83cd82..bb87c31 100644
--- a/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
+++ b/maven-scm-test/src/main/java/org/apache/maven/scm/ScmTestCase.java
@@ -324,9 +324,10 @@ public abstract class ScmTestCase
}
}
- protected void deleteDirectory( File directory ) throws IOException
+ protected void deleteDirectory( File directory )
+ throws IOException
{
- FileUtils.deleteDirectory( directory );
+ FileUtils.deleteDirectory( directory );
}
public static Date getDate( int year, int month, int day )
@@ -361,7 +362,9 @@ public abstract class ScmTestCase
{
cl.setWorkingDirectory( expectedWorkingDirectory.getAbsolutePath() );
}
- assertEquals( cl.toString(), actualCommand.toString() );
+ String expectedCommandLineAsExecuted = StringUtils.join( cl.getShellCommandline(), " " );
+ String actualCommandLineAsExecuted = StringUtils.join( actualCommand.getShellCommandline(), " " );
+ assertEquals( expectedCommandLineAsExecuted, actualCommandLineAsExecuted );
}
/**
[3/3] maven-scm git commit: format class. We are now CDD: Checkstyle
Driven Development....
Posted by ol...@apache.org.
format class. We are now CDD: Checkstyle Driven Development....
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/98045af2
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/98045af2
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/98045af2
Branch: refs/heads/master
Commit: 98045af2de59c5ea0270934d602bfca9f8e4acc9
Parents: 1948757
Author: Olivier Lamy <ol...@apache.org>
Authored: Fri Jan 2 12:42:18 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Fri Jan 2 12:42:18 2015 +1100
----------------------------------------------------------------------
.../gitexe/command/AnonymousCommandLine.java | 53 +++++++++++---------
1 file changed, 29 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-scm/blob/98045af2/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java
index d2fd786..b87b1a3 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/AnonymousCommandLine.java
@@ -19,35 +19,40 @@ package org.apache.maven.scm.provider.git.gitexe.command;
* under the License.
*/
+import org.codehaus.plexus.util.cli.Commandline;
+
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.codehaus.plexus.util.cli.Commandline;
-
-public class AnonymousCommandLine extends Commandline
+/**
+ * CommandLine extension to mask password
+ * @since 1.9.3
+ */
+public class AnonymousCommandLine
+ extends Commandline
{
public static final String PASSWORD_PLACE_HOLDER = "********";
-
- private Pattern passwordPattern = Pattern.compile( "^.*:(.*)@.*$" );
- /**
- * Provides an anonymous output to mask password. Considering URL of type :
- * <<protocol>>://<<user>>:<<password>>@
- * <<host_definition>>
- */
- @Override
- public String toString()
- {
- String output = super.toString();
- final Matcher passwordMatcher = passwordPattern.matcher( output );
- if ( passwordMatcher.find() )
- {
- // clear password
- final String clearPassword = passwordMatcher.group( 1 );
- // to be replaced in output by stars
- output = output.replace( clearPassword, PASSWORD_PLACE_HOLDER );
- }
- return output;
- }
+ private Pattern passwordPattern = Pattern.compile( "^.*:(.*)@.*$" );
+
+ /**
+ * Provides an anonymous output to mask password. Considering URL of type :
+ * <<protocol>>://<<user>>:<<password>>@
+ * <<host_definition>>
+ */
+ @Override
+ public String toString()
+ {
+ String output = super.toString();
+ final Matcher passwordMatcher = passwordPattern.matcher( output );
+ if ( passwordMatcher.find() )
+ {
+ // clear password
+ final String clearPassword = passwordMatcher.group( 1 );
+ // to be replaced in output by stars
+ output = output.replace( clearPassword, PASSWORD_PLACE_HOLDER );
+ }
+ return output;
+ }
}
\ No newline at end of file
[2/3] maven-scm git commit: [SCM-764] username and credentials shown
as INFO on commadline
Posted by ol...@apache.org.
[SCM-764] username and credentials shown as INFO on commadline
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/19487570
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/19487570
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/19487570
Branch: refs/heads/master
Commit: 1948757009d5730fd98ad011e3a581b576c91d47
Parents: a0081dc 9aef6c0
Author: Olivier Lamy <ol...@apache.org>
Authored: Fri Jan 2 12:15:41 2015 +1100
Committer: Olivier Lamy <ol...@apache.org>
Committed: Fri Jan 2 12:15:41 2015 +1100
----------------------------------------------------------------------
.../gitexe/command/AnonymousCommandLine.java | 53 ++++++++++++++++++++
.../git/gitexe/command/GitCommandLineUtils.java | 32 ++++++++++--
.../GitCommandLineUtilsAddTargetTest.java | 39 ++++++++++++--
.../java/org/apache/maven/scm/ScmTestCase.java | 9 ++--
4 files changed, 122 insertions(+), 11 deletions(-)
----------------------------------------------------------------------