File tree Expand file tree Collapse file tree 4 files changed +45
-3
lines changed
packages/odata-service-inquirer
src/prompts/datasources/sap-system
test/unit/prompts/sap-system/credentials Expand file tree Collapse file tree 4 files changed +45
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @sap-ux/odata-service-inquirer ' : patch
3+ ---
4+
5+ Fixes creds prompt shown when sap client invalid (on-prem url/client only)
Original file line number Diff line number Diff line change @@ -107,6 +107,9 @@ export function getAbapOnPremSystemQuestions(
107107 client
108108 ) ;
109109 if ( existingBackend ) {
110+ // Prevents further prompts by setting the client to invalid
111+ // This is a temp workaround until multiple systems with the same url/client key is supported
112+ sapClientRef . isValid = false ;
110113 return t ( 'prompts.validationMessages.backendSystemExistsWarning' , {
111114 backendName : existingBackend . name
112115 } ) ;
Original file line number Diff line number Diff line change @@ -45,7 +45,9 @@ export function getCredentialsPrompts<T extends Answers>(
4545 {
4646 when : async ( ) => {
4747 authRequired = await connectionValidator . isAuthRequired ( ) ;
48- return connectionValidator . systemAuthType === 'basic' && authRequired ;
48+ return (
49+ connectionValidator . systemAuthType === 'basic' && authRequired && ( ! sapClient || sapClient . isValid )
50+ ) ;
4951 } ,
5052 type : 'input' ,
5153 name : usernamePromptName ,
@@ -57,7 +59,8 @@ export function getCredentialsPrompts<T extends Answers>(
5759 validate : ( user : string ) => user ?. length > 0
5860 } as InputQuestion < T > ,
5961 {
60- when : ( ) => ! ! ( connectionValidator . systemAuthType === 'basic' && authRequired ) ,
62+ when : ( ) =>
63+ ! ! ( connectionValidator . systemAuthType === 'basic' && authRequired && ( ! sapClient || sapClient . isValid ) ) ,
6164 type : 'password' ,
6265 guiOptions : {
6366 mandatory : true ,
@@ -74,7 +77,7 @@ export function getCredentialsPrompts<T extends Answers>(
7477 connectionValidator . validatedUrl &&
7578 answers ?. [ usernamePromptName ] &&
7679 password &&
77- ( sapClient ?. isValid || ! sapClient )
80+ ( ! sapClient || sapClient . isValid )
7881 )
7982 ) {
8083 return false ;
Original file line number Diff line number Diff line change @@ -269,4 +269,35 @@ describe('Test credentials prompts', () => {
269269 } as NewSystemAnswers )
270270 ) . toBeUndefined ( ) ;
271271 } ) ;
272+
273+ test ( 'should not show credentials prompts if the sap client reference is invalid' , async ( ) => {
274+ const connectionValidator = new ConnectionValidator ( ) ;
275+ connectionValidatorMock . validity = {
276+ authenticated : false ,
277+ authRequired : true ,
278+ reachable : true
279+ } ;
280+ connectionValidatorMock . isAuthRequired . mockReturnValue ( true ) ;
281+ connectionValidatorMock . systemAuthType = 'basic' ;
282+ connectionValidatorMock . validatedUrl = 'http://abap01:1234' ;
283+ const sapClientRef = {
284+ sapClient : '999' ,
285+ isValid : true
286+ } ;
287+
288+ const credentialsPrompts = getCredentialsPrompts ( connectionValidator , promptNamespace , sapClientRef ) ;
289+ const userNamePrompt = credentialsPrompts . find (
290+ ( question ) => question . name === systemUsernamePromptName
291+ ) as InputQuestion ;
292+ const passwordPrompt = credentialsPrompts . find (
293+ ( question ) => question . name === systemPasswordPromptName
294+ ) as PasswordQuestion ;
295+
296+ expect ( await ( userNamePrompt ?. when as Function ) ( ) ) . toBe ( true ) ;
297+ expect ( await ( passwordPrompt ?. when as Function ) ( ) ) . toBe ( true ) ;
298+
299+ sapClientRef . isValid = false ;
300+ expect ( await ( userNamePrompt ?. when as Function ) ( ) ) . toBe ( false ) ;
301+ expect ( await ( passwordPrompt ?. when as Function ) ( ) ) . toBe ( false ) ;
302+ } ) ;
272303} ) ;
You can’t perform that action at this time.
0 commit comments