@@ -122,7 +122,7 @@ public async Task GetCommand_ExecuteAsync_NegotiatedCapability_EchoesIntersectio
122122 string actualOutput = context . Streams . Out . ToString ( ) . Replace ( "\r \n " , "\n " ) ;
123123
124124 Assert . Contains ( "capability[]=state\n " , actualOutput ) ;
125- Assert . DoesNotContain ( "capability[]=authtype" , actualOutput ) ;
125+ Assert . Contains ( "capability[]=authtype\n " , actualOutput ) ;
126126 }
127127
128128 [ Fact ]
@@ -328,6 +328,62 @@ public async Task GetCommand_ExecuteAsync_OutputOrdering_CapabilitiesFirstThenSc
328328 "state[] must follow continue=1" ) ;
329329 }
330330
331+ [ Fact ]
332+ public async Task GetCommand_ExecuteAsync_CapabilityAuthType_MissingRevertsToPlainPassword ( )
333+ {
334+ ICredential testCredential = new GitCredential ( "alice" , "hunter2" ) ;
335+ var response = GitResponse . Ok ( testCredential , isEphemeral : true , authtype : "token" ) ;
336+
337+ var stdin = "protocol=https\n host=example.com\n \n " ;
338+
339+ var providerMock = new Mock < IHostProvider > ( ) ;
340+ providerMock . Setup ( x => x . GetCredentialAsync ( It . IsAny < GitRequest > ( ) ) )
341+ . ReturnsAsync ( response ) ;
342+ var providerRegistry = new TestHostProviderRegistry { Provider = providerMock . Object } ;
343+ var context = new TestCommandContext { Streams = { In = stdin } } ;
344+
345+ var command = new GetCommand ( context , providerRegistry ) ;
346+
347+ await command . ExecuteAsync ( ) ;
348+
349+ string [ ] actualOutput = context . Streams . Out . ToString ( ) . Replace ( "\r \n " , "\n " ) . Split ( '\n ' ) ;
350+
351+ // Emits regular Credential without 'state[]=authtype' support.
352+ Assert . Contains ( "username=alice" , actualOutput ) ;
353+ Assert . Contains ( "password=hunter2" , actualOutput ) ;
354+ Assert . DoesNotContain ( "authtype=token" , actualOutput ) ;
355+ Assert . DoesNotContain ( "credential=hunter2" , actualOutput ) ;
356+ Assert . DoesNotContain ( "ephemeral=1" , actualOutput ) ;
357+ }
358+
359+ [ Fact ]
360+ public async Task GetCommand_ExecuteAsync_CapabilityAuthType_UsesAuthTypeFeatures ( )
361+ {
362+ ICredential testCredential = new GitCredential ( "alice" , "hunter2" ) ;
363+ var response = GitResponse . Ok ( testCredential , isEphemeral : true , authtype : "token" ) ;
364+
365+ var stdin = "protocol=https\n host=example.com\n capability[]=authtype\n \n " ;
366+
367+ var providerMock = new Mock < IHostProvider > ( ) ;
368+ providerMock . Setup ( x => x . GetCredentialAsync ( It . IsAny < GitRequest > ( ) ) )
369+ . ReturnsAsync ( response ) ;
370+ var providerRegistry = new TestHostProviderRegistry { Provider = providerMock . Object } ;
371+ var context = new TestCommandContext { Streams = { In = stdin } } ;
372+
373+ var command = new GetCommand ( context , providerRegistry ) ;
374+
375+ await command . ExecuteAsync ( ) ;
376+
377+ string [ ] actualOutput = context . Streams . Out . ToString ( ) . Replace ( "\r \n " , "\n " ) . Split ( '\n ' ) ;
378+
379+ // Ephemeral credential with 'authtype' and 'credential' value
380+ Assert . DoesNotContain ( "username=alice" , actualOutput ) ;
381+ Assert . DoesNotContain ( "password=hunter2" , actualOutput ) ;
382+ Assert . Contains ( "authtype=token" , actualOutput ) ;
383+ Assert . Contains ( "credential=hunter2" , actualOutput ) ;
384+ Assert . Contains ( "ephemeral=1" , actualOutput ) ;
385+ }
386+
331387 #region Helpers
332388
333389 private static IDictionary < string , string > ParseDictionary ( StringBuilder sb ) => ParseDictionary ( sb . ToString ( ) ) ;
0 commit comments