@@ -439,42 +439,49 @@ test("getCredentials accepts OIDC configurations", (t) => {
439439 t . assert ( credentials . some ( ( c ) => startProxyExports . isJFrogConfig ( c ) ) ) ;
440440} ) ;
441441
442- test ( "getCredentials logs a warning when a PAT is used without a username" , async ( t ) => {
443- const loggedMessages = [ ] ;
444- const logger = getRecordingLogger ( loggedMessages ) ;
445- const likelyWrongCredentials = toEncodedJSON ( [
446- {
447- type : "git_server" ,
448- host : "https://github.com/" ,
449- password : `ghp_${ makeTestToken ( ) } ` ,
450- } ,
451- ] ) ;
452-
453- const results = startProxyExports . getCredentials (
454- logger ,
455- undefined ,
456- likelyWrongCredentials ,
457- undefined ,
458- ) ;
442+ const testPATWarning = test . macro ( {
443+ exec : async ( t : ExecutionContext < unknown > ) => {
444+ const loggedMessages = [ ] ;
445+ const logger = getRecordingLogger ( loggedMessages ) ;
446+ const likelyWrongCredentials = toEncodedJSON ( [
447+ {
448+ type : "git_server" ,
449+ host : "https://github.com/" ,
450+ password : `ghp_${ makeTestToken ( ) } ` ,
451+ } ,
452+ ] ) ;
459453
460- // The configuration should be accepted, despite the likely problem.
461- t . assert ( results ) ;
462- t . is ( results . length , 1 ) ;
463- t . is ( results [ 0 ] . type , "git_server" ) ;
464- t . is ( results [ 0 ] . host , "https://github.com/" ) ;
454+ const results = startProxyExports . getCredentials (
455+ logger ,
456+ undefined ,
457+ likelyWrongCredentials ,
458+ undefined ,
459+ ) ;
465460
466- if ( startProxyExports . isUsernamePassword ( results [ 0 ] ) ) {
467- t . assert ( results [ 0 ] . password ?. startsWith ( "ghp_" ) ) ;
468- } else {
469- t . fail ( "Expected a `UsernamePassword`-based credential." ) ;
470- }
461+ // The configuration should be accepted, despite the likely problem.
462+ t . assert ( results ) ;
463+ t . is ( results . length , 1 ) ;
464+ t . is ( results [ 0 ] . type , "git_server" ) ;
465+ t . is ( results [ 0 ] . host , "https://github.com/" ) ;
466+
467+ if ( startProxyExports . isUsernamePassword ( results [ 0 ] ) ) {
468+ t . assert ( results [ 0 ] . password ?. startsWith ( "ghp_" ) ) ;
469+ } else {
470+ t . fail ( "Expected a `UsernamePassword`-based credential." ) ;
471+ }
472+
473+ // A warning should have been logged.
474+ checkExpectedLogMessages ( t , loggedMessages , [
475+ "using a GitHub Personal Access Token (PAT), but no username was provided" ,
476+ ] ) ;
477+ } ,
471478
472- // A warning should have been logged.
473- checkExpectedLogMessages ( t , loggedMessages , [
474- "using a GitHub Personal Access Token (PAT), but no username was provided" ,
475- ] ) ;
479+ title : ( providedTitle = "" ) =>
480+ `getCredentials logs a warning when a PAT is used - ${ providedTitle } ` ,
476481} ) ;
477482
483+ test ( "password without a username" , testPATWarning ) ;
484+
478485test ( "getCredentials returns all credentials for Actions when using LANGUAGE_TO_REGISTRY_TYPE" , async ( t ) => {
479486 const credentialsInput = toEncodedJSON ( mixedCredentials ) ;
480487
0 commit comments