Skip to content

Commit 1b5d459

Browse files
authored
fix(odata-service-inquirer):Hide credentials prompts if client not valid (#3765)
* fix(odata-service-inquirer):Hide credentials prompts if client not valid #3764 * Adds cset
1 parent 70984b3 commit 1b5d459

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

.changeset/old-olives-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sap-ux/odata-service-inquirer': patch
3+
---
4+
5+
Fixes creds prompt shown when sap client invalid (on-prem url/client only)

packages/odata-service-inquirer/src/prompts/datasources/sap-system/abap-on-prem/questions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

packages/odata-service-inquirer/src/prompts/datasources/sap-system/credentials/questions.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff 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;

packages/odata-service-inquirer/test/unit/prompts/sap-system/credentials/questions.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)