changeset 531:81fa236998d4 Faradi-7.1.x

TW-25057 custom clone dir should not contains password
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Thu, 10 Jan 2013 21:15:25 +0400
parents 64d3b1f5ae6b
children b58a75b12b7b d012388935fb 81b23a900379
files mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java mercurial-tests/src/testng.xml
diffstat 5 files changed, 68 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java	Mon Dec 17 15:38:55 2012 +0400
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java	Thu Jan 10 21:15:25 2013 +0400
@@ -28,7 +28,7 @@
       createClonedRepositoryParentDir(parentDir);
 
       // take last part of repository path
-      String repPath = hgRoot.getRepositoryUrlWithCredentials();
+      String repPath = hgRoot.getRepository();
       String[] splitted = repPath.split("[/\\\\]");
       if (splitted.length > 0) {
         repPath = splitted[splitted.length-1];
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java	Thu Jan 10 21:15:25 2013 +0400
@@ -0,0 +1,46 @@
+package jetbrains.buildServer.buildTriggers.vcs.mercurial;
+
+import jetbrains.buildServer.TempFiles;
+import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot;
+import jetbrains.buildServer.util.TestFor;
+import jetbrains.buildServer.vcs.VcsRoot;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.ServerPluginConfigBuilder.serverPluginConfig;
+import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot;
+import static org.testng.AssertJUnit.assertFalse;
+
+@Test
+public class HgVcsRootFactoryTest {
+
+  private TempFiles myTempFiles;
+
+  @BeforeMethod(alwaysRun = true)
+  public void setUp() {
+    myTempFiles = new TempFiles();
+  }
+
+  @AfterMethod(alwaysRun = true)
+  public void tearDown() {
+    myTempFiles.cleanup();
+  }
+
+  @TestFor(issues = "TW-25057")
+  public void vcs_root_custom_clone_dir_should_not_contain_password() throws Exception {
+    TempFiles tmp = new TempFiles();
+    String urlWithoutPath = "http://only.host/";
+    String password = "pwd";
+    VcsRoot root = vcsRoot()
+            .withUrl(urlWithoutPath)
+            .withUserName("user")
+            .withPassword(password)
+            .withCloneRepositoryTo(tmp.createTempDir())
+            .build();
+
+    HgVcsRoot hgRoot = new HgVcsRootFactory(serverPluginConfig().cachesDir(tmp.createTempDir()).build()).createHgRoot(root);
+    assertFalse("Custom clone dir contains password", hgRoot.getCustomWorkingDir().getName().contains(password));
+  }
+
+}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java	Mon Dec 17 15:38:55 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerPluginConfigBuilder.java	Thu Jan 10 21:15:25 2013 +0400
@@ -51,6 +51,11 @@
   }
 
 
+  public static ServerPluginConfigBuilder serverPluginConfig() {
+    return new ServerPluginConfigBuilder();
+  }
+
+
   public ServerPluginConfigBuilder userPullProtocol(boolean doUse) {
     myUsePullProtocol = doUse;
     return this;
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java	Mon Dec 17 15:38:55 2012 +0400
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java	Thu Jan 10 21:15:25 2013 +0400
@@ -6,6 +6,7 @@
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 
+import java.io.File;
 import java.io.IOException;
 
 /**
@@ -21,6 +22,7 @@
   private String myHgPath;
   private String myUserForTag;
   private boolean myUncompressed = true;
+  private File myCloneRepositoryTo;
 
   public static VcsRootBuilder vcsRoot() {
     return new VcsRootBuilder();
@@ -35,6 +37,8 @@
     vcsRoot.addProperty(Constants.BRANCH_NAME_PROP, myBranch);
     vcsRoot.addProperty(Constants.USER_FOR_TAG, myUserForTag);
     vcsRoot.addProperty(Constants.UNCOMPRESSED_TRANSFER, String.valueOf(myUncompressed));
+    if (myCloneRepositoryTo != null)
+      vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, String.valueOf(myCloneRepositoryTo.getAbsolutePath()));
     return vcsRoot;
   }
 
@@ -52,6 +56,11 @@
       allowing(root).getProperty(with(Constants.UNCOMPRESSED_TRANSFER)); will(returnValue(null));
       allowing(root).getProperty(with(Constants.USER_FOR_TAG)); will(returnValue(myUserForTag));
     }});
+    if (myCloneRepositoryTo != null) {
+      context.checking(new Expectations() {{
+        allowing(root).getProperty(with(Constants.SERVER_CLONE_PATH_PROP)); will(returnValue(myCloneRepositoryTo.getAbsolutePath()));
+      }});
+    }
     return root;
   }
 
@@ -96,4 +105,10 @@
     myUserForTag = username;
     return this;
   }
+
+
+  public VcsRootBuilder withCloneRepositoryTo(File cloneTo) {
+    myCloneRepositoryTo = cloneTo;
+    return this;
+  }
 }
--- a/mercurial-tests/src/testng.xml	Mon Dec 17 15:38:55 2012 +0400
+++ b/mercurial-tests/src/testng.xml	Thu Jan 10 21:15:25 2013 +0400
@@ -27,6 +27,7 @@
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.RevisionFormatTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.HgFileUtilTest"/>
       <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialXmlLogParserTest"/>
+      <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.HgVcsRootFactoryTest"/>
     </classes>
   </test>
 </suite>