Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default credentials manager check and not-found dialog #3297

Merged
merged 14 commits into from
Nov 12, 2024
Merged
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"console": "integratedTerminal",
"sourceMaps": true
},
{
"type": "node",
"name": "Current Unit Tests (Jest)",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceFolder}/node_modules/jest/bin/jest", "-i", "${fileBasenameNoExtension}"],
zFernand0 marked this conversation as resolved.
Show resolved Hide resolved
"cwd": "${workspaceFolder}/packages/zowe-explorer",
"console": "integratedTerminal",
"sourceMaps": true
},
{
"type": "node",
"name": "API Unit Tests (Jest)",
Expand Down
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Fixed issue where Zowe Explorer would present the "No configs detected" notification when initialized in a workspace without a Zowe team configuration. [#3280](https://github.com/zowe/zowe-explorer-vscode/issues/3280)
- Reduced the number of MVS API calls performed by `vscode.workspace.fs.readFile` when fetching the contents of a data set entry. [#3278](https://github.com/zowe/zowe-explorer-vscode/issues/3278)
- Fixed an issue to review inconsistent capitalization across translation strings. [#2935](https://github.com/zowe/zowe-explorer-vscode/issues/2935)
- Updated the test for the default credential manager for better compatibility with Cloud-based platforms such as Eclipse Che and Red Hat OpenShift Dev Spaces. [#3297](https://github.com/zowe/zowe-explorer-vscode/pull/3297)

## `3.0.2`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ describe("ProfilesUtils unit tests", () => {
Object.defineProperty(ZoweLogger, "info", { value: jest.fn(), configurable: true });
Object.defineProperty(SettingsConfig, "getDirectValue", { value: newMocks.mockGetDirectValue, configurable: true });
Object.defineProperty(ProfilesUtils, "PROFILE_SECURITY", { value: Constants.ZOWE_CLI_SCM, configurable: true });
Object.defineProperty(ProfilesUtils, "checkDefaultCredentialManager", { value: jest.fn(), configurable: true });
return newMocks;
}

Expand Down Expand Up @@ -457,6 +458,7 @@ describe("ProfilesUtils unit tests", () => {
describe("initializeZoweFolder", () => {
it("should create directories and files that do not exist", async () => {
const blockMocks = createBlockMocks();
jest.spyOn(ProfilesUtils, "checkDefaultCredentialManager").mockReturnValue(true);
blockMocks.mockGetDirectValue.mockReturnValue(true);
blockMocks.mockExistsSync.mockReturnValue(false);
jest.spyOn(fs, "readFileSync").mockReturnValue(Buffer.from(JSON.stringify({ overrides: { credentialManager: "@zowe/cli" } }), "utf-8"));
Expand All @@ -469,6 +471,7 @@ describe("ProfilesUtils unit tests", () => {

it("should skip creating directories and files that already exist", async () => {
const blockMocks = createBlockMocks();
jest.spyOn(ProfilesUtils, "checkDefaultCredentialManager").mockReturnValue(true);
jest.spyOn(ProfilesUtils, "getCredentialManagerOverride").mockReturnValue("@zowe/cli");
blockMocks.mockGetDirectValue.mockReturnValue("@zowe/cli");
blockMocks.mockExistsSync.mockReturnValue(true);
Expand Down Expand Up @@ -566,7 +569,7 @@ describe("ProfilesUtils unit tests", () => {

it("should handle Imperative error thrown on read config from disk", async () => {
const testError = new imperative.ImperativeError({ msg: "readConfigFromDisk failed" });
const initZoweFolderSpy = jest.spyOn(ProfilesUtils, "initializeZoweFolder").mockReturnValueOnce();
const initZoweFolderSpy = jest.spyOn(ProfilesUtils, "initializeZoweFolder").mockResolvedValueOnce();
const readConfigFromDiskSpy = jest.spyOn(ProfilesUtils, "readConfigFromDisk").mockRejectedValueOnce(testError);
await ProfilesUtils.initializeZoweProfiles((msg) => ZoweExplorerExtender.showZoweConfigError(msg));
expect(initZoweFolderSpy).toHaveBeenCalledTimes(1);
Expand All @@ -576,7 +579,7 @@ describe("ProfilesUtils unit tests", () => {

it("should handle JSON parse error thrown on read config from disk", async () => {
const testError = new Error("readConfigFromDisk failed");
const initZoweFolderSpy = jest.spyOn(ProfilesUtils, "initializeZoweFolder").mockReturnValueOnce();
const initZoweFolderSpy = jest.spyOn(ProfilesUtils, "initializeZoweFolder").mockResolvedValueOnce();
const readConfigFromDiskSpy = jest.spyOn(ProfilesUtils, "readConfigFromDisk").mockRejectedValueOnce(testError);
const showZoweConfigErrorSpy = jest.spyOn(ZoweExplorerExtender, "showZoweConfigError").mockReturnValueOnce();
await ProfilesUtils.initializeZoweProfiles((msg) => ZoweExplorerExtender.showZoweConfigError(msg));
Expand Down Expand Up @@ -649,6 +652,7 @@ describe("ProfilesUtils unit tests", () => {
it("should update the credential manager setting if secure value is true", () => {
jest.spyOn(SettingsConfig, "isConfigSettingSetByUser").mockReturnValue(false);
jest.spyOn(SettingsConfig, "getDirectValue").mockReturnValueOnce(true);
jest.spyOn(ProfilesUtils, "checkDefaultCredentialManager").mockReturnValue(true);
const loggerInfoSpy = jest.spyOn(ZoweLogger, "info");
const recordCredMgrInConfigSpy = jest.spyOn(imperative.CredentialManagerOverride, "recordCredMgrInConfig");
ProfilesUtils.updateCredentialManagerSetting();
Expand Down Expand Up @@ -679,7 +683,8 @@ describe("ProfilesUtils unit tests", () => {
let getCredentialManagerMapSpy: jest.SpyInstance;
let setupCustomCredentialManagerSpy: jest.SpyInstance;
let readProfilesFromDiskSpy: jest.SpyInstance;
let promptAndDisableCredentialManagementSpy: jest.SpyInstance;
let disableCredentialManagementSpy: jest.SpyInstance;
let checkDefaultCredentialManagerSpy: jest.SpyInstance;

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -692,7 +697,8 @@ describe("ProfilesUtils unit tests", () => {
getCredentialManagerMapSpy = jest.spyOn(ProfilesUtils, "getCredentialManagerMap");
setupCustomCredentialManagerSpy = jest.spyOn(ProfilesUtils, "setupCustomCredentialManager");
readProfilesFromDiskSpy = jest.spyOn(imperative.ProfileInfo.prototype, "readProfilesFromDisk");
promptAndDisableCredentialManagementSpy = jest.spyOn(ProfilesUtils, "promptAndDisableCredentialManagement");
disableCredentialManagementSpy = jest.spyOn(ProfilesUtils, "disableCredentialManagement");
checkDefaultCredentialManagerSpy = jest.spyOn(ProfilesUtils, "checkDefaultCredentialManager");
});

it("should retrieve the custom credential manager", async () => {
Expand Down Expand Up @@ -720,10 +726,11 @@ describe("ProfilesUtils unit tests", () => {
await expect(ProfilesUtils.getProfileInfo()).resolves.toEqual({});
});

it("should retrieve the default credential manager and prompt to disable credential management if environment not supported", async () => {
it("should throw exception of readProfilesFromDiskSpy fails", async () => {
const expectedErrMsg =
// eslint-disable-next-line max-len
"Failed to load credential manager. This may be related to Zowe Explorer being unable to use the default credential manager in a browser based environment.";
checkDefaultCredentialManagerSpy.mockReturnValue(false);
getDirectValueSpy.mockReturnValueOnce(false);
getCredentialManagerOverrideSpy.mockReturnValue("@zowe/cli");
isVSCodeCredentialPluginInstalledSpy.mockReturnValueOnce(false);
Expand All @@ -741,11 +748,11 @@ describe("ProfilesUtils unit tests", () => {
throw err;
});
await expect(ProfilesUtils.getProfileInfo()).rejects.toThrow(expectedErrMsg);
expect(promptAndDisableCredentialManagementSpy).toHaveBeenCalledTimes(1);
});

it("should ignore error if it is not an instance of ProfInfoErr", async () => {
const expectedErrorMsg = "Another error unrelated to credential management";
checkDefaultCredentialManagerSpy.mockReturnValue(true);
getDirectValueSpy.mockReturnValueOnce(false);
getCredentialManagerOverrideSpy.mockReturnValue("@zowe/cli");
isVSCodeCredentialPluginInstalledSpy.mockReturnValueOnce(false);
Expand All @@ -756,7 +763,7 @@ describe("ProfilesUtils unit tests", () => {
throw new Error(expectedErrorMsg);
});
await expect(ProfilesUtils.getProfileInfo()).resolves.not.toThrow();
expect(promptAndDisableCredentialManagementSpy).toHaveBeenCalledTimes(0);
expect(disableCredentialManagementSpy).toHaveBeenCalledTimes(0);
});
});

Expand Down Expand Up @@ -960,10 +967,11 @@ describe("ProfilesUtils unit tests", () => {
});
});

describe("promptAndDisableCredentialManagement", () => {
describe("disableCredentialManagement", () => {
let setDirectValueSpy: jest.SpyInstance;
let warningMessageSpy: jest.SpyInstance;
let executeCommandSpy: jest.SpyInstance;
let getDirectValueSpy: jest.SpyInstance;

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -972,33 +980,16 @@ describe("ProfilesUtils unit tests", () => {
setDirectValueSpy = jest.spyOn(SettingsConfig, "setDirectValue");
warningMessageSpy = jest.spyOn(Gui, "warningMessage");
executeCommandSpy = jest.spyOn(vscode.commands, "executeCommand");
getDirectValueSpy = jest.spyOn(SettingsConfig, "getDirectValue");
});

it("should prompt whether to disable credential management, and disable globally if 'Yes, globally' selected", async () => {
it("should show warning that credential management was disabled", async () => {
warningMessageSpy.mockResolvedValue("Yes, globally");
await expect(ProfilesUtils.promptAndDisableCredentialManagement()).resolves.not.toThrow();
getDirectValueSpy.mockReturnValueOnce(true);
await expect(ProfilesUtils.disableCredentialManagement()).resolves.not.toThrow();
expect(setDirectValueSpy).toHaveBeenCalledWith(Constants.SETTINGS_SECURE_CREDENTIALS_ENABLED, false, vscode.ConfigurationTarget.Global);
expect(executeCommandSpy).toHaveBeenCalledWith("workbench.action.reloadWindow");
});

it("should prompt whether to disable credential management, and disable on workspace if 'Only for this workspace' selected", async () => {
warningMessageSpy.mockResolvedValue("Only for this workspace");
await expect(ProfilesUtils.promptAndDisableCredentialManagement()).resolves.not.toThrow();
expect(setDirectValueSpy).toHaveBeenCalledWith(
Constants.SETTINGS_SECURE_CREDENTIALS_ENABLED,
false,
vscode.ConfigurationTarget.Workspace
);
expect(executeCommandSpy).toHaveBeenCalledWith("workbench.action.reloadWindow");
});

it("should prompt whether to disable credential management, and throw error if 'No'", async () => {
warningMessageSpy.mockResolvedValue("No");
await expect(ProfilesUtils.promptAndDisableCredentialManagement()).rejects.toThrow(
// eslint-disable-next-line max-len
"Failed to load credential manager. This may be related to Zowe Explorer being unable to use the default credential manager in a browser based environment."
);
});
});

describe("v1ProfileOptions", () => {
Expand Down
91 changes: 45 additions & 46 deletions packages/zowe-explorer/l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@
"Credential manager display name"
]
},
"Yes, globally": "Yes, globally",
"Only for this workspace": "Only for this workspace",
"Zowe Explorer failed to activate since the default credential manager is not supported in your environment.": "Zowe Explorer failed to activate since the default credential manager is not supported in your environment.",
"Do you wish to disable credential management? (VS Code window reload will be triggered)": "Do you wish to disable credential management? (VS Code window reload will be triggered)",
"Zowe Explorer's default credential manager is not supported in your environment. Consider installing a custom solution for your platform. Click Reload to start Zowe Explorer without a credential manager.": "Zowe Explorer's default credential manager is not supported in your environment. Consider installing a custom solution for your platform. Click Reload to start Zowe Explorer without a credential manager.",
"Reload window": "Reload window",
"Default Zowe credentials manager not found on current platform.": "Default Zowe credentials manager not found on current platform.",
"No custom credential managers found, using the default instead.": "No custom credential managers found, using the default instead.",
"Custom credential manager {0} found/Credential manager display name": {
"message": "Custom credential manager {0} found",
Expand Down Expand Up @@ -203,6 +202,48 @@
"Profile auth error": "Profile auth error",
"Profile is not authenticated, please log in to continue": "Profile is not authenticated, please log in to continue",
"Retrieving response from USS list API": "Retrieving response from USS list API",
"The 'move' function is not implemented for this USS API.": "The 'move' function is not implemented for this USS API.",
"Failed to move {0}/File path": {
"message": "Failed to move {0}",
"comment": [
"File path"
]
},
"Failed to get contents for {0}/File path": {
"message": "Failed to get contents for {0}",
"comment": [
"File path"
]
},
"Profile does not exist for this file.": "Profile does not exist for this file.",
"Saving USS file...": "Saving USS file...",
"Failed to rename {0}/File path": {
"message": "Failed to rename {0}",
"comment": [
"File path"
]
},
"Failed to delete {0}/File name": {
"message": "Failed to delete {0}",
"comment": [
"File name"
]
},
"No error details given": "No error details given",
"Error fetching destination {0} for paste action: {1}/USS pathError message": {
"message": "Error fetching destination {0} for paste action: {1}",
"comment": [
"USS path",
"Error message"
]
},
"Failed to copy {0} to {1}/Source pathDestination path": {
"message": "Failed to copy {0} to {1}",
"comment": [
"Source path",
"Destination path"
]
},
"Downloaded: {0}/Download time": {
"message": "Downloaded: {0}",
"comment": [
Expand Down Expand Up @@ -273,48 +314,6 @@
"initializeUSSFavorites.error.buttonRemove": "initializeUSSFavorites.error.buttonRemove",
"File does not exist. It may have been deleted.": "File does not exist. It may have been deleted.",
"Pulling from Mainframe...": "Pulling from Mainframe...",
"The 'move' function is not implemented for this USS API.": "The 'move' function is not implemented for this USS API.",
"Failed to move {0}/File path": {
"message": "Failed to move {0}",
"comment": [
"File path"
]
},
"Failed to get contents for {0}/File path": {
"message": "Failed to get contents for {0}",
"comment": [
"File path"
]
},
"Profile does not exist for this file.": "Profile does not exist for this file.",
"Saving USS file...": "Saving USS file...",
"Failed to rename {0}/File path": {
"message": "Failed to rename {0}",
"comment": [
"File path"
]
},
"Failed to delete {0}/File name": {
"message": "Failed to delete {0}",
"comment": [
"File name"
]
},
"No error details given": "No error details given",
"Error fetching destination {0} for paste action: {1}/USS pathError message": {
"message": "Error fetching destination {0} for paste action: {1}",
"comment": [
"USS path",
"Error message"
]
},
"Failed to copy {0} to {1}/Source pathDestination path": {
"message": "Failed to copy {0} to {1}",
"comment": [
"Source path",
"Destination path"
]
},
"{0} location/Node type": {
"message": "{0} location",
"comment": [
Expand Down
27 changes: 13 additions & 14 deletions packages/zowe-explorer/l10n/poeditor.json
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,9 @@
"Zowe Explorer profiles are being set as secured.": "",
"Custom credential manager failed to activate": "",
"Custom credential manager {0} found, attempting to activate.": "",
"Yes, globally": "",
"Only for this workspace": "",
"Zowe Explorer failed to activate since the default credential manager is not supported in your environment.": "",
"Do you wish to disable credential management? (VS Code window reload will be triggered)": "",
"Zowe Explorer's default credential manager is not supported in your environment. Consider installing a custom solution for your platform. Click Reload to start Zowe Explorer without a credential manager.": "",
"Reload window": "",
"Default Zowe credentials manager not found on current platform.": "",
"No custom credential managers found, using the default instead.": "",
"Custom credential manager {0} found": "",
"Do you wish to use this credential manager instead?": "",
Expand Down Expand Up @@ -534,6 +533,16 @@
"Profile auth error": "",
"Profile is not authenticated, please log in to continue": "",
"Retrieving response from USS list API": "",
"The 'move' function is not implemented for this USS API.": "",
"Failed to move {0}": "",
"Failed to get contents for {0}": "",
"Profile does not exist for this file.": "",
"Saving USS file...": "",
"Failed to rename {0}": "",
"Failed to delete {0}": "",
"No error details given": "",
"Error fetching destination {0} for paste action: {1}": "",
"Failed to copy {0} to {1}": "",
"Downloaded: {0}": "",
"Encoding: {0}": "",
"Binary": "",
Expand Down Expand Up @@ -562,16 +571,6 @@
"initializeUSSFavorites.error.buttonRemove": "",
"File does not exist. It may have been deleted.": "",
"Pulling from Mainframe...": "",
"The 'move' function is not implemented for this USS API.": "",
"Failed to move {0}": "",
"Failed to get contents for {0}": "",
"Profile does not exist for this file.": "",
"Saving USS file...": "",
"Failed to rename {0}": "",
"Failed to delete {0}": "",
"No error details given": "",
"Error fetching destination {0} for paste action: {1}": "",
"Failed to copy {0} to {1}": "",
"{0} location": "",
"Choose a location to create the {0}": "",
"Name of file or directory": "",
Expand Down
Loading
Loading