1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.scm;
20
21 import org.junit.Test;
22
23 import static org.junit.Assert.assertNotSame;
24 import static org.junit.Assert.assertTrue;
25
26 public class ScmResultTest {
27
28 private static final String PASSWORD = "secr$t";
29
30 private static final String SCM_URL_GIT_COLON =
31 "scm:git:https://username:" + PASSWORD + "@github.com/username/repo.git";
32
33 private static final String MOCK_ERROR_OUTPUT = "fatal: repository '" + SCM_URL_GIT_COLON + "' not found";
34
35 private static final String MOCK_ERROR_MULTILINE_OUTPUT = "remote: Invalid username or password."
36 + System.lineSeparator() + "fatal: Authentication failed for '" + SCM_URL_GIT_COLON + "'";
37
38 @Test
39 public void testPasswordsAreMaskedInOutput() throws Exception {
40 ScmResult result = new ScmResult("git push", "git-push failed", MOCK_ERROR_OUTPUT, false);
41 assertNotSame("Command output contains password", MOCK_ERROR_OUTPUT, result.getCommandOutput());
42 assertTrue("Command output not masked", result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER));
43
44 result = new ScmResult("git push", "git-push failed", MOCK_ERROR_MULTILINE_OUTPUT, false);
45 assertNotSame("Command output contains password", MOCK_ERROR_MULTILINE_OUTPUT, result.getCommandOutput());
46 assertTrue("Command output not masked", result.getCommandOutput().contains(ScmResult.PASSWORD_PLACE_HOLDER));
47 }
48 }