File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed
Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -271,7 +271,7 @@ async function initOauthClient(
271271
272272 await triggerPostAuthCallbacks ( client . credentials ) ;
273273 } else {
274- const userConsent = await getConsentForOauth ( 'Code Assist login required. ' ) ;
274+ const userConsent = await getConsentForOauth ( '' ) ;
275275 if ( ! userConsent ) {
276276 throw new FatalCancellationError ( 'Authentication cancelled by user.' ) ;
277277 }
@@ -281,8 +281,7 @@ async function initOauthClient(
281281 coreEvents . emit ( CoreEvent . UserFeedback , {
282282 severity : 'info' ,
283283 message :
284- `\n\nCode Assist login required.\n` +
285- `Attempting to open authentication page in your browser.\n` +
284+ `\n\nAttempting to open authentication page in your browser.\n` +
286285 `Otherwise navigate to:\n\n${ webLogin . authUrl } \n\n\n` ,
287286 } ) ;
288287 try {
Original file line number Diff line number Diff line change @@ -56,6 +56,25 @@ describe('getConsentForOauth', () => {
5656 ) ;
5757 } ) ;
5858
59+ it ( 'should handle empty prompt correctly' , async ( ) => {
60+ const mockEmitConsentRequest = vi . spyOn ( coreEvents , 'emitConsentRequest' ) ;
61+ vi . spyOn ( coreEvents , 'listenerCount' ) . mockReturnValue ( 1 ) ;
62+
63+ mockEmitConsentRequest . mockImplementation ( ( payload ) => {
64+ payload . onConfirm ( true ) ;
65+ } ) ;
66+
67+ await getConsentForOauth ( '' ) ;
68+
69+ expect ( mockEmitConsentRequest ) . toHaveBeenCalledWith (
70+ expect . objectContaining ( {
71+ prompt : expect . stringMatching (
72+ / ^ O p e n i n g a u t h e n t i c a t i o n p a g e i n y o u r b r o w s e r \. / ,
73+ ) ,
74+ } ) ,
75+ ) ;
76+ } ) ;
77+
5978 it ( 'should return false when user declines via UI' , async ( ) => {
6079 const mockEmitConsentRequest = vi . spyOn ( coreEvents , 'emitConsentRequest' ) ;
6180 vi . spyOn ( coreEvents , 'listenerCount' ) . mockReturnValue ( 1 ) ;
Original file line number Diff line number Diff line change @@ -15,7 +15,9 @@ import { isHeadlessMode } from './headless.js';
1515 * Handles both interactive and non-interactive (headless) modes.
1616 */
1717export async function getConsentForOauth ( prompt : string ) : Promise < boolean > {
18- const finalPrompt = prompt + ' Opening authentication page in your browser. ' ;
18+ const finalPrompt =
19+ ( prompt ? prompt + ' ' : '' ) +
20+ 'Opening authentication page in your browser. ' ;
1921
2022 if ( isHeadlessMode ( ) ) {
2123 return getOauthConsentNonInteractive ( finalPrompt ) ;
You can’t perform that action at this time.
0 commit comments