@@ -292,5 +292,46 @@ test('fromUrl(github url)', function (t) {
292
292
293
293
t . equal ( HostedGit . fromUrl ( 'git+ssh://github.com/foo.git' ) , undefined )
294
294
295
+ t . test ( 'HTTPS GitHub URL with embedded auth -- generally not a good idea' , function ( tt ) {
296
+ function verify ( host , label , branch ) {
297
+ var hostinfo = HostedGit . fromUrl ( host )
298
+ var hash = branch ? '#' + branch : ''
299
+ tt . ok ( hostinfo , label )
300
+ if ( ! hostinfo ) return
301
+ tt . is ( hostinfo . https ( ) , 'git+https://user:pass@github.com/111/222.git' + hash , label + ' -> https' )
302
+ tt . is ( hostinfo . git ( ) , 'git://user:pass@github.com/111/222.git' + hash , label + ' -> git' )
303
+ tt . is ( hostinfo . browse ( ) , 'https://github.com/111/222' + ( branch ? '/tree/' + branch : '' ) , label + ' -> browse' )
304
+ tt . is ( hostinfo . browse ( 'C' ) , 'https://github.com/111/222/tree/' + ( branch || 'master' ) + '/C' , label + ' -> browse(path)' )
305
+ tt . is ( hostinfo . browse ( 'C/D' ) , 'https://github.com/111/222/tree/' + ( branch || 'master' ) + '/C/D' , label + ' -> browse(path)' )
306
+ tt . is ( hostinfo . browse ( 'C' , 'A' ) , 'https://github.com/111/222/tree/' + ( branch || 'master' ) + '/C#a' , label + ' -> browse(path, fragment)' )
307
+ tt . is ( hostinfo . browse ( 'C/D' , 'A' ) , 'https://github.com/111/222/tree/' + ( branch || 'master' ) + '/C/D#a' , label + ' -> browse(path, fragment)' )
308
+ tt . is ( hostinfo . bugs ( ) , 'https://github.com/111/222/issues' , label + ' -> bugs' )
309
+ tt . is ( hostinfo . docs ( ) , 'https://github.com/111/222' + ( branch ? '/tree/' + branch : '' ) + '#readme' , label + ' -> docs' )
310
+ tt . is ( hostinfo . ssh ( ) , 'git@github.com:111/222.git' + hash , label + ' -> ssh' )
311
+ tt . is ( hostinfo . sshurl ( ) , 'git+ssh://git@github.com/111/222.git' + hash , label + ' -> sshurl' )
312
+ tt . is ( hostinfo . shortcut ( ) , 'github:111/222' + hash , label + ' -> shortcut' )
313
+ tt . is ( hostinfo . file ( 'C' ) , 'https://user:pass@raw.githubusercontent.com/111/222/' + ( branch || 'master' ) + '/C' , label + ' -> file' )
314
+ tt . is ( hostinfo . file ( 'C/D' ) , 'https://user:pass@raw.githubusercontent.com/111/222/' + ( branch || 'master' ) + '/C/D' , label + ' -> file' )
315
+ }
316
+
317
+ // insecure protocols
318
+ verify ( 'git://user:pass@github.com/111/222' , 'git' )
319
+ verify ( 'git://user:pass@github.com/111/222.git' , 'git.git' )
320
+ verify ( 'git://user:pass@github.com/111/222#branch' , 'git#branch' , 'branch' )
321
+ verify ( 'git://user:pass@github.com/111/222.git#branch' , 'git.git#branch' , 'branch' )
322
+
323
+ verify ( 'https://user:pass@github.com/111/222' , 'https' )
324
+ verify ( 'https://user:pass@github.com/111/222.git' , 'https.git' )
325
+ verify ( 'https://user:pass@github.com/111/222#branch' , 'https#branch' , 'branch' )
326
+ verify ( 'https://user:pass@github.com/111/222.git#branch' , 'https.git#branch' , 'branch' )
327
+
328
+ verify ( 'http://user:pass@github.com/111/222' , 'http' )
329
+ verify ( 'http://user:pass@github.com/111/222.git' , 'http.git' )
330
+ verify ( 'http://user:pass@github.com/111/222#branch' , 'http#branch' , 'branch' )
331
+ verify ( 'http://user:pass@github.com/111/222.git#branch' , 'http.git#branch' , 'branch' )
332
+
333
+ tt . end ( )
334
+ } )
335
+
295
336
t . end ( )
296
337
} )
0 commit comments