1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm.provider.svn.svnexe.command;
20
21 import java.io.File;
22
23 import org.apache.maven.scm.ScmTestCase;
24 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
25 import org.codehaus.plexus.util.Os;
26 import org.codehaus.plexus.util.cli.Commandline;
27 import org.junit.Test;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotEquals;
31
32
33
34
35
36 public class SvnCommandLineUtilsTest extends ScmTestCase {
37 @Test
38 public void testCryptPassword() throws Exception {
39
40
41
42 SvnScmProviderRepository repo = new SvnScmProviderRepository(
43 "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password");
44 String clString =
45 SvnCommandLineUtils.cryptPassword(SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
46 Commandline expectedCmd =
47 new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
48 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
49 assertEquals(expectedCmd.toString(), clString);
50
51 repo = new SvnScmProviderRepository("https://svn.apache.org/repos/asf/maven/scm/trunk", "username", null);
52 clString = SvnCommandLineUtils.cryptPassword(SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
53 assertCommandLine(
54 "svn --username username --no-auth-cache --non-interactive",
55 new File("."),
56 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
57
58 repo = new SvnScmProviderRepository(
59 "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password with spaces");
60 clString = 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(
66 "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password'with'single'quotes");
67 clString = 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(
73 "https://svn.apache.org/repos/asf/maven/scm/trunk",
74 "username",
75 "password'with'single'quotes and spaces");
76 clString = SvnCommandLineUtils.cryptPassword(SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
77 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
78 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
79 assertEquals(expectedCmd.toString(), clString);
80
81 repo = new SvnScmProviderRepository(
82 "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password\"with\"double\"quotes");
83 clString = SvnCommandLineUtils.cryptPassword(SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
84 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
85 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
86 assertEquals(expectedCmd.toString(), clString);
87
88 repo = new SvnScmProviderRepository(
89 "https://svn.apache.org/repos/asf/maven/scm/trunk",
90 "username",
91 "password\"with\"double\"quotes and spaces");
92 clString = SvnCommandLineUtils.cryptPassword(SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
93 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
94 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
95
96 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
97 assertNotEquals(expectedCmd.toString(), clString);
98 } else {
99 assertEquals(expectedCmd.toString(), clString);
100 }
101
102 repo = new SvnScmProviderRepository(
103 "https://svn.apache.org/repos/asf/maven/scm/trunk",
104 "username",
105 "password\"with\"double\"quotes'and'single'quotes");
106 clString = SvnCommandLineUtils.cryptPassword(SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
107 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
108 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
109 assertEquals(expectedCmd.toString(), clString);
110
111 repo = new SvnScmProviderRepository(
112 "https://svn.apache.org/repos/asf/maven/scm/trunk",
113 "username",
114 "password\"with\"double\"quotes'and'single'quotes and spaces");
115 clString = SvnCommandLineUtils.cryptPassword(SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
116 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
117 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
118
119 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
120 assertNotEquals(expectedCmd.toString(), clString);
121 } else {
122 assertEquals(expectedCmd.toString(), clString);
123 }
124
125 repo = new SvnScmProviderRepository("https://svn.apache.org/repos/asf/maven/scm/trunk", "username", null);
126 assertCommandLine(
127 "svn --username username --no-auth-cache --non-interactive",
128 new File("."),
129 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo));
130 }
131 }