changeset 791:249eb1d652a7

Merge branch Gaya-8.1.x
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 01 May 2014 19:55:03 +0200
parents 5cf7d1b3c476 (current diff) 914a0b473c45 (diff)
children e86aa7330709
files mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java
diffstat 3 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/AuthSettings.java	Wed Apr 30 20:13:02 2014 +0200
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/AuthSettings.java	Thu May 01 19:55:03 2014 +0200
@@ -134,6 +134,12 @@
     return userInfo;
   }
 
+  @NotNull
+  public static String escapePassword(@NotNull String password) {
+    String escaped = getEscapedUserInfo("user:" + password);
+    return escaped.substring(5);
+  }
+
   private class FakeStreamHandler extends URLStreamHandler {
     @Override
     protected URLConnection openConnection(URL u) throws IOException {
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java	Wed Apr 30 20:13:02 2014 +0200
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/VcsRootCommand.java	Thu May 01 19:55:03 2014 +0200
@@ -22,6 +22,8 @@
 import java.util.Collections;
 import java.util.Set;
 
+import static jetbrains.buildServer.util.CollectionsUtil.setOf;
+
 /**
  * @author dmitry.neverov
  */
@@ -40,6 +42,8 @@
   @NotNull
   protected Set<String> getPrivateData() {
     String password = myAuthSettings.getPassword();
-    return password != null ? Collections.singleton(password) : Collections.<String>emptySet();
+    if (password == null)
+      return Collections.<String>emptySet();
+    return setOf(password, AuthSettings.escapePassword(password));
   }
 }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Wed Apr 30 20:13:02 2014 +0200
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Thu May 01 19:55:03 2014 +0200
@@ -237,6 +237,26 @@
   }
 
 
+  @TestFor(issues = "TW-36251")
+  public void exception_should_contain_no_password_when_password_is_escaped() throws Exception {
+    String pwd = "pa{{word";//'{' requires escaping
+    String escapedPwd = "pa%7B%7Bword";
+    VcsRootImpl root = vcsRoot().withUrl("http://acme.com").withUserName("user").withPassword(pwd).build();
+    File nonExistingHg = myTempFiles.createTempFile();
+    delete(nonExistingHg);
+    String nonExistingHgPath = nonExistingHg.getAbsolutePath();
+    root.addProperty(Constants.HG_COMMAND_PATH_PROP, nonExistingHgPath);
+    try {
+      myVcs.getTestConnectionSupport().testConnection(root);
+      fail("Exception expected");
+    } catch (VcsException e) {
+      String msg = e.getCause().getMessage();
+      assertFalse(msg.contains(pwd));
+      assertFalse(msg.contains(escapedPwd));
+    }
+  }
+
+
   public void test_tag() throws IOException, VcsException {
     VcsRootImpl vcsRoot = createVcsRoot(simpleRepo());