5
5
using LibGit2Sharp . Handlers ;
6
6
using LibGit2Sharp . Tests . TestHelpers ;
7
7
using Xunit ;
8
- using Xunit . Extensions ;
9
8
10
9
namespace LibGit2Sharp . Tests
11
10
{
@@ -110,9 +109,9 @@ public void CanCloneBarely(string url)
110
109
var scd = BuildSelfCleaningDirectory ( ) ;
111
110
112
111
string clonedRepoPath = Repository . Clone ( url , scd . DirectoryPath , new CloneOptions
113
- {
114
- IsBare = true
115
- } ) ;
112
+ {
113
+ IsBare = true
114
+ } ) ;
116
115
117
116
using ( var repo = new Repository ( clonedRepoPath ) )
118
117
{
@@ -195,7 +194,7 @@ public void CanCloneWithCredentials()
195
194
}
196
195
}
197
196
198
- static Credentials CreateUsernamePasswordCredentials ( string user , string pass , bool secure )
197
+ static Credentials CreateUsernamePasswordCredentials ( string user , string pass , bool secure )
199
198
{
200
199
if ( secure )
201
200
{
@@ -222,7 +221,7 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
222
221
223
222
string clonedRepoPath = Repository . Clone ( url , scd . DirectoryPath , new CloneOptions ( )
224
223
{
225
- CredentialsProvider = ( _url , _user , _cred ) => CreateUsernamePasswordCredentials ( user , pass , secure )
224
+ CredentialsProvider = ( _url , _user , _cred ) => CreateUsernamePasswordCredentials ( user , pass , secure )
226
225
} ) ;
227
226
228
227
using ( var repo = new Repository ( clonedRepoPath ) )
@@ -237,65 +236,69 @@ public void CanCloneFromBBWithCredentials(string url, string user, string pass,
237
236
}
238
237
}
239
238
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
+ }
299
302
300
303
[ Theory ]
301
304
[ InlineData ( "git://github.com/libgit2/TestGitRepository" ) ]
@@ -441,7 +444,7 @@ public void CanRecursivelyCloneSubmodules()
441
444
string clonedRepoPath = Repository . Clone ( uri . AbsolutePath , scd . DirectoryPath , options ) ;
442
445
string workDirPath ;
443
446
444
- using ( Repository repo = new Repository ( clonedRepoPath ) )
447
+ using ( Repository repo = new Repository ( clonedRepoPath ) )
445
448
{
446
449
workDirPath = repo . Info . WorkingDirectory . TrimEnd ( new char [ ] { Path . DirectorySeparatorChar , Path . AltDirectorySeparatorChar } ) ;
447
450
}
@@ -452,14 +455,14 @@ public void CanRecursivelyCloneSubmodules()
452
455
453
456
Dictionary < string , CloneCallbackInfo > expectedCallbackInfo = new Dictionary < string , CloneCallbackInfo > ( ) ;
454
457
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
+ } ) ;
463
466
464
467
expectedCallbackInfo . Add ( Path . Combine ( workDirPath , relativeSubmodulePath ) , new CloneCallbackInfo ( )
465
468
{
@@ -486,7 +489,7 @@ public void CanRecursivelyCloneSubmodules()
486
489
}
487
490
488
491
// Verify the state of the submodule
489
- using ( Repository repo = new Repository ( clonedRepoPath ) )
492
+ using ( Repository repo = new Repository ( clonedRepoPath ) )
490
493
{
491
494
var sm = repo . Submodules [ relativeSubmodulePath ] ;
492
495
Assert . True ( sm . RetrieveStatus ( ) . HasFlag ( SubmoduleStatus . InWorkDir |
@@ -533,15 +536,15 @@ public void CanCancelRecursiveClone()
533
536
{
534
537
Repository . Clone ( uri . AbsolutePath , scd . DirectoryPath , options ) ;
535
538
}
536
- catch ( RecurseSubmodulesException ex )
539
+ catch ( RecurseSubmodulesException ex )
537
540
{
538
541
Assert . NotNull ( ex . InnerException ) ;
539
542
Assert . Equal ( typeof ( UserCancelledException ) , ex . InnerException . GetType ( ) ) ;
540
543
clonedRepoPath = ex . InitialRepositoryPath ;
541
544
}
542
545
543
546
// Verify that the submodule was not initialized.
544
- using ( Repository repo = new Repository ( clonedRepoPath ) )
547
+ using ( Repository repo = new Repository ( clonedRepoPath ) )
545
548
{
546
549
var submoduleStatus = repo . Submodules [ relativeSubmodulePath ] . RetrieveStatus ( ) ;
547
550
Assert . Equal ( SubmoduleStatus . InConfig | SubmoduleStatus . InHead | SubmoduleStatus . InIndex | SubmoduleStatus . WorkDirUninitialized ,
0 commit comments