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

fix(profiles): Pass homeDir, projectDir when creating ProfileInfo instance #3169

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
### Bug fixes

- Fixed an issue where opening sequential data sets within favorited searches resulted in an error. [#3163](https://github.com/zowe/zowe-explorer-vscode/pull/3163)
- Fixed an issue where Zowe Explorer displayed a "No Zowe client configurations" prompt when a project user configuration existed but no global configuration was present. [#3168](https://github.com/zowe/zowe-explorer-vscode/issues/3168)
- Fixed an issue where the `ProfilesUtils.getProfileInfo` function returned a new `ProfileInfo` instance that ignored the `ZOWE_CLI_HOME` environment variable and workspace paths. [#3168](https://github.com/zowe/zowe-explorer-vscode/issues/3168)

## `3.0.0`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as fs from "fs";
import * as path from "path";
import * as util from "util";
import * as vscode from "vscode";
import { Gui, imperative, ProfilesCache, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import { FileManagement, Gui, imperative, ProfilesCache, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import { createAltTypeIProfile, createInstanceOfProfile, createValidIProfile } from "../../__mocks__/mockCreators/shared";
import { MockedProperty } from "../../__mocks__/mockUtils";
import { Constants } from "../../../src/configuration/Constants";
Expand Down Expand Up @@ -248,6 +248,7 @@ describe("ProfilesUtils unit tests", () => {
value: [
{
uri: {
scheme: "file",
fsPath: "./test",
},
},
Expand Down Expand Up @@ -1314,4 +1315,15 @@ describe("ProfilesUtils unit tests", () => {
onlyV1ProfsExistMock[Symbol.dispose]();
});
});

describe("setupDefaultCredentialManager", () => {
it("calls readProfilesFromDisk with homeDir and projectDir", async () => {
const readProfilesFromDiskMock = jest.spyOn(imperative.ProfileInfo.prototype, "readProfilesFromDisk").mockImplementation();
await ProfilesUtils.setupDefaultCredentialManager();
expect(readProfilesFromDiskMock).toHaveBeenCalledWith({
homeDir: FileManagement.getZoweDir(),
projectDir: vscode.workspace.workspaceFolders?.[0].uri.fsPath,
});
});
});
});
7 changes: 6 additions & 1 deletion packages/zowe-explorer/src/utils/ProfilesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,13 @@ export class ProfilesUtils {
const profileInfo = new imperative.ProfileInfo("zowe", {
credMgrOverride: defaultCredentialManager,
});

const workspacePath = ZoweVsCodeExtension.workspaceRoot?.uri.fsPath;
// Trigger initialize() function of credential manager to throw an error early if failed to load
await profileInfo.readProfilesFromDisk();
await profileInfo.readProfilesFromDisk({
homeDir: FileManagement.getZoweDir(),
projectDir: workspacePath ? FileManagement.getFullPath(workspacePath) : undefined,
});
return profileInfo;
} catch (err) {
if (err instanceof imperative.ProfInfoErr && err.errorCode === imperative.ProfInfoErr.LOAD_CRED_MGR_FAILED) {
Expand Down
Loading