Skip to content
Permalink
Browse files

Add [JENKINS-46054] failing tests

If the repository URL for a submodule includes ".url" in the
URL, then the submodule query code in the command line git
implementation gathers the wrong name as the name of the
submodule.

These tests check specific conditions with the regular
expression string used to parse the "git config"
output.

They intentionally fail with the current regular expression.
  • Loading branch information
MarkEWaite committed Nov 3, 2017
1 parent c2b1ff4 commit 725a9ac09ac9c7c5970f1bd3cf6c77503017e35f
@@ -141,6 +141,9 @@
private StandardCredentials defaultCredentials;
private StandardCredentials lfsCredentials;

/* Package protected for testing */
final static String SUBMODULE_REMOTE_PATTERN_STRING = "^submodule\\.(.*)\\.url";

private void warnIfWindowsTemporaryDirNameHasSpaces() {
if (!isWindows()) {
return;
@@ -1089,7 +1092,7 @@ else if (!referencePath.isDirectory())
try {
// We might fail if we have no modules, so catch this
// exception and just return.
cfgOutput = launchCommand("config", "-f", ".gitmodules", "--get-regexp", "^submodule\\.(.*)\\.url");
cfgOutput = launchCommand("config", "-f", ".gitmodules", "--get-regexp", SUBMODULE_REMOTE_PATTERN_STRING);
} catch (GitException e) {
listener.error("No submodules found.");
return;
@@ -1098,7 +1101,7 @@ else if (!referencePath.isDirectory())
// Use a matcher to find each configured submodule name, and
// then run the submodule update command with the provided
// path.
Pattern pattern = Pattern.compile("^submodule\\.(.*)\\.url", Pattern.MULTILINE);
Pattern pattern = Pattern.compile(SUBMODULE_REMOTE_PATTERN_STRING, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(cfgOutput);
while (matcher.find()) {
ArgumentListBuilder perModuleArgs = args.clone();
@@ -0,0 +1,110 @@
package org.jenkinsci.plugins.gitclient;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

public class SubmodulePatternStringTest {

private Pattern submoduleConfigPattern;
private String remoteName = "simple-name";

@Before
public void configure() {
// String patternString = "^submodule\\.([^ ]+)\\.url ";
String patternString = CliGitAPIImpl.SUBMODULE_REMOTE_PATTERN_STRING;
submoduleConfigPattern = Pattern.compile(patternString, Pattern.MULTILINE);
}

@Issue("46054")
@Test
public void urlEmbeddedInRepoURL() {
String repoUrl = "file://gitroot/thirdparty.url.repo.git";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}

@Issue("46054")
@Test
public void urlEmbeddedInRepoURLsubmoduleEmbeddedDot() {
String repoUrl = "https://mark.url:some%20pass.urlify@gitroot/repo.git";
remoteName = "simple.name";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}

@Issue("46054")
@Test
public void urlEmbeddedInSubmoduleRepoNameEndsWithURL() {
String repoUrl = "https://gitroot/repo.url";
remoteName = "simple.name";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}

@Issue("46054")
@Test
public void urlEmbeddedInSubmoduleRepoNameEndsWithURLSpace() {
String repoUrl = "https://gitroot/repo.url ";
remoteName = "simple.name";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}

@Issue("46054")
@Test
public void urlEmbeddedInSubmoduleNameAndRepoNameEndsWithURL() {
String repoUrl = "https://gitroot/repo.url.git";
remoteName = "simple.name.url";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}

@Issue("46054")
@Test
public void urlExploratoryTestFailureCase() {
/* See https://github.com/MarkEWaite/JENKINS-46054.url/ */
String repoUrl = "https://github.com/MarkEWaite/JENKINS-46054.url";
remoteName = "modules/JENKINS-46504.url";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}

@Issue("46054")
@Test
public void remoteNameIncludesSubmodule() {
/* See https://github.com/MarkEWaite/JENKINS-46054.url/ */
String repoUrl = "https://github.com/MarkEWaite/JENKINS-46054.url";
remoteName = "submodule.JENKINS-46504.url";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertTrue("Match not found for '" + submoduleConfigOutput + "'", matcher.find());
assertThat(matcher.group(1), is(remoteName));
}

@Issue("46054")
@Test
public void urlEmbeddedInRepoNameEndsWithURLEmptyRemoteName() {
String repoUrl = "https://github.com/MarkEWaite/JENKINS-46054.url.git";
remoteName = "";
String submoduleConfigOutput = "submodule." + remoteName + ".url " + repoUrl;
Matcher matcher = submoduleConfigPattern.matcher(submoduleConfigOutput);
assertFalse("Unexpected match found for '" + submoduleConfigOutput + "'", matcher.find());
}
}

0 comments on commit 725a9ac

Please sign in to comment.
You can’t perform that action at this time.