Search in sources :

Example 21 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class HttpAuthTest method disable_credential_helpers.

@RequiredGitVersion(min = "2.9.0")
@TestFor(issues = { "TW-46668", "TW-45991", "TW-46391" })
public void disable_credential_helpers(@NotNull GitExec git) throws Exception {
    // Test checks that we disable credential helpers configured on machine
    File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git");
    Random r = new Random();
    final String user = "user";
    final String password = String.valueOf(r.nextInt(100));
    myServer = new GitHttpServer(git.getPath(), repo);
    myServer.setCredentials(user, password);
    myServer.start();
    VcsRootImpl root = vcsRoot().withFetchUrl(myServer.getRepoUrl()).withAuthMethod(AuthenticationMethod.PASSWORD).withUsername(user).withPassword(password).withBranch("master").build();
    File buildDir = myTempFiles.createTempDir();
    AgentRunningBuild build = runningBuild().sharedEnvVariable(Constants.TEAMCITY_AGENT_GIT_PATH, git.getPath()).sharedConfigParams(PluginConfigImpl.USE_ALTERNATES, "true").withAgentConfiguration(myAgentConfiguration).withCheckoutDir(buildDir).addRoot(root).build();
    // run first build to initialize mirror:
    Checkout checkout = new Checkout(root, "add81050184d3c818560bdd8839f50024c188586", buildDir, build);
    checkout.run(TimeUnit.SECONDS.toMillis(10));
    assertTrue(checkout.success());
    // update remote repo with new commits:
    FileUtil.delete(repo);
    copyRepository(dataFile("repo_for_fetch.2"), repo);
    // configure hanging credential helper for mirror:
    File mirrorDir = myBuilder.getMirrorManager().getMirrorDir(myServer.getRepoUrl().replaceAll("http://", "http://" + user + "@"));
    Repository mirror = new RepositoryBuilder().setGitDir(mirrorDir).build();
    StoredConfig config = mirror.getConfig();
    config.setString("credential", null, "helper", createHangingCredProvider(100).getCanonicalPath());
    config.save();
    // run build requiring a mirror update, hanging helper should be disabled and checkout should finish successfully
    checkout = new Checkout(root, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168", buildDir, build);
    checkout.run(TimeUnit.SECONDS.toMillis(10));
    assertTrue(checkout.success());
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) GitTestUtil.copyRepository(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository) Repository(org.eclipse.jgit.lib.Repository) Random(java.util.Random) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) RepositoryBuilder(org.eclipse.jgit.lib.RepositoryBuilder) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 22 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class HttpUrlWithUsernameTest method no_username_in_http_urls_upgrade.

@Test(dataProvider = "mirrorModes")
public void no_username_in_http_urls_upgrade(@NotNull MirrorMode mirrorMode) throws Exception {
    // run first build to initialize fetch urls with usernames
    File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git");
    startGitServer(repo);
    VcsRootImpl root = createRoot();
    AgentRunningBuild build1 = createBuild(configParams(mirrorMode, PluginConfigImpl.EXCLUDE_USERNAME_FROM_HTTP_URL, "false"));
    checkout(root, build1, "add81050184d3c818560bdd8839f50024c188586");
    // update remote repo to cause fetch
    FileUtil.delete(repo);
    copyRepository(dataFile("repo_for_fetch.2"), repo);
    AgentRunningBuild build = createBuild(configParams(mirrorMode));
    checkout(root, build, "d47dda159b27b9a8c4cee4ce98e4435eb5b17168");
    if (mirrorMode != MirrorMode.DISABLED) {
        StoredConfig config = getMirrorConfig(root);
        then(config.getString("remote", "origin", "url")).doesNotContain(USER + "@");
        then(config.getString("credential", null, "username")).isEqualTo(USER);
    }
    StoredConfig config = getWorkingDirConfig();
    then(config.getString("remote", "origin", "url")).doesNotContain(USER + "@");
    then(config.getString("credential", null, "username")).isEqualTo(USER);
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 23 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class HttpUrlWithUsernameTest method no_username_in_http_urls.

@Test(dataProvider = "mirrorModes")
public void no_username_in_http_urls(@NotNull MirrorMode mirrorMode) throws Exception {
    File repo = copyRepository(myTempFiles, dataFile("repo_for_fetch.1"), "repo.git");
    startGitServer(repo);
    VcsRootImpl root = createRoot();
    AgentRunningBuild build = createBuild(configParams(mirrorMode));
    checkout(root, build, "add81050184d3c818560bdd8839f50024c188586");
    if (mirrorMode != MirrorMode.DISABLED) {
        StoredConfig config = getMirrorConfig(root);
        then(config.getString("remote", "origin", "url")).doesNotContain(USER + "@");
        then(config.getString("credential", null, "username")).isEqualTo(USER);
    }
    StoredConfig config = getWorkingDirConfig();
    then(config.getString("remote", "origin", "url")).doesNotContain(USER + "@");
    then(config.getString("credential", null, "username")).isEqualTo(USER);
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) AgentRunningBuild(jetbrains.buildServer.agent.AgentRunningBuild) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test)

