Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Test special characters in credentials workspace path
JENKINS-44041 - Windows authenticated git checkout fails if '(' or ')' in path to workspace
JENKINS-43931 - Windows authenticated git checkout fails if ' ' in path to workspace
JENKINS-44127 - Authenticated git checkout fails if '%' in path to workspace (Windows & Linux)
  • Loading branch information
MarkEWaite committed May 18, 2017
1 parent e91ecef commit 5c74414
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions src/test/java/org/jenkinsci/plugins/gitclient/CredentialsTest.java
Expand Up @@ -70,6 +70,7 @@ public class CredentialsTest {
private final String fileToCheck;
private final Boolean submodules;
private final Boolean useParentCreds;
private final char specialCharacter;

private GitClient git;
private File repo;
Expand Down Expand Up @@ -102,6 +103,11 @@ private static PrintStream log() {
return StreamTaskListener.fromStdout().getLogger();
}

/* Windows refuses directory names with '*', '<', '>', '|', '?', and ':' */
private final String SPECIALS_TO_CHECK = "%()`$&{}[]"
+ (isWindows() ? "" : "*<>:|?");
private static int specialsIndex = 0;

public CredentialsTest(String gitImpl, String gitRepoUrl, String username, String password, File privateKey, String passphrase, String fileToCheck, Boolean submodules, Boolean useParentCreds) {
this.gitImpl = gitImpl;
this.gitRepoURL = gitRepoUrl;
Expand All @@ -112,27 +118,32 @@ public CredentialsTest(String gitImpl, String gitRepoUrl, String username, Strin
this.fileToCheck = fileToCheck;
this.submodules = submodules;
this.useParentCreds = useParentCreds;
this.specialCharacter = SPECIALS_TO_CHECK.charAt(specialsIndex);
specialsIndex = specialsIndex + 1;
if (specialsIndex >= SPECIALS_TO_CHECK.length()) {
specialsIndex = 0;
}
log().println(show("Repo", gitRepoUrl)
+ show("implementation", gitImpl)
+ show("username", username)
+ show("password", password)
+ show("spec", specialCharacter)
+ show("impl", gitImpl)
+ show("user", username)
+ show("pass", password)
+ show("key", privateKey));
}

@Before
public void setUp() throws IOException, InterruptedException {
git = null;
repo = tempFolder.newFolder();
if (random.nextBoolean()) {
/* Randomly use a repo with a space in name - JENKINS-43931 */
String newDirName = "a space";
File repoParent = repo;
repo = new File(repoParent, newDirName);
boolean dirCreated = repo.mkdirs();
assertTrue("Failed to create " + repo.getAbsolutePath(), dirCreated);
File repoTemp = new File(repoParent, newDirName + "@tmp"); // use adjacent temp directory
dirCreated = repoTemp.mkdirs();
assertTrue("Failed to create " + repoTemp.getAbsolutePath(), dirCreated);
}
/* Use a repo with a special character in name - JENKINS-43931 */
String newDirName = "use " + specialCharacter + " dir";
File repoParent = repo;
repo = new File(repoParent, newDirName);
boolean dirCreated = repo.mkdirs();
assertTrue("Failed to create " + repo.getAbsolutePath(), dirCreated);
File repoTemp = new File(repoParent, newDirName + "@tmp"); // use adjacent temp directory
dirCreated = repoTemp.mkdirs();
assertTrue("Failed to create " + repoTemp.getAbsolutePath(), dirCreated);
Logger logger = Logger.getLogger(this.getClass().getPackage().getName() + "-" + logCount++);
handler = new LogHandler();
handler.setLevel(Level.ALL);
Expand Down Expand Up @@ -323,10 +334,7 @@ public static Collection gitRepoUrls() throws MalformedURLException, FileNotFoun
}
}
Collections.shuffle(repos); // randomize test order
int toIndex = repos.size() < 3 ? repos.size() : 3;
if (TEST_ALL_CREDENTIALS) {
toIndex = Math.min(repos.size(), 60); // Don't run more than 60 variations of test - about 9 minutes
}
int toIndex = Math.min(repos.size(), TEST_ALL_CREDENTIALS ? 90 : 6); // Don't run more than 90 variations of test - about 12 minutes
return repos.subList(0, toIndex);
}

Expand Down Expand Up @@ -454,6 +462,14 @@ private String show(String name, File file) {
return "";
}

private String show(String name, char value) {
return " " + name + ": '" + value + "'";
}

private boolean isWindows() {
return File.pathSeparatorChar == ';';
}

/* If not in a Jenkins job, then default to run all credentials tests.
*
* Developers without ~/.ssh/auth-data/repos.json will see no difference
Expand Down

0 comments on commit 5c74414

Please sign in to comment.