Mercurial > hg > mercurial
diff mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java @ 981:64b5816390f9 Indore-2017.2.x
TW-50054 support hg path whitelist
Use hg path from VCS root only if it in whitelist
author | Dmitry Neverov <dmitry.neverov@gmail.com> |
---|---|
date | Wed, 24 Jan 2018 21:19:56 +0100 |
parents | 2b1bd4bca6ad |
children | 4a0ea921c214 |
line wrap: on
line diff
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java Wed Jan 24 13:49:01 2018 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java Wed Jan 24 21:19:56 2018 +0100 @@ -141,6 +141,30 @@ assertEquals(hgRoot.getCustomClonePath(), tempDir.getCanonicalPath()); } + public void hg_path_whitelist() throws Exception { + assertFalse(HgVcsRoot.isAllowedHgPath(null)); + assertFalse(HgVcsRoot.isAllowedHgPath("/some/path")); + setInternalProperty(Constants.HG_PATH_WHITELIST, "/some/path1;/some/path2"); + assertTrue(HgVcsRoot.isAllowedHgPath("/some/path1")); + assertTrue(HgVcsRoot.isAllowedHgPath("/some/path2")); + assertFalse(HgVcsRoot.isAllowedHgPath("/some/other/path")); + assertFalse(HgVcsRoot.isAllowedHgPath("/some/path11")); + assertFalse(HgVcsRoot.isAllowedHgPath("/some/path1/hg")); + + ServerHgPathProvider serverHgPathProvider = new ServerHgPathProvider(new ServerPluginConfigBuilder().build()); + HgVcsRoot root = new HgVcsRoot(vcsRoot().withHgPath("/some/other/path").withUrl("http://some.org/repo").build()); + assertEquals("hg", serverHgPathProvider.getHgPath(root)); + + serverHgPathProvider = new ServerHgPathProvider(new ServerPluginConfigBuilder().hgPath("/server/hg/path").build()); + root = new HgVcsRoot(vcsRoot().withHgPath("/some/other/path").withUrl("http://some.org/repo").build()); + assertEquals("/server/hg/path", serverHgPathProvider.getHgPath(root)); + + root = new HgVcsRoot(vcsRoot().withHgPath("/some/path1").withUrl("http://some.org/repo").build()); + assertEquals("/some/path1", serverHgPathProvider.getHgPath(root)); + root = new HgVcsRoot(vcsRoot().withHgPath("/some/path2").withUrl("http://some.org/repo").build()); + assertEquals("/some/path2", serverHgPathProvider.getHgPath(root)); + } + private VcsRootImpl createVcsRoot(String url) { return createVcsRoot(url, "user", "pwd"); }