Skip to content

Commit

Permalink
Fix profileManagerWillLoad failing before read from disk
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <[email protected]>
  • Loading branch information
t1m0thyj committed Oct 18, 2024
1 parent 820caed commit 04fdf7e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/imperative/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to the Imperative package will be documented in this file.

## Recent Changes

- BugFix: Fixed an issue where the `ProfileInfo.profileManagerWillLoad` method failed if profiles were not yet read from disk. [#2284](https://github.com/zowe/zowe-cli/issues/2284)
- BugFix: Fixed an issue where the `ProfileInfo.onlyV1ProfilesExist` method could wrongly return true when V2 profiles exist. [#2311](https://github.com/zowe/zowe-cli/issues/2311)
- Deprecated the static method `ProfileInfo.onlyV1ProfilesExist` and replaced it with an `onlyV1ProfilesExist` instance method on the `ProfileInfo` class.
- BugFix: Fixed an issue where the `ConvertV1Profiles.convert` method may create team configuration files in the wrong directory if the environment variable `ZOWE_CLI_HOME` is set. [#2312](https://github.com/zowe/zowe-cli/issues/2312)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ describe("TeamConfig ProfileInfo tests", () => {
describe("profileManagerWillLoad", () => {
it("should return false if secure credentials fail to load", async () => {
const profInfo = createNewProfInfo(teamProjDir);
jest.spyOn((profInfo as any).mCredentials, "isSecured", "get").mockReturnValueOnce(true);
jest.spyOn((profInfo as any).mCredentials, "isCredentialManagerInAppSettings").mockReturnValueOnce(true);
jest.spyOn((profInfo as any).mCredentials, "loadManager").mockImplementationOnce(async () => {
throw new Error("bad credential manager");
});
Expand All @@ -336,10 +336,10 @@ describe("TeamConfig ProfileInfo tests", () => {
expect(response).toEqual(true);
});

it("should return true if credentials are not secure", async () => {
it("should return true if there is no credential manager", async () => {
// ensure that we are not in the team project directory
const profInfo = createNewProfInfo(origDir);
(profInfo as any).mCredentials = { isSecured: false };
jest.spyOn((profInfo as any).mCredentials, "isCredentialManagerInAppSettings").mockReturnValueOnce(false);
const response = await profInfo.profileManagerWillLoad();
expect(response).toEqual(true);
});
Expand Down
9 changes: 5 additions & 4 deletions packages/imperative/src/config/src/ProfileCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export class ProfileCredentials {

/**
* Check if secure credentials will be encrypted or stored in plain text.
* If using team config, this will always return true. If using classic
* profiles, this will check whether a custom CredentialManager is defined
* in the Imperative settings.json file.
* This will return true if the team configuration files contain secure
* fields, or if a custom CredentialManager is defined in the Imperative
* settings.json file.
*/
public get isSecured(): boolean {
this.mSecured = this.isTeamConfigSecure() || this.isCredentialManagerInAppSettings();
Expand Down Expand Up @@ -109,8 +109,9 @@ export class ProfileCredentials {
/**
* Check whether a custom CredentialManager is defined in the Imperative
* settings.json file.
* @internal
*/
private isCredentialManagerInAppSettings(): boolean {
public isCredentialManagerInAppSettings(): boolean {
try {
const fileName = path.join(ImperativeConfig.instance.cliHome, "settings", "imperative.json");
let settings: any;
Expand Down
8 changes: 5 additions & 3 deletions packages/imperative/src/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -885,11 +885,13 @@ export class ProfileInfo {

//_________________________________________________________________________
/**
* Function to ensure the credential manager will load successfully
* Returns true if it will load, or the credentials are not secured. Returns false if it will not load.
* Checks whether the credential manager will load successfully.
* @returns
* True if it loaded successfully, or there is no credential manager
* configured in Imperative settings.json
*/
public async profileManagerWillLoad(): Promise<boolean> {
if (this.mCredentials.isSecured) {
if (this.mCredentials.isCredentialManagerInAppSettings()) {
try {
await this.mCredentials.loadManager();
return true;
Expand Down

0 comments on commit 04fdf7e

Please sign in to comment.