From 22b55e166003c49904c129d7a0ecdba4ce62a3a4 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Mon, 28 Aug 2023 17:57:21 -0400 Subject: [PATCH] Fix merging of profile properties in ProfileInfo.createSession Signed-off-by: Timothy Johnson --- CHANGELOG.md | 4 ++++ .../__tests__/ProfileInfo.TeamConfig.test.ts | 13 +++++++++++++ packages/config/src/ProfileInfo.ts | 17 ++++++++++++----- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c404bfa8..7841e629a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the Imperative package will be documented in this file. +## Recent Changes + +- BugFix: Fixed merging of profile properties in `ProfileInfo.createSession`. [#1008](https://github.com/zowe/imperative/issues/1008) + ## `5.18.0` - Enhancement: Replaced use of `node-keytar` with the new `keyring` module from `@zowe/secrets-for-zowe-sdk`. [zowe-cli#1622](https://github.com/zowe/zowe-cli/issues/1622) diff --git a/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts b/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts index cd05cc12a..1042b5a53 100644 --- a/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts +++ b/packages/config/__tests__/ProfileInfo.TeamConfig.test.ts @@ -187,6 +187,18 @@ describe("TeamConfig ProfileInfo tests", () => { locType: ProfLocType.TEAM_CONFIG }, }, + { + argName: "tokenType", dataType: "string", argValue: SessConstants.TOKEN_TYPE_JWT, + argLoc: { + locType: ProfLocType.TEAM_CONFIG + }, + }, + { + argName: "tokenValue", dataType: "string", argValue: "testToken", + argLoc: { + locType: ProfLocType.TEAM_CONFIG + }, + }, ]; it("should create a session", async () => { @@ -201,6 +213,7 @@ describe("TeamConfig ProfileInfo tests", () => { expect(newSess.ISession.secureProtocol).toBe(AbstractSession.DEFAULT_SECURE_PROTOCOL); expect(newSess.ISession.basePath).toBe(AbstractSession.DEFAULT_BASE_PATH); expect(newSess.ISession.base64EncodedAuth).toBe(b64TestAuth); + // Auth token should be undefined because user and password takes precedence expect(newSess.ISession.tokenType).toBeUndefined(); expect(newSess.ISession.tokenValue).toBeUndefined(); }); diff --git a/packages/config/src/ProfileInfo.ts b/packages/config/src/ProfileInfo.ts index 0e1f3a197..6d15c63a3 100644 --- a/packages/config/src/ProfileInfo.ts +++ b/packages/config/src/ProfileInfo.ts @@ -555,11 +555,15 @@ export class ProfileInfo { profArgs: IProfArgAttrs[], connOpts: IOptionsForAddConnProps = {} ): Session { - // initialize a session config with arguments from profile arguments - const sessCfg: ISession = ProfileInfo.initSessCfg(profArgs); + // Initialize a session config with values from profile arguments + const sessCfg: ISession = ProfileInfo.initSessCfg(profArgs, + ["rejectUnauthorized", "basePath", "protocol"]); - // we have no command arguments, so just supply an empty object + // Populate command arguments object with arguments to be resolved const cmdArgs: ICommandArguments = { $0: "", _: [] }; + for (const { argName, argValue } of profArgs) { + cmdArgs[argName] = argValue; + } // resolve the choices among various session config properties ConnectionPropsForSessCfg.resolveSessCfgProps(sessCfg, cmdArgs, connOpts); @@ -1061,15 +1065,18 @@ export class ProfileInfo { * * @param profArgs * An array of profile argument attributes. + * @param argNames + * An array of argument names to load from the profile. Defaults to + * all arguments that have an associated ISession property. * * @returns A session containing all of the supplied profile argument * attributes that are relevant to a session. */ - public static initSessCfg(profArgs: IProfArgAttrs[]): ISession { + public static initSessCfg(profArgs: IProfArgAttrs[], argNames?: string[]): ISession { const sessCfg: any = {}; // the set of names of arguments in IProfArgAttrs used in ISession - const profArgNames = [ + const profArgNames = argNames ?? [ "host", "port", "user", "password", "rejectUnauthorized", "protocol", "basePath", "tokenType", "tokenValue" ];