Skip to content

Use native HTTPS support again #1911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 80 additions & 77 deletions LibGit2Sharp.Tests/CloneFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using LibGit2Sharp.Handlers;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using Xunit.Extensions;

namespace LibGit2Sharp.Tests
{
Expand Down Expand Up @@ -110,9 +109,9 @@ public void CanCloneBarely(string url)
var scd = BuildSelfCleaningDirectory();

string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
{
IsBare = true
});
{
IsBare = true
});

using (var repo = new Repository(clonedRepoPath))
{
Expand Down Expand Up @@ -195,7 +194,7 @@ public void CanCloneWithCredentials()
}
}

static Credentials CreateUsernamePasswordCredentials (string user, string pass, bool secure)
static Credentials CreateUsernamePasswordCredentials(string user, string pass, bool secure)
{
if (secure)
{
Expand All @@ -222,7 +221,7 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,

string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
{
CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials (user, pass, secure)
CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials(user, pass, secure)
});

using (var repo = new Repository(clonedRepoPath))
Expand All @@ -237,65 +236,69 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
}
}

//[SkippableTheory]
//[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
//[InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
//public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
//{
// var scd = BuildSelfCleaningDirectory();

// InconclusiveIf(
// () =>
// certType == typeof (CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
// "SSH not supported");

// bool wasCalled = false;
// bool checksHappy = false;

// var options = new CloneOptions {
// CertificateCheck = (cert, valid, host) => {
// wasCalled = true;

// Assert.Equal(hostname, host);
// Assert.Equal(certType, cert.GetType());

// if (certType == typeof(CertificateX509)) {
// Assert.True(valid);
// var x509 = ((CertificateX509)cert).Certificate;
// // we get a string with the different fields instead of a structure, so...
// Assert.Contains("CN=github.com,", x509.Subject);
// checksHappy = true;
// return false;
// }

// if (certType == typeof(CertificateSsh)) {
// var hostkey = (CertificateSsh)cert;
// Assert.True(hostkey.HasMD5);
// /*
// * Once you've connected and thus your ssh has stored the hostkey,
// * you can get the hostkey for a host with
// *
// * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
// *
// * though GitHub's hostkey won't change anytime soon.
// */
// Assert.Equal("1627aca576282d36631b564debdfa648",
// BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
// checksHappy = true;
// return false;
// }

// return false;
// },
// };

// Assert.Throws<UserCancelledException>(() =>
// Repository.Clone(url, scd.DirectoryPath, options)
// );

// Assert.True(wasCalled);
// Assert.True(checksHappy);
//}
[SkippableTheory]
[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
[InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
{
var scd = BuildSelfCleaningDirectory();

InconclusiveIf(
() =>
certType == typeof(CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
"SSH not supported");

bool wasCalled = false;
bool checksHappy = false;

var options = new CloneOptions
{
CertificateCheck = (cert, valid, host) =>
{
wasCalled = true;

Assert.Equal(hostname, host);
Assert.Equal(certType, cert.GetType());

if (certType == typeof(CertificateX509))
{
Assert.True(valid);
var x509 = ((CertificateX509)cert).Certificate;
// we get a string with the different fields instead of a structure, so...
Assert.Contains("CN=github.com,", x509.Subject);
checksHappy = true;
return false;
}

if (certType == typeof(CertificateSsh))
{
var hostkey = (CertificateSsh)cert;
Assert.True(hostkey.HasMD5);
/*
* Once you've connected and thus your ssh has stored the hostkey,
* you can get the hostkey for a host with
*
* ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
*
* though GitHub's hostkey won't change anytime soon.
*/
Assert.Equal("1627aca576282d36631b564debdfa648",
BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
checksHappy = true;
return false;
}

return false;
},
};

Assert.Throws<UserCancelledException>(() =>
Repository.Clone(url, scd.DirectoryPath, options)
);

Assert.True(wasCalled);
Assert.True(checksHappy);
}

[Theory]
[InlineData("git://github.com/libgit2/TestGitRepository")]
Expand Down Expand Up @@ -441,7 +444,7 @@ public void CanRecursivelyCloneSubmodules()
string clonedRepoPath = Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
string workDirPath;

using(Repository repo = new Repository(clonedRepoPath))
using (Repository repo = new Repository(clonedRepoPath))
{
workDirPath = repo.Info.WorkingDirectory.TrimEnd(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
}
Expand All @@ -452,14 +455,14 @@ public void CanRecursivelyCloneSubmodules()

Dictionary<string, CloneCallbackInfo> expectedCallbackInfo = new Dictionary<string, CloneCallbackInfo>();
expectedCallbackInfo.Add(workDirPath, new CloneCallbackInfo()
{
RecursionDepth = 0,
RemoteUrl = uri.AbsolutePath,
StartingWorkInRepositoryCalled = true,
FinishedWorkInRepositoryCalled = true,
CheckoutProgressCalled = true,
RemoteRefUpdateCalled = true,
});
{
RecursionDepth = 0,
RemoteUrl = uri.AbsolutePath,
StartingWorkInRepositoryCalled = true,
FinishedWorkInRepositoryCalled = true,
CheckoutProgressCalled = true,
RemoteRefUpdateCalled = true,
});

expectedCallbackInfo.Add(Path.Combine(workDirPath, relativeSubmodulePath), new CloneCallbackInfo()
{
Expand All @@ -486,7 +489,7 @@ public void CanRecursivelyCloneSubmodules()
}

// Verify the state of the submodule
using(Repository repo = new Repository(clonedRepoPath))
using (Repository repo = new Repository(clonedRepoPath))
{
var sm = repo.Submodules[relativeSubmodulePath];
Assert.True(sm.RetrieveStatus().HasFlag(SubmoduleStatus.InWorkDir |
Expand Down Expand Up @@ -533,15 +536,15 @@ public void CanCancelRecursiveClone()
{
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
}
catch(RecurseSubmodulesException ex)
catch (RecurseSubmodulesException ex)
{
Assert.NotNull(ex.InnerException);
Assert.Equal(typeof(UserCancelledException), ex.InnerException.GetType());
clonedRepoPath = ex.InitialRepositoryPath;
}

// Verify that the submodule was not initialized.
using(Repository repo = new Repository(clonedRepoPath))
using (Repository repo = new Repository(clonedRepoPath))
{
var submoduleStatus = repo.Submodules[relativeSubmodulePath].RetrieveStatus();
Assert.Equal(SubmoduleStatus.InConfig | SubmoduleStatus.InHead | SubmoduleStatus.InIndex | SubmoduleStatus.WorkDirUninitialized,
Expand Down
1 change: 1 addition & 0 deletions LibGit2Sharp.Tests/GlobalSettingsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public void CanGetMinimumCompiledInFeatures()
BuiltInFeatures features = GlobalSettings.Version.Features;

Assert.True(features.HasFlag(BuiltInFeatures.Threads));
Assert.True(features.HasFlag(BuiltInFeatures.Https));
}

[Fact]
Expand Down
Loading