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 = SvnCommandLineUtils.cryptPassword(
45 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
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(
53 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
54 assertCommandLine(
55 "svn --username username --no-auth-cache --non-interactive",
56 new File("."),
57 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
58
59 repo = new SvnScmProviderRepository(
60 "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password with spaces");
61 clString = SvnCommandLineUtils.cryptPassword(
62 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
63 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
64 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
65 assertEquals(expectedCmd.toString(), clString);
66
67 repo = new SvnScmProviderRepository(
68 "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password'with'single'quotes");
69 clString = SvnCommandLineUtils.cryptPassword(
70 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
71 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
72 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
73 assertEquals(expectedCmd.toString(), clString);
74
75 repo = new SvnScmProviderRepository(
76 "https://svn.apache.org/repos/asf/maven/scm/trunk",
77 "username",
78 "password'with'single'quotes and spaces");
79 clString = SvnCommandLineUtils.cryptPassword(
80 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
81 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
82 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
83 assertEquals(expectedCmd.toString(), clString);
84
85 repo = new SvnScmProviderRepository(
86 "https://svn.apache.org/repos/asf/maven/scm/trunk", "username", "password\"with\"double\"quotes");
87 clString = SvnCommandLineUtils.cryptPassword(
88 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
89 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
90 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
91 assertEquals(expectedCmd.toString(), clString);
92
93 repo = new SvnScmProviderRepository(
94 "https://svn.apache.org/repos/asf/maven/scm/trunk",
95 "username",
96 "password\"with\"double\"quotes and spaces");
97 clString = SvnCommandLineUtils.cryptPassword(
98 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
99 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
100 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
101
102 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
103 assertNotEquals(expectedCmd.toString(), clString);
104 } else {
105 assertEquals(expectedCmd.toString(), clString);
106 }
107
108 repo = new SvnScmProviderRepository(
109 "https://svn.apache.org/repos/asf/maven/scm/trunk",
110 "username",
111 "password\"with\"double\"quotes'and'single'quotes");
112 clString = SvnCommandLineUtils.cryptPassword(
113 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
114 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
115 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
116 assertEquals(expectedCmd.toString(), clString);
117
118 repo = new SvnScmProviderRepository(
119 "https://svn.apache.org/repos/asf/maven/scm/trunk",
120 "username",
121 "password\"with\"double\"quotes'and'single'quotes and spaces");
122 clString = SvnCommandLineUtils.cryptPassword(
123 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
124 expectedCmd = new Commandline("svn --username username --password ***** --no-auth-cache --non-interactive");
125 expectedCmd.setWorkingDirectory(new File(".").getAbsolutePath());
126
127 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
128 assertNotEquals(expectedCmd.toString(), clString);
129 } else {
130 assertEquals(expectedCmd.toString(), clString);
131 }
132
133 repo = new SvnScmProviderRepository("https://svn.apache.org/repos/asf/maven/scm/trunk", "username", null);
134 assertCommandLine(
135 "svn --username username --no-auth-cache --non-interactive",
136 new File("."),
137 SvnCommandLineUtils.getBaseSvnCommandLine(new File("."), repo, false));
138 }
139 }