Skip to content

Commit

Permalink
Merge pull request #1618 from libgit2/ethomson/notls
Browse files Browse the repository at this point in the history
WIP: Use managed HTTP stack
  • Loading branch information
bording authored Nov 23, 2020
2 parents dbb17e7 + fd8e277 commit 3d72762
Show file tree
Hide file tree
Showing 32 changed files with 954 additions and 336 deletions.
118 changes: 59 additions & 59 deletions LibGit2Sharp.Tests/CloneFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,65 +237,65 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
}
}

[SkippableTheory]
[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
[InlineData("[email protected]: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("[email protected]: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
98 changes: 50 additions & 48 deletions LibGit2Sharp.Tests/FileHistoryFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,56 @@ namespace LibGit2Sharp.Tests
{
public class FileHistoryFixture : BaseFixture
{
[Theory]
[InlineData("https://github.com/nulltoken/follow-test.git")]
public void CanDealWithFollowTest(string url)
{
var scd = BuildSelfCleaningDirectory();
var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

using (var repo = new Repository(clonedRepoPath))
{
// $ git log --follow --format=oneline so-renamed.txt
// 88f91835062161febb46fb270ef4188f54c09767 Update not-yet-renamed.txt AND rename into so-renamed.txt
// ef7cb6a63e32595fffb092cb1ae9a32310e58850 Add not-yet-renamed.txt
var fileHistoryEntries = repo.Commits.QueryBy("so-renamed.txt").ToList();
Assert.Equal(2, fileHistoryEntries.Count());
Assert.Equal("88f91835062161febb46fb270ef4188f54c09767", fileHistoryEntries[0].Commit.Sha);
Assert.Equal("ef7cb6a63e32595fffb092cb1ae9a32310e58850", fileHistoryEntries[1].Commit.Sha);

// $ git log --follow --format=oneline untouched.txt
// c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
fileHistoryEntries = repo.Commits.QueryBy("untouched.txt").ToList();
Assert.Single(fileHistoryEntries);
Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[0].Commit.Sha);

// $ git log --follow --format=oneline under-test.txt
// 0b5b18f2feb917dee98df1210315b2b2b23c5bec Rename file renamed.txt into under-test.txt
// 49921d463420a892c9547a326632ef6a9ba3b225 Update file renamed.txt
// 70f636e8c64bbc2dfef3735a562bb7e195d8019f Rename file under-test.txt into renamed.txt
// d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d Updated file under test
// 9da10ef7e139c49604a12caa866aae141f38b861 Updated file under test
// 599a5d821fb2c0a25855b4233e26d475c2fbeb34 Updated file under test
// 678b086b44753000567aa64344aa0d8034fa0083 Updated file under test
// 8f7d9520f306771340a7c79faea019ad18e4fa1f Updated file under test
// bd5f8ee279924d33be8ccbde82e7f10b9d9ff237 Updated file under test
// c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
fileHistoryEntries = repo.Commits.QueryBy("under-test.txt").ToList();
Assert.Equal(10, fileHistoryEntries.Count());
Assert.Equal("0b5b18f2feb917dee98df1210315b2b2b23c5bec", fileHistoryEntries[0].Commit.Sha);
Assert.Equal("49921d463420a892c9547a326632ef6a9ba3b225", fileHistoryEntries[1].Commit.Sha);
Assert.Equal("70f636e8c64bbc2dfef3735a562bb7e195d8019f", fileHistoryEntries[2].Commit.Sha);
Assert.Equal("d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d", fileHistoryEntries[3].Commit.Sha);
Assert.Equal("9da10ef7e139c49604a12caa866aae141f38b861", fileHistoryEntries[4].Commit.Sha);
Assert.Equal("599a5d821fb2c0a25855b4233e26d475c2fbeb34", fileHistoryEntries[5].Commit.Sha);
Assert.Equal("678b086b44753000567aa64344aa0d8034fa0083", fileHistoryEntries[6].Commit.Sha);
Assert.Equal("8f7d9520f306771340a7c79faea019ad18e4fa1f", fileHistoryEntries[7].Commit.Sha);
Assert.Equal("bd5f8ee279924d33be8ccbde82e7f10b9d9ff237", fileHistoryEntries[8].Commit.Sha);
Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[9].Commit.Sha);
}
}
//Looks like nulltoken deleted the repo this test was using

//[Theory]
//[InlineData("https://github.com/nulltoken/follow-test.git")]
//public void CanDealWithFollowTest(string url)
//{
// var scd = BuildSelfCleaningDirectory();
// var clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);

// using (var repo = new Repository(clonedRepoPath))
// {
// // $ git log --follow --format=oneline so-renamed.txt
// // 88f91835062161febb46fb270ef4188f54c09767 Update not-yet-renamed.txt AND rename into so-renamed.txt
// // ef7cb6a63e32595fffb092cb1ae9a32310e58850 Add not-yet-renamed.txt
// var fileHistoryEntries = repo.Commits.QueryBy("so-renamed.txt").ToList();
// Assert.Equal(2, fileHistoryEntries.Count());
// Assert.Equal("88f91835062161febb46fb270ef4188f54c09767", fileHistoryEntries[0].Commit.Sha);
// Assert.Equal("ef7cb6a63e32595fffb092cb1ae9a32310e58850", fileHistoryEntries[1].Commit.Sha);

// // $ git log --follow --format=oneline untouched.txt
// // c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
// fileHistoryEntries = repo.Commits.QueryBy("untouched.txt").ToList();
// Assert.Single(fileHistoryEntries);
// Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[0].Commit.Sha);

// // $ git log --follow --format=oneline under-test.txt
// // 0b5b18f2feb917dee98df1210315b2b2b23c5bec Rename file renamed.txt into under-test.txt
// // 49921d463420a892c9547a326632ef6a9ba3b225 Update file renamed.txt
// // 70f636e8c64bbc2dfef3735a562bb7e195d8019f Rename file under-test.txt into renamed.txt
// // d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d Updated file under test
// // 9da10ef7e139c49604a12caa866aae141f38b861 Updated file under test
// // 599a5d821fb2c0a25855b4233e26d475c2fbeb34 Updated file under test
// // 678b086b44753000567aa64344aa0d8034fa0083 Updated file under test
// // 8f7d9520f306771340a7c79faea019ad18e4fa1f Updated file under test
// // bd5f8ee279924d33be8ccbde82e7f10b9d9ff237 Updated file under test
// // c10c1d5f74b76f20386d18674bf63fbee6995061 Initial commit
// fileHistoryEntries = repo.Commits.QueryBy("under-test.txt").ToList();
// Assert.Equal(10, fileHistoryEntries.Count());
// Assert.Equal("0b5b18f2feb917dee98df1210315b2b2b23c5bec", fileHistoryEntries[0].Commit.Sha);
// Assert.Equal("49921d463420a892c9547a326632ef6a9ba3b225", fileHistoryEntries[1].Commit.Sha);
// Assert.Equal("70f636e8c64bbc2dfef3735a562bb7e195d8019f", fileHistoryEntries[2].Commit.Sha);
// Assert.Equal("d3868d57a6aaf2ae6ed4887d805ae4bc91d8ce4d", fileHistoryEntries[3].Commit.Sha);
// Assert.Equal("9da10ef7e139c49604a12caa866aae141f38b861", fileHistoryEntries[4].Commit.Sha);
// Assert.Equal("599a5d821fb2c0a25855b4233e26d475c2fbeb34", fileHistoryEntries[5].Commit.Sha);
// Assert.Equal("678b086b44753000567aa64344aa0d8034fa0083", fileHistoryEntries[6].Commit.Sha);
// Assert.Equal("8f7d9520f306771340a7c79faea019ad18e4fa1f", fileHistoryEntries[7].Commit.Sha);
// Assert.Equal("bd5f8ee279924d33be8ccbde82e7f10b9d9ff237", fileHistoryEntries[8].Commit.Sha);
// Assert.Equal("c10c1d5f74b76f20386d18674bf63fbee6995061", fileHistoryEntries[9].Commit.Sha);
// }
//}

[Theory]
[InlineData(null)]
Expand Down
1 change: 0 additions & 1 deletion LibGit2Sharp.Tests/GlobalSettingsFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public void CanGetMinimumCompiledInFeatures()
BuiltInFeatures features = GlobalSettings.Version.Features;

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

[Fact]
Expand Down
8 changes: 4 additions & 4 deletions LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netcoreapp2.1</TargetFrameworks>
<TargetFrameworks>net472;netcoreapp2.1</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LibGit2Sharp\LibGit2Sharp.csproj" />
<ProjectReference Include="..\NativeLibraryLoadTestApp\x86\NativeLibraryLoadTestApp.x86.csproj" Condition="'$(TargetFramework)' == 'net46'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
<ProjectReference Include="..\NativeLibraryLoadTestApp\x64\NativeLibraryLoadTestApp.x64.csproj" Condition="'$(TargetFramework)' == 'net46'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
<ProjectReference Include="..\NativeLibraryLoadTestApp\x86\NativeLibraryLoadTestApp.x86.csproj" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
<ProjectReference Include="..\NativeLibraryLoadTestApp\x64\NativeLibraryLoadTestApp.x64.csproj" Condition="'$(TargetFramework)' != 'netcoreapp2.1'" ReferenceOutputAssembly="false" OutputItemType="TestAppExe" />
</ItemGroup>

<ItemGroup>
Expand All @@ -23,7 +23,7 @@

<ItemGroup>
<Compile Include="..\LibGit2Sharp\Core\Platform.cs" Link="TestHelpers\Platform.cs" />
<Compile Remove="desktop\**" Condition="'$(TargetFramework)' != 'net46'" />
<Compile Remove="desktop\**" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<Content Include="Resources\**\*.*" CopyToOutputDirectory="PreserveNewest" />
<None Update="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
Expand Down
11 changes: 10 additions & 1 deletion LibGit2Sharp/AmbiguousSpecificationException.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using LibGit2Sharp.Core;
using System;
using System.Runtime.Serialization;

Expand All @@ -7,7 +8,7 @@ namespace LibGit2Sharp
/// The exception that is thrown when the provided specification cannot uniquely identify a reference, an object or a path.
/// </summary>
[Serializable]
public class AmbiguousSpecificationException : LibGit2SharpException
public class AmbiguousSpecificationException : NativeException
{
/// <summary>
/// Initializes a new instance of the <see cref="AmbiguousSpecificationException"/> class.
Expand Down Expand Up @@ -50,5 +51,13 @@ public AmbiguousSpecificationException(string message, Exception innerException)
protected AmbiguousSpecificationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }

internal override GitErrorCode ErrorCode
{
get
{
return GitErrorCode.Ambiguous;
}
}
}
}
14 changes: 11 additions & 3 deletions LibGit2Sharp/BareRepositoryException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LibGit2Sharp
/// working directory is performed against a bare repository.
/// </summary>
[Serializable]
public class BareRepositoryException : LibGit2SharpException
public class BareRepositoryException : NativeException
{
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.BareRepositoryException"/> class.
Expand Down Expand Up @@ -52,8 +52,16 @@ protected BareRepositoryException(SerializationInfo info, StreamingContext conte
: base(info, context)
{ }

internal BareRepositoryException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
internal BareRepositoryException(string message, GitErrorCategory category)
: base(message, category)
{ }

internal override GitErrorCode ErrorCode
{
get
{
return GitErrorCode.BareRepo;
}
}
}
}
6 changes: 5 additions & 1 deletion LibGit2Sharp/CertificateX509.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace LibGit2Sharp
/// </summary>
public class CertificateX509 : Certificate
{

/// <summary>
/// For mocking purposes
/// </summary>
Expand All @@ -30,6 +29,11 @@ internal unsafe CertificateX509(git_certificate_x509* cert)
Certificate = new X509Certificate(data);
}

internal CertificateX509(X509Certificate cert)
{
Certificate = cert;
}

internal unsafe IntPtr ToPointers(out IntPtr dataPtr)
{
var certData = Certificate.Export(X509ContentType.Cert);
Expand Down
14 changes: 11 additions & 3 deletions LibGit2Sharp/CheckoutConflictException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace LibGit2Sharp
/// in the working directory.
/// </summary>
[Serializable]
public class CheckoutConflictException : LibGit2SharpException
public class CheckoutConflictException : NativeException
{
/// <summary>
/// Initializes a new instance of the <see cref="LibGit2Sharp.CheckoutConflictException"/> class.
Expand Down Expand Up @@ -53,8 +53,16 @@ protected CheckoutConflictException(SerializationInfo info, StreamingContext con
: base(info, context)
{ }

internal CheckoutConflictException(string message, GitErrorCode code, GitErrorCategory category)
: base(message, code, category)
internal CheckoutConflictException(string message, GitErrorCategory category)
: base(message, category)
{ }

internal override GitErrorCode ErrorCode
{
get
{
return GitErrorCode.Conflict;
}
}
}
}
Loading

0 comments on commit 3d72762

Please sign in to comment.