Skip to content
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

Use managed HTTP stack #1618

Merged
merged 44 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f9bded4
Use custom HTTPS transport
ethomson Oct 7, 2018
dc22039
Exceptions: refactor native exceptions to include code
ethomson Oct 14, 2018
4381f70
ManagedHttpSmartSubtransport: provide certificate callbacks
ethomson Oct 14, 2018
15d68e5
Managed HTTP transport: support user-agent
ethomson Oct 14, 2018
9d7dd69
Managed HTTP transport: allow custom transport
ethomson Nov 2, 2018
5a64349
smart subtransports: improve safety
ethomson Nov 6, 2018
7be9794
Tests: Don't look for HTTPS in libgit2
ethomson Nov 10, 2018
70b393b
Use the .NET standard HTTP class
ethomson Nov 10, 2018
04094f5
SSL validation: cope with GIT_PASSTHROUGH
ethomson Oct 16, 2019
4a459f1
HTTP: complete only when actually complete
ethomson Oct 16, 2019
814054b
dispose the response
ethomson Jan 7, 2020
efdb363
Fixed build warnings about System.Net.Http version issues
AArnott Jan 30, 2020
f6f3cb6
Throw more precise exceptions when they happen
AArnott Jan 30, 2020
ae1563d
Improve xml doc comments for extensibility point API
AArnott Jan 30, 2020
a46fb80
Increase the size of the very small read buffer
AArnott Jan 30, 2020
e034243
fixup doc comments
ethomson Feb 18, 2020
8d83f06
Update LibGit2Sharp/Core/ManagedHttpSmartSubtransport.cs
bording Apr 3, 2020
0950390
Suppress Expect: 100 Continue header
AArnott Apr 3, 2020
b388b05
Merge pull request #1772 from AArnott/no100Continue
bording Apr 3, 2020
f5abbba
Update SDK version
bording Apr 5, 2020
27a034d
Only use managed https with new net472 target
bording Apr 5, 2020
a0374ba
Don't dispose HttpClientHandler separately
bording Apr 5, 2020
c3ac103
Minor cleanup
bording Apr 5, 2020
807012a
Add net472 test runs
bording Apr 5, 2020
32af8db
Fix LoadFromSpecifiedPath test on net472
bording Apr 5, 2020
9daf4cc
Update to binaries package that doesn't use OpenSSL on linux
bording Apr 5, 2020
80ea092
Fix when Register is called before NativeMethod cctor
bording Apr 7, 2020
35bca83
Fix XML comment
bording Apr 7, 2020
d2db2ac
Cleanup
bording Apr 7, 2020
9ee00e4
Make managed http opt-in on non-Linux OSes
bording Apr 7, 2020
a5ef816
Managed subtransport: support Default Credentials
ethomson May 10, 2020
7ca3791
Move to only netstandard2.0 target
bording May 30, 2020
86be042
Change to an opt-out model for the managed implementation
bording May 30, 2020
0bea3cf
WIP Try using CredentialCache
bording May 30, 2020
2c763f7
Make test pass, can't do this for real though
bording May 30, 2020
9b6043f
Nevermind, can't change handler properties after it's been used
bording May 30, 2020
868eb38
Always use managed https transport
bording Nov 7, 2020
a514c5f
Remove certificate validation check
bording Nov 7, 2020
665eb5f
Add lock to credential cache modifications
bording Nov 7, 2020
2c90f41
Add netcoreapp2.1 target
bording Nov 7, 2020
d4a6cd4
Remove unneeded reference
bording Nov 7, 2020
4a9af01
Use SocketsHttpHandler on .NET Core
bording Nov 7, 2020
2fae75f
Comment out test using deleted repo
bording Nov 7, 2020
fd8e277
Comment out certificate check test
bording Nov 7, 2020
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
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("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
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