Skip to content

Commit 3947e7d

Browse files
committed
fixup! fixup! fixup! fixup! Allow the caller to inspect the host's certificate
1 parent a17a946 commit 3947e7d

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

LibGit2Sharp.Tests/CloneFixture.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,28 +250,25 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
250250
"SSH not supported");
251251

252252
bool wasCalled = false;
253+
bool checksHappy = false;
253254

254-
255-
Repository.Clone(url, scd.DirectoryPath, new CloneOptions
256-
{
257-
CertificateCheck = (cert, valid, host) =>
258-
{
255+
var options = new CloneOptions {
256+
CertificateCheck = (cert, valid, host) => {
259257
wasCalled = true;
260258

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

264-
if (certType == typeof(CertificateX509))
265-
{
262+
if (certType == typeof(CertificateX509)) {
266263
Assert.True(valid);
267264
var x509 = ((CertificateX509)cert).Certificate;
268265
// we get a string with the different fields instead of a structure, so...
269266
Assert.True(x509.Subject.Contains("CN=github.com,"));
270-
return true;
267+
checksHappy = true;
268+
return false;
271269
}
272270

273-
if (certType == typeof(CertificateSsh))
274-
{
271+
if (certType == typeof(CertificateSsh)) {
275272
var hostkey = (CertificateSsh)cert;
276273
Assert.True(hostkey.HasMD5);
277274
/*
@@ -283,15 +280,21 @@ public void CanInspectCertificateOnClone(string url, string hostname, Type certT
283280
* though GitHub's hostkey won't change anytime soon.
284281
*/
285282
Assert.Equal("1627aca576282d36631b564debdfa648",
286-
BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
287-
return true;
283+
BitConverter.ToString(hostkey.HashMD5).ToLower().Replace("-", ""));
284+
checksHappy = true;
285+
return false;
288286
}
289287

290288
return false;
291289
},
292-
});
290+
};
291+
292+
Assert.Throws<UserCancelledException>(() =>
293+
Repository.Clone(url, scd.DirectoryPath, options)
294+
);
293295

294296
Assert.True(wasCalled);
297+
Assert.True(checksHappy);
295298
}
296299

297300
[Fact]

0 commit comments

Comments
 (0)