Skip to content

Commit

Permalink
Merge branch 'main' into refactor/expose-local-storage
Browse files Browse the repository at this point in the history
Signed-off-by: Trae Yelovich <[email protected]>
  • Loading branch information
traeok committed Nov 13, 2024
2 parents 9032a62 + 6784053 commit 6f97044
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 71 deletions.
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}"],
"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 @@ -24,6 +24,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)
- Fixed issue where persistent settings defined at the workspace level were migrated into global storage rather than workspace-specific storage. [#3180](https://github.com/zowe/zowe-explorer-vscode/issues/3180)

## `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
7 changes: 3 additions & 4 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. This is typically the case when running in container-based environments or Linux systems that miss required security libraries or user permissions.": "Default Zowe credentials manager not found on current platform. This is typically the case when running in container-based environments or Linux systems that miss required security libraries or user permissions.",
"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
7 changes: 3 additions & 4 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. This is typically the case when running in container-based environments or Linux systems that miss required security libraries or user permissions.": "",
"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
Loading

0 comments on commit 6f97044

Please sign in to comment.