Mercurial > hg > mercurial
view mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialUrlSupportTest.java @ 1054:b01c7d60afb2 release-92072
TW-70054
author | victory.bedrosova |
---|---|
date | Fri, 12 Feb 2021 16:27:47 +0100 |
parents | 7bf4d943d5bb |
children | 8e5475e8adbd |
line wrap: on
line source
/* * Copyright 2000-2018 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.util.TestFor; import jetbrains.buildServer.vcs.Credentials; import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsUrl; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.util.Map; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialSupportBuilder.mercurialSupport; import static junit.framework.Assert.*; @Test public class MercurialUrlSupportTest extends BaseMercurialTestCase { private MercurialUrlSupport myUrlSupport; @BeforeMethod @Override public void setUp() throws Exception { super.setUp(); ServerPluginConfig myPluginConfig = new ServerPluginConfigBuilder() .cachesDir(myTempFiles.createTempDir()) .build(); MercurialVcsSupport vcsSupport = mercurialSupport().withConfig(myPluginConfig).build(); myUrlSupport = new MercurialUrlSupport(vcsSupport); } public void maven_like_url() throws VcsException { VcsUrl url = new VcsUrl("scm:hg:http://host/v3", new Credentials("user1", "pass1")); Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url); assertNotNull(props); assertEquals("http://host/v3", props.get(Constants.REPOSITORY_PROP)); assertEquals("user1", props.get(Constants.USERNAME)); assertEquals("pass1", props.get(Constants.PASSWORD)); } public void http_protocol_mercurial_repo() throws VcsException { VcsUrl url = new VcsUrl("http://hg.jetbrains.org/hg/mercurial/", new Credentials("user1", "pass1")); Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url); assertNotNull(props); assertEquals("http://hg.jetbrains.org/hg/mercurial/", props.get(Constants.REPOSITORY_PROP)); assertEquals("user1", props.get(Constants.USERNAME)); assertEquals("pass1", props.get(Constants.PASSWORD)); } public void ssh_protocol_mercurial_repo() throws VcsException { VcsUrl url = new VcsUrl("ssh://hg@bitbucket.org/user/repo"); Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url); assertNotNull(props); assertEquals("ssh://hg@bitbucket.org/user/repo", props.get(Constants.REPOSITORY_PROP)); } public void http_protocol_svn_repo() throws VcsException { VcsUrl url = new VcsUrl("http://svn.jetbrains.org/teamcity/plugins/xml-tests-reporting/trunk"); Map<String, String> props = myUrlSupport.convertToVcsRootProperties(url); assertNull(props); } @TestFor(issues = "TW-70054") public void exception_on_command_injection() throws VcsException { try { myUrlSupport.convertToVcsRootProperties(new VcsUrl("--config=hooks.pre-identify=whoami>/tmp/JRNJRN")); } catch (IllegalArgumentException e) { // expected return; } fail("Expection not thrown "); } }