Skip to content

Commit

Permalink
Merge pull request #1178 from zowe/always-allow-prompting
Browse files Browse the repository at this point in the history
PR #1120 linked issue: Always allow prompting
  • Loading branch information
lauren-li authored Feb 5, 2021
2 parents f9bf175 + 38106a3 commit a4cf007
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 72 deletions.
12 changes: 6 additions & 6 deletions packages/zowe-explorer/__tests__/__unit__/Profiles.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2018,13 +2018,13 @@ 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.mockReturnValue({
status: "inactive",
name: blockMocks.invalidProfile.name,
});
blockMocks.profiles.promptCredentials = jest.fn(() => {
return undefined;
Expand Down
83 changes: 29 additions & 54 deletions packages/zowe-explorer/src/Profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,42 +71,25 @@ 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) {
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;
// }

// 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)
) {
let profileStatus: IProfileValidation;
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") {
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(
Expand All @@ -117,33 +100,25 @@ 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;
}

// Validate profile
profileStatus = await this.getProfileSetting(theProfile);
} else {
if (profileStatus.status === "unverified") {
// Profile should have enough information to allow validation
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<IProfileValidation> {
Expand Down Expand Up @@ -754,7 +729,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")
);
Expand All @@ -769,7 +744,7 @@ export class Profiles extends ProfilesCache {
}
}

if (newPass === undefined) {
if (newPass === undefined || (rePrompt && newUser === "")) {
vscode.window.showInformationMessage(
localize("promptCredentials.undefined.password", "Operation Cancelled")
);
Expand Down
18 changes: 6 additions & 12 deletions packages/zowe-explorer/src/abstract/ZoweTreeProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit a4cf007

Please sign in to comment.