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"));
}
}
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);
}
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");
}
}
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()));
}
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()));
}
Aggregations