Search in sources :

Example 81 with TestFor

use of jetbrains.buildServer.util.TestFor 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)

Example 82 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class TransportFactoryTest method transport_for_anonymous_protocol_should_not_have_credentials.

@TestFor(issues = "TW-25087")
public void transport_for_anonymous_protocol_should_not_have_credentials() throws Exception {
    File tmp = myTempFiles.createTempDir();
    Repository r = new RepositoryBuilder().setBare().setGitDir(tmp).build();
    VcsRoot root = vcsRoot().withFetchUrl("git://some.org/repo.git").withAuthMethod(AuthenticationMethod.PASSWORD).withUsername("user").withPassword("pwd").build();
    AuthSettings authSettings = new AuthSettingsImpl(root, new URIishHelperImpl());
    TransportFactory factory = new TransportFactoryImpl(myConfigBuilder.build(), new EmptyVcsRootSshKeyManager());
    factory.createTransport(r, new URIishHelperImpl().createAuthURI(authSettings, "git://some.org/repo.git").get(), authSettings);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) RepositoryBuilder(org.eclipse.jgit.lib.RepositoryBuilder) GitTestUtil.getVcsRoot(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.getVcsRoot) VcsRoot(jetbrains.buildServer.vcs.VcsRoot) GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) TestFor(jetbrains.buildServer.util.TestFor)

Example 83 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class FetchCommandImplTest method should_throw_special_exception_when_stderr_mentions_broken_index.

@TestFor(issues = "TW-18853")
public void should_throw_special_exception_when_stderr_mentions_broken_index() throws VcsException {
    AgentGitCommandLine failedCmd = new AgentGitCommandLine(null, getFakeGen(), new StubContext()) {

        @Override
        public ExecResult run(@NotNull GitCommandSettings settings) throws VcsException {
            throw new VcsException("fatal: index file smaller than expected");
        }
    };
    FetchCommand fetch = new FetchCommandImpl(failedCmd).setRefspec("+refs/heads/*:refs/remotes/origin/*").setTimeout(3600).setAuthSettings(getEmptyAuthSettings());
    try {
        fetch.call();
    } catch (GitIndexCorruptedException e) {
    // expected
    } catch (VcsException e) {
        fail("GitIndexCorruptedException should be thrown");
    }
}
Also used : GitCommandSettings(jetbrains.buildServer.buildTriggers.vcs.git.command.GitCommandSettings) FetchCommandImpl(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.FetchCommandImpl) GitIndexCorruptedException(jetbrains.buildServer.buildTriggers.vcs.git.command.errors.GitIndexCorruptedException) FetchCommand(jetbrains.buildServer.buildTriggers.vcs.git.command.FetchCommand) StubContext(jetbrains.buildServer.buildTriggers.vcs.git.command.impl.StubContext) VcsException(jetbrains.buildServer.vcs.VcsException) AgentGitCommandLine(jetbrains.buildServer.buildTriggers.vcs.git.agent.AgentGitCommandLine) NotNull(org.jetbrains.annotations.NotNull) TestFor(jetbrains.buildServer.util.TestFor)

Example 84 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class SshAuthenticationTest method ssh_git_rsa_key_file_with_no_cr_lf_on_end.

@TestFor(issues = "TW-75138")
@Test(dataProvider = "true,false")
public void ssh_git_rsa_key_file_with_no_cr_lf_on_end(boolean nativeOperationsEnabled) throws Exception {
    final File key = dataFile("keys/id_rsa");
    final File wrong_key = myTempFiles.createTempFile((FileUtil.readText(key, "UTF-8").trim()).replace("\n", "\r\n"));
    do_ssh_test(nativeOperationsEnabled, true, "ssh://git@%s:%s/home/git/repo.git", "", null, "keys/id_rsa.pub", b -> b.withAuthMethod(AuthenticationMethod.PRIVATE_KEY_FILE).withPrivateKeyPath(wrong_key.getAbsolutePath()));
}
Also used : GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Example 85 with TestFor

use of jetbrains.buildServer.util.TestFor in project teamcity-git by JetBrains.

the class SshAuthenticationTest method ssh_git_rsa_key_file_with_extra_lf_on_end.

@TestFor(issues = "TW-75138")
@Test(dataProvider = "true,false")
public void ssh_git_rsa_key_file_with_extra_lf_on_end(boolean nativeOperationsEnabled) throws Exception {
    final File key = dataFile("keys/id_rsa");
    final File wrong_key = myTempFiles.createTempFile((FileUtil.readText(key, "UTF-8") + "\n"));
    do_ssh_test(nativeOperationsEnabled, true, "ssh://git@%s:%s/home/git/repo.git", "", null, "keys/id_rsa.pub", b -> b.withAuthMethod(AuthenticationMethod.PRIVATE_KEY_FILE).withPrivateKeyPath(wrong_key.getAbsolutePath()));
}
Also used : GitTestUtil.dataFile(jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile) File(java.io.File) Test(org.testng.annotations.Test) TestFor(jetbrains.buildServer.util.TestFor)

Aggregations

TestFor (jetbrains.buildServer.util.TestFor)129 Test (org.testng.annotations.Test)81 File (java.io.File)65 GitTestUtil.dataFile (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.dataFile)56 VcsRootImpl (jetbrains.buildServer.vcs.impl.VcsRootImpl)26 CheckoutRules (jetbrains.buildServer.vcs.CheckoutRules)21 VcsRoot (jetbrains.buildServer.vcs.VcsRoot)17 SFinishedBuild (jetbrains.buildServer.serverSide.SFinishedBuild)12 VcsException (jetbrains.buildServer.vcs.VcsException)11 URIish (org.eclipse.jgit.transport.URIish)11 Repository (org.eclipse.jgit.lib.Repository)9 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)7 AfterMethod (org.testng.annotations.AfterMethod)7 BeforeMethod (org.testng.annotations.BeforeMethod)7 Method (java.lang.reflect.Method)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 GitTestUtil.copyRepository (jetbrains.buildServer.buildTriggers.vcs.git.tests.GitTestUtil.copyRepository)6 Build (jetbrains.buildServer.server.rest.model.build.Build)6 BuildTypeImpl (jetbrains.buildServer.serverSide.impl.BuildTypeImpl)6 FileUtil.writeFile (jetbrains.buildServer.util.FileUtil.writeFile)6