Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Fix merging of profile properties in ProfileInfo.createSession #1010

Merged
merged 1 commit into from
Aug 29, 2023
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions packages/config/__tests__/ProfileInfo.TeamConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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();
});
Expand Down
17 changes: 12 additions & 5 deletions packages/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
];
Expand Down