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