View Javadoc
1   package org.apache.maven.scm.provider.svn.svnexe.command;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   * http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.scm.ScmTestCase;
23  import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
24  import org.codehaus.plexus.util.Os;
25  import org.codehaus.plexus.util.cli.Commandline;
26  
27  import static org.junit.Assert.assertNotEquals;
28  
29  import java.io.File;
30  
31  /**
32   * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
33   *
34   */
35  public class SvnCommandLineUtilsTest
36      extends ScmTestCase
37  {
38      public void testCryptPassword()
39          throws Exception
40      {
41          /* FIXME Plexus does not quote the crypted password on Windows which is actually incorrect at the moment
42           * it would cause wildcard expansion with cmd: https://github.com/codehaus-plexus/plexus-utils/issues/37.
43           */
44          SvnScmProviderRepository repo =
45              new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password" );
46          String clString =
47              SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
48          Commandline expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
49          expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
50          assertEquals( expectedCmd.toString(), clString );
51  
52          repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", null );
53          clString =
54              SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
55          assertCommandLine( "svn --username username --no-auth-cache --non-interactive", new File( "." ),
56                             SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
57  
58          repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password with spaces" );
59          clString =
60                  SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
61          expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
62          expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
63          assertEquals( expectedCmd.toString(), clString );
64  
65          repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password'with'single'quotes" );
66          clString =
67                  SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
68          expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
69          expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
70          assertEquals( expectedCmd.toString(), clString );
71  
72          repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password'with'single'quotes and spaces" );
73          clString =
74                  SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
75          expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
76          expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
77          assertEquals( expectedCmd.toString(), clString );
78  
79          repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password\"with\"double\"quotes" );
80          clString =
81                  SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
82          expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
83          expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
84          assertEquals( expectedCmd.toString(), clString );
85  
86          repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password\"with\"double\"quotes and spaces" );
87          clString =
88                  SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
89          expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
90          expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
91          // FIXME https://github.com/codehaus-plexus/plexus-utils/issues/36
92          if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
93          {
94              assertNotEquals( expectedCmd.toString(), clString );
95          }
96          else {
97              assertEquals( expectedCmd.toString(), clString );
98          }
99  
100         repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password\"with\"double\"quotes'and'single'quotes" );
101         clString =
102                 SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
103         expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
104         expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
105         assertEquals( expectedCmd.toString(), clString );
106 
107         repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password\"with\"double\"quotes'and'single'quotes and spaces" );
108         clString =
109                 SvnCommandLineUtils.cryptPassword( SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
110         expectedCmd = new Commandline( "svn --username username --password ***** --no-auth-cache --non-interactive" );
111         expectedCmd.setWorkingDirectory( new File( "." ).getAbsolutePath() );
112         // FIXME https://github.com/codehaus-plexus/plexus-utils/issues/36
113         if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
114         {
115             assertNotEquals( expectedCmd.toString(), clString );
116         }
117         else {
118             assertEquals( expectedCmd.toString(), clString );
119         }
120 
121         repo = new SvnScmProviderRepository( "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", null );
122         assertCommandLine( "svn --username username --no-auth-cache --non-interactive", new File( "." ),
123                            SvnCommandLineUtils.getBaseSvnCommandLine( new File( "." ), repo ) );
124     }
125 }