From 33854f2292f3a6c1546193b74317e29393ebd8e4 Mon Sep 17 00:00:00 2001 From: katelynienaber Date: Tue, 2 Feb 2021 11:59:33 +0100 Subject: [PATCH 1/3] Veeery rough copy Signed-off-by: katelynienaber --- .../__tests__/__unit__/Profiles.unit.test.ts | 16 +++-- packages/zowe-explorer/src/Profiles.ts | 66 ++++++++----------- .../src/abstract/ZoweTreeProvider.ts | 18 ++--- 3 files changed, 42 insertions(+), 58 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts index 8767cfb959..1b3e83d5c4 100644 --- a/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts @@ -2018,13 +2018,17 @@ describe("Profiles Unit Tests - Function checkCurrentProfile", () => { const blockMocks = await createBlockMocks(globalMocks); const theProfiles = await Profiles.createInstance(blockMocks.log); + const mockValidateProfiles = jest.fn(); Object.defineProperty(theProfiles, "validateProfiles", { - value: jest.fn(() => { - return { - status: "active", - name: blockMocks.invalidProfile.name, - }; - }), + value: mockValidateProfiles, + }); + mockValidateProfiles.mockReturnValueOnce({ + status: "active", + name: blockMocks.invalidProfile.name, + }); + mockValidateProfiles.mockReturnValue({ + status: "inactive", + name: blockMocks.invalidProfile.name, }); blockMocks.profiles.promptCredentials = jest.fn(() => { return undefined; diff --git a/packages/zowe-explorer/src/Profiles.ts b/packages/zowe-explorer/src/Profiles.ts index 1a968ac697..ebc5577015 100644 --- a/packages/zowe-explorer/src/Profiles.ts +++ b/packages/zowe-explorer/src/Profiles.ts @@ -79,16 +79,7 @@ export class Profiles extends ProfilesCache { } public async checkCurrentProfile(theProfile: IProfileLoaded) { - const profileStatus: IProfileValidation = await this.getProfileSetting(theProfile); - if (profileStatus.status === "inactive") { - this.validProfile = ValidProfileEnum.INVALID; - return profileStatus; - } - - // if (profileStatus.status === "unverified") { - // this.validProfile = ValidProfileEnum.UNVERIFIED; - // return profileStatus; - // } + let profileStatus: IProfileValidation = await this.getProfileSetting(theProfile); // This step is for prompting of credentials. It will be triggered if it meets the following conditions: // - The service does not have username or password and base profile doesn't exists @@ -101,12 +92,18 @@ export class Profiles extends ProfilesCache { baseProfile.profile.host !== theProfile.profile.host && baseProfile.profile.port !== theProfile.profile.port) ) { + // The profile will need to be reactivated, so remove it from profilesForValidation + this.profilesForValidation.filter((profile, index) => { + if (profile.name === theProfile.name && profile.status !== "unverified") { + this.profilesForValidation.splice(index, 1); + } + }); try { - const values = await Profiles.getInstance().promptCredentials(theProfile.name); + const values = await Profiles.getInstance().promptCredentials(theProfile.name, true); if (values !== undefined) { - this.usrNme = values[0]; - this.passWrd = values[1]; - this.baseEncd = values[2]; + theProfile.profile.user = values[0]; + theProfile.profile.password = values[1]; + theProfile.profile.base64EncodedAuth = values[2]; } } catch (error) { errorHandling( @@ -117,33 +114,22 @@ export class Profiles extends ProfilesCache { ); return profileStatus; } - if (this.usrNme !== undefined && this.passWrd !== undefined && this.baseEncd !== undefined) { - theProfile.profile.user = this.usrNme; - theProfile.profile.password = this.passWrd; - theProfile.profile.base64EncodedAuth = this.baseEncd; - if (profileStatus.status === "unverified") { - this.validProfile = ValidProfileEnum.UNVERIFIED; - } else { - this.validProfile = ValidProfileEnum.VALID; - } - return profileStatus; - } else { - // return invalid if credentials are not provided - if (profileStatus.status === "unverified") { - this.validProfile = ValidProfileEnum.UNVERIFIED; - } else { - this.validProfile = ValidProfileEnum.INVALID; - } - return profileStatus; - } - } else { - if (profileStatus.status === "unverified") { + + // Revalidate profile + profileStatus = await this.getProfileSetting(theProfile); + } + switch (profileStatus.status) { + case "unverified": this.validProfile = ValidProfileEnum.UNVERIFIED; - } else { + break; + case "inactive": + this.validProfile = ValidProfileEnum.INVALID; + break; + case "active": this.validProfile = ValidProfileEnum.VALID; - } - return profileStatus; + break; } + return profileStatus; } public async getProfileSetting(theProfile: IProfileLoaded): Promise { @@ -754,7 +740,7 @@ export class Profiles extends ProfilesCache { newUser = loadSession.user = loadProfile.profile.user; } - if (newUser === undefined) { + if (newUser === undefined || (rePrompt && newUser === "")) { vscode.window.showInformationMessage( localize("promptCredentials.undefined.username", "Operation Cancelled") ); @@ -769,7 +755,7 @@ export class Profiles extends ProfilesCache { } } - if (newPass === undefined) { + if (newPass === undefined || (rePrompt && newUser === "")) { vscode.window.showInformationMessage( localize("promptCredentials.undefined.password", "Operation Cancelled") ); diff --git a/packages/zowe-explorer/src/abstract/ZoweTreeProvider.ts b/packages/zowe-explorer/src/abstract/ZoweTreeProvider.ts index af714b9ecf..04324c62f6 100644 --- a/packages/zowe-explorer/src/abstract/ZoweTreeProvider.ts +++ b/packages/zowe-explorer/src/abstract/ZoweTreeProvider.ts @@ -193,10 +193,8 @@ export class ZoweTreeProvider { node.contextValue.toLowerCase().includes("session") || node.contextValue.toLowerCase().includes("server") ) { - // change contextValue only if the word inactive is not there - if (node.contextValue.toLowerCase().indexOf("inactive") === -1) { - node.contextValue = node.contextValue + globals.INACTIVE_CONTEXT; - } + node.contextValue = node.contextValue.replace(/(?<=.*)(_Active|_Inactive|_Unverified)$/, ""); + node.contextValue = node.contextValue + globals.INACTIVE_CONTEXT; const inactiveIcon = getIconById(IconId.sessionInactive); if (inactiveIcon) { node.iconPath = inactiveIcon.path; @@ -224,10 +222,8 @@ export class ZoweTreeProvider { node.contextValue.toLowerCase().includes("session") || node.contextValue.toLowerCase().includes("server") ) { - // change contextValue only if the word active is not there - if (node.contextValue.toLowerCase().indexOf("active") === -1) { - node.contextValue = node.contextValue + globals.ACTIVE_CONTEXT; - } + node.contextValue = node.contextValue.replace(/(?<=.*)(_Active|_Inactive|_Unverified)$/, ""); + node.contextValue = node.contextValue + globals.ACTIVE_CONTEXT; const activeIcon = getIconById(IconId.sessionActive); if (activeIcon) { node.iconPath = activeIcon.path; @@ -238,10 +234,8 @@ export class ZoweTreeProvider { node.contextValue.toLowerCase().includes("session") || node.contextValue.toLowerCase().includes("server") ) { - // change contextValue only if the word unverified is not there - if (node.contextValue.toLowerCase().indexOf("unverified") === -1) { - node.contextValue = node.contextValue + globals.UNVERIFIED_CONTEXT; - } + node.contextValue = node.contextValue.replace(/(?<=.*)(_Active|_Inactive|_Unverified)$/, ""); + node.contextValue = node.contextValue + globals.UNVERIFIED_CONTEXT; } } await this.refresh(); From 62442606b95dc048d2c829b78d0ee7e93029facb Mon Sep 17 00:00:00 2001 From: katelynienaber Date: Fri, 5 Feb 2021 10:11:06 +0100 Subject: [PATCH 2/3] Fixed error occurring when user prompted Signed-off-by: katelynienaber --- .../zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts | 4 ---- packages/zowe-explorer/src/Profiles.ts | 7 +++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts b/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts index 1b3e83d5c4..60c019e833 100644 --- a/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts +++ b/packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts @@ -2022,10 +2022,6 @@ describe("Profiles Unit Tests - Function checkCurrentProfile", () => { Object.defineProperty(theProfiles, "validateProfiles", { value: mockValidateProfiles, }); - mockValidateProfiles.mockReturnValueOnce({ - status: "active", - name: blockMocks.invalidProfile.name, - }); mockValidateProfiles.mockReturnValue({ status: "inactive", name: blockMocks.invalidProfile.name, diff --git a/packages/zowe-explorer/src/Profiles.ts b/packages/zowe-explorer/src/Profiles.ts index ebc5577015..ca287022ec 100644 --- a/packages/zowe-explorer/src/Profiles.ts +++ b/packages/zowe-explorer/src/Profiles.ts @@ -79,7 +79,7 @@ export class Profiles extends ProfilesCache { } public async checkCurrentProfile(theProfile: IProfileLoaded) { - let profileStatus: IProfileValidation = await this.getProfileSetting(theProfile); + let profileStatus: IProfileValidation; // This step is for prompting of credentials. It will be triggered if it meets the following conditions: // - The service does not have username or password and base profile doesn't exists @@ -115,7 +115,10 @@ export class Profiles extends ProfilesCache { return profileStatus; } - // Revalidate profile + // Validate profile + profileStatus = await this.getProfileSetting(theProfile); + } else { + // Profile should have enough information to allow validation profileStatus = await this.getProfileSetting(theProfile); } switch (profileStatus.status) { From 38106a37e01820ce57c0c954c4acc5afd1c75ef8 Mon Sep 17 00:00:00 2001 From: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> Date: Fri, 5 Feb 2021 10:40:49 -0500 Subject: [PATCH 3/3] update check for missing creds to not rely on base profile (#1184) Signed-off-by: Billie Simmons <49491949+JillieBeanSim@users.noreply.github.com> --- packages/zowe-explorer/src/Profiles.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/packages/zowe-explorer/src/Profiles.ts b/packages/zowe-explorer/src/Profiles.ts index ca287022ec..5b2be65b81 100644 --- a/packages/zowe-explorer/src/Profiles.ts +++ b/packages/zowe-explorer/src/Profiles.ts @@ -71,27 +71,13 @@ export class Profiles extends ProfilesCache { private dsSchema: string = "Zowe-DS-Persistent"; private ussSchema: string = "Zowe-USS-Persistent"; private jobsSchema: string = "Zowe-Jobs-Persistent"; - private usrNme: string; - private passWrd: string; - private baseEncd: string; public constructor(log: Logger) { super(log); } public async checkCurrentProfile(theProfile: IProfileLoaded) { let profileStatus: IProfileValidation; - - // This step is for prompting of credentials. It will be triggered if it meets the following conditions: - // - The service does not have username or password and base profile doesn't exists - // - The service does not have username or password and the base profile has a different host and port - const baseProfile = this.getBaseProfile(); - - if ( - (!theProfile.profile.tokenType && (!theProfile.profile.user || !theProfile.profile.password)) || - (baseProfile && - baseProfile.profile.host !== theProfile.profile.host && - baseProfile.profile.port !== theProfile.profile.port) - ) { + if (!theProfile.profile.tokenType && (!theProfile.profile.user || !theProfile.profile.password)) { // The profile will need to be reactivated, so remove it from profilesForValidation this.profilesForValidation.filter((profile, index) => { if (profile.name === theProfile.name && profile.status !== "unverified") {