@@ -7,7 +7,12 @@ import { KnownLanguage } from "./languages";
77import { getRunnerLogger } from "./logging" ;
88import * as startProxyExports from "./start-proxy" ;
99import { parseLanguage } from "./start-proxy" ;
10- import { setupTests } from "./testing-utils" ;
10+ import {
11+ checkExpectedLogMessages ,
12+ getRecordingLogger ,
13+ makeTestToken ,
14+ setupTests ,
15+ } from "./testing-utils" ;
1116
1217setupTests ( test ) ;
1318
@@ -174,6 +179,37 @@ test("getCredentials throws an error when non-printable characters are used", as
174179 }
175180} ) ;
176181
182+ test ( "getCredentials logs a warning when a PAT is used without a username" , async ( t ) => {
183+ const loggedMessages = [ ] ;
184+ const logger = getRecordingLogger ( loggedMessages ) ;
185+ const likelyWrongCredentials = toEncodedJSON ( [
186+ {
187+ type : "git_server" ,
188+ host : "https://github.com/" ,
189+ password : `ghp_${ makeTestToken ( ) } ` ,
190+ } ,
191+ ] ) ;
192+
193+ const results = startProxyExports . getCredentials (
194+ logger ,
195+ undefined ,
196+ likelyWrongCredentials ,
197+ undefined ,
198+ ) ;
199+
200+ // The configuration should be accepted, despite the likely problem.
201+ t . assert ( results ) ;
202+ t . is ( results . length , 1 ) ;
203+ t . is ( results [ 0 ] . type , "git_server" ) ;
204+ t . is ( results [ 0 ] . host , "https://github.com/" ) ;
205+ t . assert ( results [ 0 ] . password ?. startsWith ( "ghp_" ) ) ;
206+
207+ // A warning should have been logged.
208+ checkExpectedLogMessages ( t , loggedMessages , [
209+ "using a GitHub Personal Access Token (PAT), but no username was provided" ,
210+ ] ) ;
211+ } ) ;
212+
177213test ( "parseLanguage" , async ( t ) => {
178214 // Exact matches
179215 t . deepEqual ( parseLanguage ( "csharp" ) , KnownLanguage . csharp ) ;
0 commit comments