fix some bugs in url support
authorPavel Sher <pavel.sher@gmail.com>
Sun, 24 Nov 2013 18:11:21 +0000 (19:11 +0100)
committerPavel Sher <pavel.sher@gmail.com>
Sun, 24 Nov 2013 18:11:21 +0000 (19:11 +0100)
git-server/src/jetbrains/buildServer/buildTriggers/vcs/git/GitUrlSupport.java
git-tests/src/jetbrains/buildServer/buildTriggers/vcs/git/tests/GitUrlSupportTest.java

index a2172aed247b05da78a1dbcf3242123aba31f7b3..76001ac753b6409050eb19cbcb05d15d7bc14c16 100644 (file)
@@ -65,21 +65,22 @@ public class GitUrlSupport implements UrlSupport {
     }
 
     Credentials credentials = url.getCredentials();
-    Map<String, String> props = new HashMap<String, String>();
+    Map<String, String> props = new HashMap<String, String>(myGitSupport.getDefaultVcsProperties());
     props.put(Constants.FETCH_URL, fetchUrl);
+    props.put(Constants.AUTH_METHOD, AuthenticationMethod.ANONYMOUS.toString());
+
     if (credentials != null) {
+      props.put(Constants.AUTH_METHOD, AuthenticationMethod.PASSWORD.toString());
       props.put(Constants.USERNAME, credentials.getUsername());
+      props.put(Constants.PASSWORD, credentials.getPassword());
     }
+
     final boolean scpSyntax = isScpSyntax(uri);
     if (scpSyntax || "ssh".equals(uri.getScheme())) {
       if (scpSyntax && credentials == null) {
         props.put(Constants.USERNAME, uri.getUser());
       }
       props.put(Constants.AUTH_METHOD, AuthenticationMethod.PRIVATE_KEY_DEFAULT.toString());
-      props.put(Constants.IGNORE_KNOWN_HOSTS, "true");
-    } else if (credentials != null && !StringUtil.isEmptyOrSpaces(fetchUrl)) {
-      props.put(Constants.AUTH_METHOD, AuthenticationMethod.PASSWORD.toString());
-      props.put(Constants.PASSWORD, credentials.getPassword());
     }
 
     if (testRequired) {
index da040d222a983d570ac77acaca229656f5bffad6..9bca5915029d4337056cf9417e0d8d36c6427ce5 100644 (file)
@@ -124,7 +124,21 @@ public class GitUrlSupportTest extends BaseTestCase {
     VcsUrl url = new VcsUrl("http://git.jetbrains.org/teamcity/git-plugin.git");
     GitVcsRoot root = toGitRoot(url);
 
-    assertEquals("http://git.jetbrains.org/teamcity/git-plugin.git", root.getRepositoryFetchURL().toString());
+    assertEquals("http://git.jetbrains.org/teamcity/git-plugin.git", root.getProperty(Constants.FETCH_URL));
+    assertEquals("refs/heads/master", root.getProperty(Constants.BRANCH_NAME));
+    assertEquals(AuthenticationMethod.ANONYMOUS.name(), root.getProperty(Constants.AUTH_METHOD));
+  }
+
+  @Test
+  public void http_protocol_with_credentials() throws Exception {
+    VcsUrl url = new VcsUrl("http://git.jetbrains.org/teamcity/git-plugin.git", new Credentials("user1", "pwd1"));
+    GitVcsRoot root = toGitRoot(url);
+
+    assertEquals("http://git.jetbrains.org/teamcity/git-plugin.git", root.getProperty(Constants.FETCH_URL));
+    assertEquals("refs/heads/master", root.getProperty(Constants.BRANCH_NAME));
+    assertEquals(AuthenticationMethod.PASSWORD.name(), root.getProperty(Constants.AUTH_METHOD));
+    assertEquals("user1", root.getProperty(Constants.USERNAME));
+    assertEquals("pwd1", root.getProperty(Constants.PASSWORD));
   }
 
   @Test