Skip to content

Commit 79caa3d

Browse files
authored
Merge pull request #1911 from libgit2/native-https
Use native HTTPS support again
2 parents 5055fbd + 29efc69 commit 79caa3d

File tree

5 files changed

+90
-505
lines changed

5 files changed

+90
-505
lines changed

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 80 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using LibGit2Sharp.Handlers;
66
using LibGit2Sharp.Tests.TestHelpers;
77
using Xunit;
8-
using Xunit.Extensions;
98

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

112111
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions
113-
{
114-
IsBare = true
115-
});
112+
{
113+
IsBare = true
114+
});
116115

117116
using (var repo = new Repository(clonedRepoPath))
118117
{
@@ -195,7 +194,7 @@ public void CanCloneWithCredentials()
195194
}
196195
}
197196

198-
static Credentials CreateUsernamePasswordCredentials (string user, string pass, bool secure)
197+
static Credentials CreateUsernamePasswordCredentials(string user, string pass, bool secure)
199198
{
200199
if (secure)
201200
{
@@ -222,7 +221,7 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
222221

223222
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath, new CloneOptions()
224223
{
225-
CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials (user, pass, secure)
224+
CredentialsProvider = (_url, _user, _cred) => CreateUsernamePasswordCredentials(user, pass, secure)
226225
});
227226

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

240-
//[SkippableTheory]
241-
//[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
242-
//[InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
243-
//public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
244-
//{
245-
// var scd = BuildSelfCleaningDirectory();
246-
247-
// InconclusiveIf(
248-
// () =>
249-
// certType == typeof (CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
250-
// "SSH not supported");
251-
252-
// bool wasCalled = false;
253-
// bool checksHappy = false;
254-
255-
// var options = new CloneOptions {
256-
// CertificateCheck = (cert, valid, host) => {
257-
// wasCalled = true;
258-
259-
// Assert.Equal(hostname, host);
260-
// Assert.Equal(certType, cert.GetType());
261-
262-
// if (certType == typeof(CertificateX509)) {
263-
// Assert.True(valid);
264-
// var x509 = ((CertificateX509)cert).Certificate;
265-
// // we get a string with the different fields instead of a structure, so...
266-
// Assert.Contains("CN=github.com,", x509.Subject);
267-
// checksHappy = true;
268-
// return false;
269-
// }
270-
271-
// if (certType == typeof(CertificateSsh)) {
272-
// var hostkey = (CertificateSsh)cert;
273-
// Assert.True(hostkey.HasMD5);
274-
// /*
275-
// * Once you've connected and thus your ssh has stored the hostkey,
276-
// * you can get the hostkey for a host with
277-
// *
278-
// * ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
279-
// *
280-
// * though GitHub's hostkey won't change anytime soon.
281-
// */
282-
// Assert.Equal("1627aca576282d36631b564debdfa648",
283-
// BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
284-
// checksHappy = true;
285-
// return false;
286-
// }
287-
288-
// return false;
289-
// },
290-
// };
291-
292-
// Assert.Throws<UserCancelledException>(() =>
293-
// Repository.Clone(url, scd.DirectoryPath, options)
294-
// );
295-
296-
// Assert.True(wasCalled);
297-
// Assert.True(checksHappy);
298-
//}
239+
[SkippableTheory]
240+
[InlineData("https://github.com/libgit2/TestGitRepository.git", "github.com", typeof(CertificateX509))]
241+
[InlineData("git@github.com:libgit2/TestGitRepository.git", "github.com", typeof(CertificateSsh))]
242+
public void CanInspectCertificateOnClone(string url, string hostname, Type certType)
243+
{
244+
var scd = BuildSelfCleaningDirectory();
245+
246+
InconclusiveIf(
247+
() =>
248+
certType == typeof(CertificateSsh) && !GlobalSettings.Version.Features.HasFlag(BuiltInFeatures.Ssh),
249+
"SSH not supported");
250+
251+
bool wasCalled = false;
252+
bool checksHappy = false;
253+
254+
var options = new CloneOptions
255+
{
256+
CertificateCheck = (cert, valid, host) =>
257+
{
258+
wasCalled = true;
259+
260+
Assert.Equal(hostname, host);
261+
Assert.Equal(certType, cert.GetType());
262+
263+
if (certType == typeof(CertificateX509))
264+
{
265+
Assert.True(valid);
266+
var x509 = ((CertificateX509)cert).Certificate;
267+
// we get a string with the different fields instead of a structure, so...
268+
Assert.Contains("CN=github.com,", x509.Subject);
269+
checksHappy = true;
270+
return false;
271+
}
272+
273+
if (certType == typeof(CertificateSsh))
274+
{
275+
var hostkey = (CertificateSsh)cert;
276+
Assert.True(hostkey.HasMD5);
277+
/*
278+
* Once you've connected and thus your ssh has stored the hostkey,
279+
* you can get the hostkey for a host with
280+
*
281+
* ssh-keygen -F github.com -l | tail -n 1 | cut -d ' ' -f 2 | tr -d ':'
282+
*
283+
* though GitHub's hostkey won't change anytime soon.
284+
*/
285+
Assert.Equal("1627aca576282d36631b564debdfa648",
286+
BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
287+
checksHappy = true;
288+
return false;
289+
}
290+
291+
return false;
292+
},
293+
};
294+
295+
Assert.Throws<UserCancelledException>(() =>
296+
Repository.Clone(url, scd.DirectoryPath, options)
297+
);
298+
299+
Assert.True(wasCalled);
300+
Assert.True(checksHappy);
301+
}
299302

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

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

453456
Dictionary<string, CloneCallbackInfo> expectedCallbackInfo = new Dictionary<string, CloneCallbackInfo>();
454457
expectedCallbackInfo.Add(workDirPath, new CloneCallbackInfo()
455-
{
456-
RecursionDepth = 0,
457-
RemoteUrl = uri.AbsolutePath,
458-
StartingWorkInRepositoryCalled = true,
459-
FinishedWorkInRepositoryCalled = true,
460-
CheckoutProgressCalled = true,
461-
RemoteRefUpdateCalled = true,
462-
});
458+
{
459+
RecursionDepth = 0,
460+
RemoteUrl = uri.AbsolutePath,
461+
StartingWorkInRepositoryCalled = true,
462+
FinishedWorkInRepositoryCalled = true,
463+
CheckoutProgressCalled = true,
464+
RemoteRefUpdateCalled = true,
465+
});
463466

464467
expectedCallbackInfo.Add(Path.Combine(workDirPath, relativeSubmodulePath), new CloneCallbackInfo()
465468
{
@@ -486,7 +489,7 @@ public void CanRecursivelyCloneSubmodules()
486489
}
487490

488491
// Verify the state of the submodule
489-
using(Repository repo = new Repository(clonedRepoPath))
492+
using (Repository repo = new Repository(clonedRepoPath))
490493
{
491494
var sm = repo.Submodules[relativeSubmodulePath];
492495
Assert.True(sm.RetrieveStatus().HasFlag(SubmoduleStatus.InWorkDir |
@@ -533,15 +536,15 @@ public void CanCancelRecursiveClone()
533536
{
534537
Repository.Clone(uri.AbsolutePath, scd.DirectoryPath, options);
535538
}
536-
catch(RecurseSubmodulesException ex)
539+
catch (RecurseSubmodulesException ex)
537540
{
538541
Assert.NotNull(ex.InnerException);
539542
Assert.Equal(typeof(UserCancelledException), ex.InnerException.GetType());
540543
clonedRepoPath = ex.InitialRepositoryPath;
541544
}
542545

543546
// Verify that the submodule was not initialized.
544-
using(Repository repo = new Repository(clonedRepoPath))
547+
using (Repository repo = new Repository(clonedRepoPath))
545548
{
546549
var submoduleStatus = repo.Submodules[relativeSubmodulePath].RetrieveStatus();
547550
Assert.Equal(SubmoduleStatus.InConfig | SubmoduleStatus.InHead | SubmoduleStatus.InIndex | SubmoduleStatus.WorkDirUninitialized,

LibGit2Sharp.Tests/GlobalSettingsFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void CanGetMinimumCompiledInFeatures()
1515
BuiltInFeatures features = GlobalSettings.Version.Features;
1616

1717
Assert.True(features.HasFlag(BuiltInFeatures.Threads));
18+
Assert.True(features.HasFlag(BuiltInFeatures.Https));
1819
}
1920

2021
[Fact]

0 commit comments

Comments
 (0)