Permalink
Browse files

added a test for cloning via private key authentication

  • Loading branch information...
1 parent 1ec3031 commit 23e8923d1cfd8d5403f3d8e7e1234ae6daaf85ac @henon committed Mar 31, 2010
View
@@ -177,13 +177,14 @@ private static FileSystemInfo resolveImpl(DirectoryInfo dir, string name)
*/
public static DirectoryInfo userHome()
{
- return USER_HOME.home;
+ return UserHomeStrategy();
+ //return USER_HOME.home;
}
- private static class USER_HOME
- {
- public static DirectoryInfo home = userHomeImpl();
- }
+ //private static class USER_HOME
+ //{
+ // public static DirectoryInfo home = userHomeStrategy();
+ //}
/**
* Determine the user's home directory (location where preferences are).
@@ -209,7 +210,15 @@ private static DirectoryInfo userHomeImpl()
return new DirectoryInfo(userHomeFolderPath);
}
- /**
+ public static Func<DirectoryInfo> UserHomeStrategy = userHomeImpl;
+
+ public static Func<DirectoryInfo> StandardUserHomeStrategy
+ {
+ get { return userHomeImpl; }
+ }
+
+
+ /**
* Determine the global application directory (location where preferences are).
* Also known as the "all users" directory.
* <para />
@@ -787,6 +787,9 @@
<None Include="Resources\single_file_commit\i-am-a-file">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+ <None Include="Resources\ssh\known_hosts">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
<None Include="Resources\SubmoduleRepository.git\COMMIT_EDITMSG">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -868,6 +871,9 @@
<None Include="Resources\SubmoduleRepository.git\refs\heads\master">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+ <None Include="Resources\ssh\id_rsa">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GitSharp\GitSharp.csproj">
@@ -37,6 +37,7 @@
*/
using System;
+using GitSharp.Commands;
using GitSharp.Core;
using GitSharp.Core.Exceptions;
using GitSharp.Core.Util;
@@ -47,91 +48,125 @@
namespace GitSharp.Tests.GitSharp
{
- [TestFixture]
- public class CloneTests : RepositoryTestCase
- {
- [Test]
- public void Check_cloned_bare_repo()
- {
- Assert.Ignore("This test has not been implemented yet.");
- }
-
- [Test]
- public void Check_cloned_repo_git()
- {
- string toPath = Path.Combine(trash.FullName, "test");
- string fromUrl = "git://github.com/henon/TestGitRepository.git";
-
- using (Repository repo = Git.Clone(fromUrl, toPath))
- {
- var status = new RepositoryStatus(repo, new RepositoryStatusOptions { ForceContentCheck = false });
- Assert.IsFalse(status.AnyDifferences);
-
- status = new RepositoryStatus(repo, new RepositoryStatusOptions { ForceContentCheck = true });
- Assert.IsFalse(status.AnyDifferences);
-
- Assert.IsTrue(Repository.IsValid(repo.Directory));
- //Verify content is in the proper location
- var readme = Path.Combine(repo.WorkingDirectory, "master.txt");
- Assert.IsTrue(new FileInfo(readme).Exists);
- }
- }
-
- [Test]
- public void Try_cloning_non_existing_repo_git()
- {
- string toPath = Path.Combine(trash.FullName, "test");
- string fromUrl = "git://github.com/henon/nonExistingRepo.git";
- AssertHelper.Throws<NoRemoteRepositoryException>(() => { using (Repository repo = Git.Clone(fromUrl, toPath)) { } }, "Repository shouldn't exist.");
- }
-
- [Test]
- [Ignore("TransportLocal is not completely ported yet.")]
- public void Checked_cloned_local_dotGit_suffixed_repo()
- {
- //setup of .git directory
- var resource =
- new DirectoryInfo(PathUtil.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"),
- "OneFileRepository"));
- var tempRepository =
- new DirectoryInfo(Path.Combine(trash.FullName, "OneFileRepository" + Path.GetRandomFileName() + Constants.DOT_GIT_EXT));
- CopyDirectory(resource.FullName, tempRepository.FullName);
-
- var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, Constants.DOT_GIT));
- Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName);
-
-
- using (var repo = new Repository(repositoryPath.FullName))
- {
- Assert.IsTrue(Repository.IsValid(repo.Directory));
- Commit headCommit = repo.Head.CurrentCommit;
- Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headCommit.Hash);
- }
-
- string toPath = Path.Combine(trash.FullName, "to.git");
-
- using (var repo = Git.Clone(repositoryPath.FullName, toPath))
- {
- Assert.IsTrue(Repository.IsValid(repo.Directory));
- Commit headCommit = repo.Head.CurrentCommit;
- Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headCommit.Hash);
- }
- }
-
- [Test]
- [Ignore]
- public void Check_cloned_repo_http()
- {
- string toPath = Path.Combine(trash.FullName, "test");
- string fromUrl = "http://github.com/henon/TestGitRepository.git";
-
- using (Repository repo = Git.Clone(fromUrl, toPath))
- {
- Assert.IsTrue(Repository.IsValid(repo.Directory));
- //Verify content is in the proper location
- var readme = Path.Combine(repo.WorkingDirectory, "master.txt");
- Assert.IsTrue(new FileInfo(readme).Exists);
- }
- }
- }
+ [TestFixture]
+ public class CloneTests : RepositoryTestCase
+ {
+ [Test]
+ public void Check_cloned_bare_repo()
+ {
+ Assert.Ignore("This test has not been implemented yet.");
+ }
+
+ [Test]
+ public void Check_cloned_repo_git()
+ {
+ string toPath = Path.Combine(trash.FullName, "test");
+ string fromUrl = "git://github.com/henon/TestGitRepository.git";
+
+ using (Repository repo = Git.Clone(fromUrl, toPath))
+ {
+ var status = new RepositoryStatus(repo, new RepositoryStatusOptions { ForceContentCheck = false });
+ Assert.IsFalse(status.AnyDifferences);
+
+ status = new RepositoryStatus(repo, new RepositoryStatusOptions { ForceContentCheck = true });
+ Assert.IsFalse(status.AnyDifferences);
+
+ Assert.IsTrue(Repository.IsValid(repo.Directory));
+ //Verify content is in the proper location
+ var readme = Path.Combine(repo.WorkingDirectory, "master.txt");
+ Assert.IsTrue(new FileInfo(readme).Exists);
+ }
+ }
+
+ [Test]
+ public void Try_cloning_non_existing_repo_git()
+ {
+ string toPath = Path.Combine(trash.FullName, "test");
+ string fromUrl = "git://github.com/henon/nonExistingRepo.git";
+ AssertHelper.Throws<NoRemoteRepositoryException>(() => { using (Repository repo = Git.Clone(fromUrl, toPath)) { } }, "Repository shouldn't exist.");
+ }
+
+ [Test]
+ [Ignore("TransportLocal is not completely ported yet.")]
+ public void Checked_cloned_local_dotGit_suffixed_repo()
+ {
+ //setup of .git directory
+ var resource =
+ new DirectoryInfo(PathUtil.Combine(Path.Combine(Environment.CurrentDirectory, "Resources"),
+ "OneFileRepository"));
+ var tempRepository =
+ new DirectoryInfo(Path.Combine(trash.FullName, "OneFileRepository" + Path.GetRandomFileName() + Constants.DOT_GIT_EXT));
+ CopyDirectory(resource.FullName, tempRepository.FullName);
+
+ var repositoryPath = new DirectoryInfo(Path.Combine(tempRepository.FullName, Constants.DOT_GIT));
+ Directory.Move(repositoryPath.FullName + "ted", repositoryPath.FullName);
+
+
+ using (var repo = new Repository(repositoryPath.FullName))
+ {
+ Assert.IsTrue(Repository.IsValid(repo.Directory));
+ Commit headCommit = repo.Head.CurrentCommit;
+ Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headCommit.Hash);
+ }
+
+ string toPath = Path.Combine(trash.FullName, "to.git");
+
+ using (var repo = Git.Clone(repositoryPath.FullName, toPath))
+ {
+ Assert.IsTrue(Repository.IsValid(repo.Directory));
+ Commit headCommit = repo.Head.CurrentCommit;
+ Assert.AreEqual("f3ca78a01f1baa4eaddcc349c97dcab95a379981", headCommit.Hash);
+ }
+ }
+
+ [Test]
+ [Ignore]
+ public void Check_cloned_repo_http()
+ {
+ string toPath = Path.Combine(trash.FullName, "test");
+ string fromUrl = "http://github.com/henon/TestGitRepository.git";
+
+ using (Repository repo = Git.Clone(fromUrl, toPath))
+ {
+ Assert.IsTrue(Repository.IsValid(repo.Directory));
+ //Verify content is in the proper location
+ var readme = Path.Combine(repo.WorkingDirectory, "master.txt");
+ Assert.IsTrue(new FileInfo(readme).Exists);
+ }
+ }
+
+ [Test]
+ public void CloneWithPrivateKeyAuthentication()
+ {
+ string toPath = Path.Combine(trash.FullName, "test");
+ string fromUrl = "git@github.com:author/TestGitRepository.git";
+
+ var ssh_dir = Path.Combine(trash.FullName, ".ssh");
+ Directory.CreateDirectory(ssh_dir);
+ new FileInfo("Resources/ssh/id_rsa").CopyTo(Path.Combine(ssh_dir, "id_rsa"));
+ new FileInfo("Resources/ssh/known_hosts").CopyTo(Path.Combine(ssh_dir, "known_hosts"));
+
+ FS.UserHomeStrategy = () => new DirectoryInfo(trash.FullName);
+ try
+ {
+ using (var repo = Git.Clone(fromUrl, toPath))
+ {
+ var status = new RepositoryStatus(repo, new RepositoryStatusOptions { ForceContentCheck = false });
+ Assert.IsFalse(status.AnyDifferences);
+
+ status = new RepositoryStatus(repo, new RepositoryStatusOptions { ForceContentCheck = true });
+ Assert.IsFalse(status.AnyDifferences);
+
+ Assert.IsTrue(Repository.IsValid(repo.Directory));
+ //Verify content is in the proper location
+ var readme = Path.Combine(repo.WorkingDirectory, "master.txt");
+ Assert.IsTrue(new FileInfo(readme).Exists);
+ }
+ }
+ finally
+ {
+ FS.UserHomeStrategy = FS.StandardUserHomeStrategy;
+ }
+ }
+ }
}
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEoAIBAAKCAQEA501++mBahjw9uDBsNAOKw4jXOxFl14pQBgLDEL+fNf3eJm8F
+Figi2Q1dCiw0jXtBm2oUKNtc949HCbCDUy1fPZH3XecQeP3t7cDpTsVkdn746QYi
+8vfH/PGPbNHsOomS4WwsjQsbqpK06xohlK6EO/7EJiEon1eLPhw32b1gwvy6i5Yt
+/eDuUTcC2iV2Rb80IVvNi3OXWmg6y678P5zEjd/UVCSmDKyPWxrvcpVNGOBDFQsj
+GXYwIuXzcDTpg1lbUuRSN9bYRTYPTCl9gwuUGxaZbaipUsuS2V7LUJ/dWrJExMn3
+DJDVdC5FJdnix1BKnyoFkaN5iGlhfHMQYFWz8QIBIwKCAQAnpuKRUlipTCfWbrN2
+oYWAmx2VGOzjHwZnbjARf+9oV2fpVNxM8PAH86mMtx7zrrrKL3Erk1HECe7rt9v/
+oWDIue/k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+xhJccTbuOthIGCFj8xuoZy93Z0BMUC9kyhUcqGskPf7fsPUH
++QHHc8H9kXMkjar3tZCUJXQGtJbMRvEONDPfmZjg+P9rneK3
+-----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
+github.com,65.74.177.129 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==

0 comments on commit 23e8923

Please sign in to comment.