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

Commit

Permalink
addres PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: zFernand0 <[email protected]>
  • Loading branch information
zFernand0 committed Jul 5, 2023
1 parent 9571e98 commit c248e16
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All notable changes to the Imperative package will be documented in this file.

- Enhancement: Handled unique cookie identifier in the form of dynamic token types. [#966](https://github.com/zowe/imperative/pull/996)
- Enhancement: Added a new utility method to `ImperativeExpect` to match regular expressions. [#966](https://github.com/zowe/imperative/pull/996)
- Enhancement: Added support for mutliple login operations in a single `config secure` command execution. [#966](https://github.com/zowe/imperative/pull/996)
- Enhancement: Added support for multiple login operations in a single `config secure` command execution. [#966](https://github.com/zowe/imperative/pull/996)
- BugFix: Allowed for multiple `auth logout` operations. [#966](https://github.com/zowe/imperative/pull/996)
- BugFix: Prevented `auto-init` from sending two `login` requests to the server. [#966](https://github.com/zowe/imperative/pull/996)

Expand Down
21 changes: 19 additions & 2 deletions packages/config/__tests__/ConfigAutoStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ describe("ConfigAutoStore tests", () => {
expect(authHandler instanceof AbstractAuthHandler).toBe(true);
});

it("should be able to find auth handler for base profile with a dynamic token type", async () => {
it("should be able to find auth handler for base profile with a dynamic APIML token type", async () => {
await setupConfigToLoad({
profiles: {
base: {
type: "base",
properties: {
tokenType: SessConstants.TOKEN_TYPE_JWT + ".1"
tokenType: SessConstants.TOKEN_TYPE_APIML + ".1"
}
}
},
Expand All @@ -85,6 +85,23 @@ describe("ConfigAutoStore tests", () => {
expect(authHandler instanceof AbstractAuthHandler).toBe(true);
});

it("should not be able to find auth handler for base profile with a dynamic JWT token type", async () => {
await setupConfigToLoad({
profiles: {
base: {
type: "base",
properties: {
tokenType: SessConstants.TOKEN_TYPE_JWT + ".1"
}
}
},
defaults: { base: "base" }
});

const authHandler = ConfigAutoStore.findAuthHandlerForProfile("profiles.base", {} as any);
expect(authHandler).toBeUndefined();
});

it("should be able to find auth handler for service profile", async () => {
await setupConfigToLoad({
profiles: {
Expand Down
9 changes: 5 additions & 4 deletions packages/config/src/ConfigAutoStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
IConfigAutoStoreFindAuthHandlerForProfileOpts,
IConfigAutoStoreStoreSessCfgPropsOpts
} from "./doc/IConfigAutoStoreOpts";
import { TOKEN_TYPE_APIML } from "../../rest/src/session/SessConstants";

/**
* Class to manage automatic storage of properties in team config.
Expand Down Expand Up @@ -89,7 +90,7 @@ export class ConfigAutoStore {
return;
} else if (profile.tokenType == null) { // If tokenType undefined in service profile, fall back to base profile
const baseProfileName = ConfigUtils.getActiveProfileName("base", opts.cmdArguments, opts.defaultBaseProfileName);
return this._findAuthHandlerForProfile({ ...opts, profilePath: config.api.profiles.expandPath(baseProfileName) });
return this._findAuthHandlerForProfile({ ...opts, profilePath: config.api.profiles.getProfilePathFromName(baseProfileName) });
}
}

Expand All @@ -106,7 +107,7 @@ export class ConfigAutoStore {

if (authHandlerClass instanceof AbstractAuthHandler) {
const { promptParams } = authHandlerClass.getAuthHandlerApi();
if (profile.tokenType.startsWith(promptParams.defaultTokenType)) {
if (profile.tokenType === promptParams.defaultTokenType || profile.tokenType.startsWith(TOKEN_TYPE_APIML)) {
return authHandlerClass; // Auth service must have matching token type
}
}
Expand Down Expand Up @@ -140,7 +141,7 @@ export class ConfigAutoStore {
return;
}
const [profileType, profileName] = profileData ?? [opts.profileType, opts.profileName];
const profilePath = config.api.profiles.expandPath(profileName);
const profilePath = config.api.profiles.getProfilePathFromName(profileName);

// Replace user and password with tokenValue if tokenType is defined in config
if (profileProps.includes("user") && profileProps.includes("password") && await this._fetchTokenForSessCfg({ ...opts, profilePath })) {
Expand Down Expand Up @@ -179,7 +180,7 @@ export class ConfigAutoStore {
(propName === "tokenValue" && profileObj.tokenType == null && baseProfileObj.tokenType != null ||
profileType === "base")
) {
propProfilePath = config.api.profiles.expandPath(baseProfileName);
propProfilePath = config.api.profiles.getProfilePathFromName(baseProfileName);
isSecureProp = baseProfileSchema.properties[propName].secure || baseProfileSecureProps.includes(propName);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/ProfileInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export class ProfileInfo {
const foundProfNm = configProperties.defaults[profileType];

// for a team config, we use the last node of the jsonLoc as the name
const foundJson = this.mLoadedConfig.api.profiles.expandPath(foundProfNm);
const foundJson = this.mLoadedConfig.api.profiles.getProfilePathFromName(foundProfNm);
const teamOsLocation: string[] = this.findTeamOsLocation(foundJson);

// assign the required poperties to defaultProfile
Expand Down Expand Up @@ -1330,7 +1330,7 @@ export class ProfileInfo {
* @param opts Set of options that allow this method to get the profile location
*/
private argTeamConfigLoc(opts: IArgTeamConfigLoc): [IProfLoc, boolean] {
const segments = this.mLoadedConfig.api.profiles.expandPath(opts.profileName).split(".profiles.");
const segments = this.mLoadedConfig.api.profiles.getProfilePathFromName(opts.profileName).split(".profiles.");
let osLocInfo: IProfLocOsLocLayer;
if (opts.osLocInfo?.user != null || opts.osLocInfo?.global != null)
osLocInfo = { user: opts.osLocInfo?.user, global: opts.osLocInfo?.global };
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/api/ConfigLayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class ConfigLayers extends ConfigApi {
* @returns User and global properties, or undefined if profile does not exist
*/
public find(profileName: string): { user: boolean, global: boolean } {
const profilePath = this.mConfig.api.profiles.expandPath(profileName);
const profilePath = this.mConfig.api.profiles.getProfilePathFromName(profileName);
for (const layer of this.mConfig.layers) {
if (lodash.get(layer.properties, profilePath) != null) {
return layer;
Expand Down
13 changes: 13 additions & 0 deletions packages/config/src/api/ConfigProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,21 @@ export class ConfigProfiles extends ConfigApi {
*
* @returns The expanded path.
*
* @deprecated Please use getProfilePathFromName
*/
public expandPath(shortPath: string): string {
return this.getProfilePathFromName(shortPath);
}

// _______________________________________________________________________
/**
* Expands a short path into an expanded path.
*
* @param shortPath The short path.
*
* @returns The expanded path.
*/
public getProfilePathFromName(shortPath: string): string {
return shortPath.replace(/(^|\.)/g, "$1profiles.");
}

Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/api/ConfigSecure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class ConfigSecure extends ConfigApi {
* @returns Array of secure property names
*/
public securePropsForProfile(profileName: string) {
const profilePath = this.mConfig.api.profiles.expandPath(profileName);
const profilePath = this.mConfig.api.profiles.getProfilePathFromName(profileName);
const secureProps = [];
for (const propPath of this.secureFields()) {
const pathSegments = propPath.split("."); // profiles.XXX.properties.YYY
Expand Down
4 changes: 2 additions & 2 deletions packages/imperative/src/auth/handlers/BaseAuthHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export abstract class BaseAuthHandler extends AbstractAuthHandler {
}
}

const profilePath = config.api.profiles.expandPath(profileName);
const profilePath = config.api.profiles.getProfilePathFromName(profileName);
config.set(`${profilePath}.properties.tokenType`, this.mSession.ISession.tokenType);
config.set(`${profilePath}.properties.tokenValue`, tokenValue, { secure: true });

Expand Down Expand Up @@ -237,7 +237,7 @@ export abstract class BaseAuthHandler extends AbstractAuthHandler {
// If you specified a token on the command line, then don't delete the one in the profile if it doesn't match
if (Object.keys(profileProps).length > 0 && profileProps.tokenType != null && profileProps.tokenValue != null &&
profileProps.tokenType === params.arguments.tokenType && profileProps.tokenValue === params.arguments.tokenValue) {
const profilePath = config.api.profiles.expandPath(profileName);
const profilePath = config.api.profiles.getProfilePathFromName(profileName);
config.delete(`${profilePath}.properties.tokenType`);
config.delete(`${profilePath}.properties.tokenValue`);

Expand Down

0 comments on commit c248e16

Please sign in to comment.