Example 24 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class TestConnectionTest method test_not_existing_local_repository.

@TestFor(issues = "TW-9933")
public void test_not_existing_local_repository() throws Exception {
    File notExisting = new File(myTempFiles.createTempDir(), "not-existing");
    String url = GitUtils.toURL(notExisting);
    VcsRootImpl root = vcsRoot().withFetchUrl(url).build();
    try {
        myGit.testConnection(root);
        fail("Should throw an exception for not-existing repository");
    } catch (VcsException e) {
        TeamCityAsserts.assertContainsAny(e.getMessage(), "Cannot access the '" + url + "' repository", "Please make sure you have the correct access rights and the repository exists");
        assertFalse(e.getMessage().endsWith("\n"));
    }
}
Also used : VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 25 with VcsRootImpl

use of jetbrains.buildServer.vcs.impl.VcsRootImpl in project teamcity-git by JetBrains.

the class TestConnectionTest method wrong_github_username.

@TestFor(issues = "TW-24074")
@Test(dataProvider = "common-github-auth-errors")
public void wrong_github_username(@NotNull final String error) {
    TransportFactory factoryWithGivenError = new TransportFactory() {

        public Transport createTransport(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings) throws NotSupportedException, VcsException, TransportException {
            return createTransport(r, url, authSettings, 60);
        }

        public Transport createTransport(@NotNull Repository r, @NotNull URIish url, @NotNull AuthSettings authSettings, int timeoutSeconds) throws NotSupportedException, VcsException, TransportException {
            throw new TransportException(url.toString() + ": " + error, new JSchException(error));
        }

        @NotNull
        @Override
        public SshSessionFactory getSshSessionFactory(@NotNull URIish url, @NotNull AuthSettings authSettings) throws VcsException {
            throw new UnsupportedOperationException();
        }
    };
    myGit = gitSupport().withTransportFactory(factoryWithGivenError).withServerPaths(myPaths).build();
    String wrongUsername = "user";
    VcsRootImpl root = vcsRoot().withFetchUrl("git@github.com:user/repo.git").withBranch("master").withAuthMethod(AuthenticationMethod.PRIVATE_KEY_DEFAULT).withUsername(wrongUsername).build();
    try {
        myGit.testConnection(root);
        fail("should fail during transport creation");
    } catch (VcsException e) {
        assertTrue(e.getMessage(), e.getMessage().contains("Wrong username: '" + wrongUsername + "', GitHub expects the 'git' username"));
    }
}
Also used : URIish(org.eclipse.jgit.transport.URIish) JSchException(com.jcraft.jsch.JSchException) Repository(org.eclipse.jgit.lib.Repository) VcsRootImpl(jetbrains.buildServer.vcs.impl.VcsRootImpl) VcsException(jetbrains.buildServer.vcs.VcsException) NotNull(org.jetbrains.annotations.NotNull) TransportException(org.eclipse.jgit.errors.TransportException) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)51 File (java.io.File)35 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)34 TestFor (jetbrains.buildServer.util.TestFor)26 Test (org.testng.annotations.Test)25 VcsException (jetbrains.buildServer.vcs.VcsException)10 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)9 LockFile (org.eclipse.jgit.internal.storage.file.LockFile)9 StoredConfig (org.eclipse.jgit.lib.StoredConfig)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 AgentRunningBuild (jetbrains.buildServer.agent.AgentRunningBuild)6 AfterMethod (org.testng.annotations.AfterMethod)6 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)5 NotNull (org.jetbrains.annotations.NotNull)5 JSchException (com.jcraft.jsch.JSchException)4 Repository (org.eclipse.jgit.lib.Repository)4 ServerPaths (jetbrains.buildServer.serverSide.ServerPaths)3 VcsRootSshKeyManager (jetbrains.buildServer.ssh.VcsRootSshKeyManager)3