view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/SettingsTest.java @ 322:6667765025c6

Merge branch Eluru-6.5.x
author Dmitry Neverov <dmitry.neverov@jetbrains.com>
date Mon, 19 Sep 2011 12:02:37 +0400
parents 33305b2022c2 568ce42b1e9d
children e5b15dc36e63
line wrap: on
line source
/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jetbrains.buildServer.buildTriggers.vcs.mercurial;

import jetbrains.buildServer.TempFiles;
import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.Settings;
import jetbrains.buildServer.vcs.VcsRoot;
import jetbrains.buildServer.vcs.impl.VcsRootImpl;
import junit.framework.TestCase;
import org.jetbrains.annotations.NotNull;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

/**
 * @author Pavel.Sher
 */
@Test
public class SettingsTest extends TestCase {

  private TempFiles myTempFiles = new TempFiles();
  private MirrorManager myMirrorManager;

  @Override
  @BeforeMethod
  public void setUp() throws Exception {
    myMirrorManager = new MirrorManager(myTempFiles.createTempDir());
  }

  @Override
  @AfterMethod
  public void tearDown() throws Exception {
    myTempFiles.cleanup();
  }

  public void test_url_without_credentials() {
    VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path");
    Settings settings = createSettings(vcsRoot);
    assertEquals("http://user:pwd@host.com/path", settings.getRepositoryUrl());
  }

  public void test_url_with_credentials() {
    VcsRootImpl vcsRoot = createVcsRoot("http://user:pwd@host.com/path");
    Settings settings = createSettings(vcsRoot);
    assertEquals("http://user:pwd@host.com/path", settings.getRepositoryUrl());
  }

  public void test_url_with_username() {
    VcsRootImpl vcsRoot = createVcsRoot("http://user@host.com/path");
    Settings settings = createSettings(vcsRoot);
    assertEquals("http://user:pwd@host.com/path", settings.getRepositoryUrl());
  }

  public void test_url_with_at_after_slash() {
    VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path@");
    Settings settings = createSettings(vcsRoot);
    assertEquals("http://user:pwd@host.com/path@", settings.getRepositoryUrl());
  }

  public void test_url_with_at_in_username() {
    VcsRootImpl vcsRoot = createVcsRoot("http://host.com/path", "my.name@gmail.com", "1234");
    Settings settings = createSettings(vcsRoot);
    assertEquals("http://my.name%40gmail.com:1234@host.com/path", settings.getRepositoryUrl());
  }

  /** TW-13768 */
  public void test_underscore_in_host() {
		VcsRootImpl vcsRoot = createVcsRoot("http://Klekovkin.SDK_GARANT:8000/", "my.name@gmail.com", "1234");
    Settings settings = createSettings(vcsRoot);
		assertEquals("http://my.name%40gmail.com:1234@Klekovkin.SDK_GARANT:8000/", settings.getRepositoryUrl());
	}

  /** TW-13768 */
  public void test_underscore_in_host_with_credentials_in_url() {
    VcsRootImpl vcsRoot = createVcsRoot("http://me:mypass@Klekovkin.SDK_GARANT:8000/");
    Settings settings = createSettings(vcsRoot);
		assertEquals("http://me:mypass@Klekovkin.SDK_GARANT:8000/", settings.getRepositoryUrl());
  }

  public void test_windows_path() throws Exception {
    VcsRootImpl vcsRoot = createVcsRoot("c:\\windows\\path");
    Settings settings = createSettings(vcsRoot);
    assertEquals("c:\\windows\\path", settings.getRepositoryUrl());
  }

  public void test_file_scheme_has_no_credentials() {
    VcsRootImpl vcsRoot = createVcsRoot("file:///path/to/repo", "my.name@gmail.com", "1234");
    Settings settings = createSettings(vcsRoot);
    assertEquals("file:///path/to/repo", settings.getRepositoryUrl());
  }

  public void uncompressed_transfer() {
    VcsRootImpl root = createVcsRoot("http://host.com/path");
    root.addProperty(Constants.UNCOMPRESSED_TRANSFER, "true");
    Settings settings = createSettings(root);
    assertTrue(settings.isUncompressedTransfer());
  }

  //TW-18262
  public void ampersand_in_password() {
    VcsRootImpl vcsRoot = createVcsRoot("http://some.org/path", "user", "m&n");
    Settings settings = createSettings(vcsRoot);
    assertEquals("http://user:m%26n@some.org/path", settings.getRepositoryUrl());
  }

  private VcsRootImpl createVcsRoot(String url) {
    return createVcsRoot(url, "user", "pwd");
  }

  private VcsRootImpl createVcsRoot(String url, String userName, String password) {
    VcsRootImpl vcsRoot = new VcsRootImpl(1, Constants.VCS_NAME);
    vcsRoot.addProperty(Constants.HG_COMMAND_PATH_PROP, "hg.exe");
    vcsRoot.addProperty(Constants.REPOSITORY_PROP, url);
    vcsRoot.addProperty(Constants.USERNAME, userName);
    vcsRoot.addProperty(Constants.PASSWORD, password);
    return vcsRoot;
  }

  private Settings createSettings(@NotNull final VcsRoot root) {
    ServerPluginConfig config = new ServerPluginConfigBuilder().build();
    return new Settings(new ServerHgPathProvider(config), root);
  }
}