@@ -14,9 +14,9 @@ import * as startProxyExports from "./start-proxy";
1414import { parseLanguage } from "./start-proxy" ;
1515import * as statusReport from "./status-report" ;
1616import {
17+ assertNotLogged ,
1718 checkExpectedLogMessages ,
1819 createFeatures ,
19- getRecordingLogger ,
2020 makeTestToken ,
2121 RecordingLogger ,
2222 setupTests ,
@@ -445,11 +445,11 @@ const testPATWarning = test.macro({
445445 credentials : startProxyExports . RawCredential [ ] ,
446446 checkAccepted : (
447447 t : ExecutionContext < unknown > ,
448+ logger : RecordingLogger ,
448449 results : startProxyExports . Credential [ ] ,
449450 ) => void ,
450451 ) => {
451- const loggedMessages = [ ] ;
452- const logger = getRecordingLogger ( loggedMessages ) ;
452+ const logger = new RecordingLogger ( ) ;
453453 const likelyWrongCredentials = toEncodedJSON ( credentials ) ;
454454
455455 const results = startProxyExports . getCredentials (
@@ -459,12 +459,7 @@ const testPATWarning = test.macro({
459459 undefined ,
460460 ) ;
461461
462- checkAccepted ( t , results ) ;
463-
464- // A warning should have been logged.
465- checkExpectedLogMessages ( t , loggedMessages , [
466- "using a GitHub Personal Access Token (PAT), but no username was provided" ,
467- ] ) ;
462+ checkAccepted ( t , logger , results ) ;
468463 } ,
469464
470465 title : ( providedTitle = "" ) =>
@@ -481,7 +476,7 @@ test(
481476 password : `ghp_${ makeTestToken ( ) } ` ,
482477 } ,
483478 ] ,
484- ( t , results ) => {
479+ ( t , logger , results ) => {
485480 // The configurations should be accepted, despite the likely problem.
486481 t . assert ( results ) ;
487482 t . is ( results . length , 1 ) ;
@@ -493,6 +488,43 @@ test(
493488 } else {
494489 t . fail ( "Expected a `UsernamePassword`-based credential." ) ;
495490 }
491+
492+ // A warning should have been logged.
493+ checkExpectedLogMessages ( t , logger . messages , [
494+ "using a GitHub Personal Access Token (PAT), but no username was provided" ,
495+ ] ) ;
496+ } ,
497+ ) ;
498+
499+ test (
500+ "password with a username" ,
501+ testPATWarning ,
502+ [
503+ {
504+ type : "git_server" ,
505+ host : "https://github.com/" ,
506+ username : "someone" ,
507+ password : `ghp_${ makeTestToken ( ) } ` ,
508+ } ,
509+ ] ,
510+ ( t , logger , results ) => {
511+ // The configurations should be accepted, despite the likely problem.
512+ t . assert ( results ) ;
513+ t . is ( results . length , 1 ) ;
514+ t . is ( results [ 0 ] . type , "git_server" ) ;
515+ t . is ( results [ 0 ] . host , "https://github.com/" ) ;
516+
517+ if ( startProxyExports . isUsernamePassword ( results [ 0 ] ) ) {
518+ t . assert ( results [ 0 ] . password ?. startsWith ( "ghp_" ) ) ;
519+ } else {
520+ t . fail ( "Expected a `UsernamePassword`-based credential." ) ;
521+ }
522+
523+ assertNotLogged (
524+ t ,
525+ logger ,
526+ "using a GitHub Personal Access Token (PAT), but no username was provided" ,
527+ ) ;
496528 } ,
497529) ;
498530
@@ -506,7 +538,38 @@ test(
506538 token : `ghp_${ makeTestToken ( ) } ` ,
507539 } ,
508540 ] ,
509- ( t , results ) => {
541+ ( t , logger , results ) => {
542+ // The configurations should be accepted, despite the likely problem.
543+ t . assert ( results ) ;
544+ t . is ( results . length , 1 ) ;
545+ t . is ( results [ 0 ] . type , "git_server" ) ;
546+ t . is ( results [ 0 ] . host , "https://github.com/" ) ;
547+
548+ if ( startProxyExports . isToken ( results [ 0 ] ) ) {
549+ t . assert ( results [ 0 ] . token ?. startsWith ( "ghp_" ) ) ;
550+ } else {
551+ t . fail ( "Expected a `Token`-based credential." ) ;
552+ }
553+
554+ // A warning should have been logged.
555+ checkExpectedLogMessages ( t , logger . messages , [
556+ "using a GitHub Personal Access Token (PAT), but no username was provided" ,
557+ ] ) ;
558+ } ,
559+ ) ;
560+
561+ test (
562+ "token with a username" ,
563+ testPATWarning ,
564+ [
565+ {
566+ type : "git_server" ,
567+ host : "https://github.com/" ,
568+ username : "someone" ,
569+ token : `ghp_${ makeTestToken ( ) } ` ,
570+ } ,
571+ ] ,
572+ ( t , logger , results ) => {
510573 // The configurations should be accepted, despite the likely problem.
511574 t . assert ( results ) ;
512575 t . is ( results . length , 1 ) ;
@@ -518,6 +581,12 @@ test(
518581 } else {
519582 t . fail ( "Expected a `Token`-based credential." ) ;
520583 }
584+
585+ assertNotLogged (
586+ t ,
587+ logger ,
588+ "using a GitHub Personal Access Token (PAT), but no username was provided" ,
589+ ) ;
521590 } ,
522591) ;
523592
0 commit comments