From 18a449100d1aa0c3772ae3167638286736b1f788 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 23 Jun 2023 15:10:59 +0000 Subject: [PATCH 01/29] Allow for variable APIML token types Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/src/apiml/Services.ts | 4 ++-- packages/core/src/auth/Login.ts | 4 ++-- packages/core/src/auth/Logout.ts | 4 ++-- packages/core/src/constants/Core.constants.ts | 5 ++++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/core/src/apiml/Services.ts b/packages/core/src/apiml/Services.ts index 8c96bd87ab..9ab64caa42 100644 --- a/packages/core/src/apiml/Services.ts +++ b/packages/core/src/apiml/Services.ts @@ -82,8 +82,8 @@ export class Services { ImperativeExpect.toNotBeNullOrUndefined(session.ISession.user, "User name for API ML basic login must be defined."); ImperativeExpect.toNotBeNullOrUndefined(session.ISession.password, "Password for API ML basic login must be defined."); } else { - ImperativeExpect.toBeEqual(session.ISession.tokenType, "apimlAuthenticationToken", - "Token type for API ML token login must be apimlAuthenticationToken."); + ImperativeExpect.toMatchRegExp(session.ISession.tokenType, "^apimlAuthenticationToken.*", + `Token type (${session.ISession.tokenType}) for API ML token login must start with 'apimlAuthenticationToken'.`); ImperativeExpect.toNotBeNullOrUndefined(session.ISession.tokenValue, "Token value for API ML token login must be defined."); } diff --git a/packages/core/src/auth/Login.ts b/packages/core/src/auth/Login.ts index ae70efdbc6..278d614ae4 100644 --- a/packages/core/src/auth/Login.ts +++ b/packages/core/src/auth/Login.ts @@ -30,8 +30,8 @@ export class Login { public static async apimlLogin(session: AbstractSession) { Logger.getAppLogger().trace("Login.login()"); ImperativeExpect.toNotBeNullOrUndefined(session, "Required session must be defined"); - ImperativeExpect.toBeEqual(session.ISession.tokenType, "apimlAuthenticationToken", - "Token type for API ML login must be apimlAuthenticationToken."); + ImperativeExpect.toMatchRegExp(session.ISession.tokenType, "^apimlAuthenticationToken.*", + `Token type (${session.ISession.tokenType}) for API ML token login must start with 'apimlAuthenticationToken'.`); const client = new ZosmfRestClient(session); await client.request({ diff --git a/packages/core/src/auth/Logout.ts b/packages/core/src/auth/Logout.ts index 663df90d45..592768e190 100644 --- a/packages/core/src/auth/Logout.ts +++ b/packages/core/src/auth/Logout.ts @@ -30,8 +30,8 @@ export class Logout { public static async apimlLogout(session: AbstractSession) { Logger.getAppLogger().trace("Logout.logout()"); ImperativeExpect.toNotBeNullOrUndefined(session, "Required session must be defined"); - ImperativeExpect.toBeEqual(session.ISession.tokenType, "apimlAuthenticationToken", - "Token type for API ML logout must be apimlAuthenticationToken."); + ImperativeExpect.toMatchRegExp(session.ISession.tokenType, "^apimlAuthenticationToken.*", + `Token type (${session.ISession.tokenType}) for API ML logout must start with 'apimlAuthenticationToken'.`); ImperativeExpect.toNotBeNullOrUndefined(session.ISession.tokenValue, "Session token not populated. Unable to log out."); const client = new ZosmfRestClient(session); diff --git a/packages/core/src/constants/Core.constants.ts b/packages/core/src/constants/Core.constants.ts index e897442daa..e48ea39ecb 100644 --- a/packages/core/src/constants/Core.constants.ts +++ b/packages/core/src/constants/Core.constants.ts @@ -311,7 +311,10 @@ export class ProfileConstants { */ public static readonly APIML_LOGOUT_OPTION_TOKEN_TYPE: ICommandOptionDefinition = { ...ProfileConstants.BASE_OPTION_TOKEN_TYPE, - allowableValues: { values: SessConstants.ALL_TOKEN_TYPES } + allowableValues: { + values: SessConstants.ALL_TOKEN_TYPES + .map(tk => tk.indexOf(SessConstants.TOKEN_TYPE_APIML) >= 0 ? `^${SessConstants.TOKEN_TYPE_APIML}.*` : tk) + } }; /** From 38d495a787a8ece76f2536e245c796f13a5601ee Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:46:43 +0000 Subject: [PATCH 02/29] prevent basepath requirement error on invalid credentials for zowe auth login Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/src/auth/Login.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/core/src/auth/Login.ts b/packages/core/src/auth/Login.ts index 278d614ae4..a8b692b5eb 100644 --- a/packages/core/src/auth/Login.ts +++ b/packages/core/src/auth/Login.ts @@ -34,6 +34,9 @@ export class Login { `Token type (${session.ISession.tokenType}) for API ML token login must start with 'apimlAuthenticationToken'.`); const client = new ZosmfRestClient(session); + if(!session.ISession.basePath) { + session.ISession.basePath = "/"; // prevent basepath requirement error on invalid credentials + } await client.request({ request: "POST", resource: LoginConstants.APIML_V1_RESOURCE From f67b7ae8e6a61fa19ba869b6c95d5649d9f80432 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Mon, 26 Jun 2023 14:47:55 +0000 Subject: [PATCH 03/29] allow v2 logout with expired or invalid token Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/src/auth/Logout.ts | 6 +++--- packages/core/src/auth/LogoutConstants.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/core/src/auth/Logout.ts b/packages/core/src/auth/Logout.ts index 592768e190..fe7aff140f 100644 --- a/packages/core/src/auth/Logout.ts +++ b/packages/core/src/auth/Logout.ts @@ -25,7 +25,7 @@ export class Logout { * @static * @param {AbstractSession} session * @returns - * @memberof Login + * @memberof Logout */ public static async apimlLogout(session: AbstractSession) { Logger.getAppLogger().trace("Logout.logout()"); @@ -41,12 +41,12 @@ export class Logout { resource: LogoutConstants.APIML_V1_RESOURCE }); } catch (err) { - if (!err.message.includes(LogoutConstants.APIML_V1_TOKEN_EXP_ERR)) { + if (!err.message.includes(LogoutConstants.APIML_V1_TOKEN_EXP_ERR) && !err.message.includes(LogoutConstants.APIML_V2_TOKEN_EXP_ERR)) { throw err; } } - if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { + if (client.response.statusCode !== RestConstants.HTTP_STATUS_204 && client.response.statusCode !== RestConstants.HTTP_STATUS_401) { if (!(client.response.statusCode === RestConstants.HTTP_STATUS_500 && client.dataString.includes(LogoutConstants.APIML_V1_TOKEN_EXP_ERR))) { throw new ImperativeError((client as any).populateError({ diff --git a/packages/core/src/auth/LogoutConstants.ts b/packages/core/src/auth/LogoutConstants.ts index edc4d63598..2e96dbaede 100644 --- a/packages/core/src/auth/LogoutConstants.ts +++ b/packages/core/src/auth/LogoutConstants.ts @@ -34,4 +34,12 @@ export class LogoutConstants { */ public static readonly APIML_V1_TOKEN_EXP_ERR: string = "TokenExpireException"; + /** + * Zowe Token Expired Error Code + * @static + * @type {string} + * @memberof LogoutConstants + */ + public static readonly APIML_V2_TOKEN_EXP_ERR: string = "org.zowe.apiml.security.query."; + } From 337b35f607ca02ae35fd99e020e8978a40f674f9 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Mon, 26 Jun 2023 20:04:18 +0000 Subject: [PATCH 04/29] make the list of acceptable responses more flexible Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/src/auth/Logout.ts | 8 +++++++- packages/core/src/auth/LogoutConstants.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/core/src/auth/Logout.ts b/packages/core/src/auth/Logout.ts index fe7aff140f..10e34f7e46 100644 --- a/packages/core/src/auth/Logout.ts +++ b/packages/core/src/auth/Logout.ts @@ -41,7 +41,13 @@ export class Logout { resource: LogoutConstants.APIML_V1_RESOURCE }); } catch (err) { - if (!err.message.includes(LogoutConstants.APIML_V1_TOKEN_EXP_ERR) && !err.message.includes(LogoutConstants.APIML_V2_TOKEN_EXP_ERR)) { + let shouldThrow = true; + LogoutConstants.APIML_V2_LOGOUT_ERR_LIST.forEach((errorKey: string) => { + if (err.message.includes(errorKey)) { + shouldThrow = false; + } + }); + if (shouldThrow) { throw err; } } diff --git a/packages/core/src/auth/LogoutConstants.ts b/packages/core/src/auth/LogoutConstants.ts index 2e96dbaede..9b631c8318 100644 --- a/packages/core/src/auth/LogoutConstants.ts +++ b/packages/core/src/auth/LogoutConstants.ts @@ -35,11 +35,15 @@ export class LogoutConstants { public static readonly APIML_V1_TOKEN_EXP_ERR: string = "TokenExpireException"; /** - * Zowe Token Expired Error Code + * Zowe Token Expired Error Codes * @static * @type {string} * @memberof LogoutConstants */ - public static readonly APIML_V2_TOKEN_EXP_ERR: string = "org.zowe.apiml.security.query."; - + public static readonly APIML_V2_LOGOUT_ERR_LIST: string[] = [ + LogoutConstants.APIML_V1_TOKEN_EXP_ERR, + "org.zowe.apiml.security.expiredToken", + "org.zowe.apiml.security.query.invalidToken", + "org.zowe.apiml.security.query.tokenNotProvided", + ]; } From f6625d48708f794fa3de3d711862b5a69664224d Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 30 Jun 2023 12:32:03 +0000 Subject: [PATCH 05/29] important: not throwing 401 errors on logout Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../auth/__unit__/Logout.apiml.unit.test.ts | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts index 7989ed125c..70e65749a5 100644 --- a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts +++ b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts @@ -69,7 +69,20 @@ describe("Auth Logout APIML unit tests", () => { }); describe("Error handling tests - HTTP 401", () => { - it("should be able to raise an error with HTTP 401", async () => { + // it("should be able to raise an error with HTTP 401", async () => { + // ZosmfRestClient.prototype.request = jest.fn(); + // (ZosmfRestClient.prototype as any).mResponse = badResponse401; + // let caughtError; + // try{ + // await Logout.apimlLogout(fakeSession); + // } catch (error) { + // caughtError = error; + // } + // expect(caughtError).toBeDefined(); + // expect(caughtError instanceof ImperativeError).toEqual(true); + // expect(caughtError.mDetails).toMatchSnapshot(); + // }); + it("should not throw an error with HTTP 401", async () => { ZosmfRestClient.prototype.request = jest.fn(); (ZosmfRestClient.prototype as any).mResponse = badResponse401; let caughtError; @@ -78,19 +91,7 @@ describe("Auth Logout APIML unit tests", () => { } catch (error) { caughtError = error; } - expect(caughtError).toBeDefined(); - expect(caughtError instanceof ImperativeError).toEqual(true); - expect(caughtError.mDetails.message).toContain("This operation requires authentication."); - expect(caughtError.mDetails.message).toContain("z/OSMF REST API Error:"); - expect(caughtError.mDetails.message).toContain("REST API Failure with HTTP(S) status 401"); - expect(caughtError.mDetails.message).toContain("Host: undefined"); - expect(caughtError.mDetails.message).toContain("Port: undefined"); - expect(caughtError.mDetails.additionalDetails).toContain("HTTP(S) error status \"401\" received."); - expect(caughtError.mDetails.additionalDetails).toContain( - "Review request details (resource, base path, credentials, payload) and ensure correctness." - ); - expect(caughtError.mDetails.additionalDetails).toContain("Host: undefined"); - expect(caughtError.mDetails.additionalDetails).toContain("Port: undefined"); + expect(caughtError).toBeUndefined(); }); }); From 23026836df91ef0b58c7c61a5ec1c6c690d43cda Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 30 Jun 2023 12:32:44 +0000 Subject: [PATCH 06/29] fix other unit tests and make sure we go back to undefined for basepath='/' Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts | 2 +- packages/core/__tests__/apiml/__unit__/Services.unit.test.ts | 2 +- packages/core/src/auth/Login.ts | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index 6449a1a2de..d692cba23f 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -78,7 +78,7 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { session.ISession.tokenValue = await Login.apimlLogin(session); session.ISession.storeCookie = false; session.ISession.type = SessConstants.AUTH_TYPE_TOKEN; - session.ISession.user = session.ISession.password = session.ISession.cert = session.ISession.certKey = undefined; + session.ISession.base64EncodedAuth = session.ISession.user = session.ISession.password = session.ISession.cert = session.ISession.certKey = undefined; } const restErrUnauthorized = 403; diff --git a/packages/core/__tests__/apiml/__unit__/Services.unit.test.ts b/packages/core/__tests__/apiml/__unit__/Services.unit.test.ts index ef7d4ea532..e6f4be7b6a 100644 --- a/packages/core/__tests__/apiml/__unit__/Services.unit.test.ts +++ b/packages/core/__tests__/apiml/__unit__/Services.unit.test.ts @@ -163,7 +163,7 @@ describe("APIML Services unit tests", () => { } expect(caughtError).toBeDefined(); - expect(caughtError.message).toContain("Token type for API ML token login must be apimlAuthenticationToken."); + expect(caughtError.message).toContain("Token type (fakeToken) for API ML token login must start with 'apimlAuthenticationToken'."); }); it("should require token value for token sessions", async () => { diff --git a/packages/core/src/auth/Login.ts b/packages/core/src/auth/Login.ts index a8b692b5eb..92a8c3f565 100644 --- a/packages/core/src/auth/Login.ts +++ b/packages/core/src/auth/Login.ts @@ -43,6 +43,9 @@ export class Login { }); if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { + if (session.ISession.basePath === "/") { + session.ISession.basePath = undefined; + } throw new ImperativeError((client as any).populateError({ msg: `REST API Failure with HTTP(S) status ${client.response.statusCode}`, causeErrors: client.dataString, From 17d4bc4e26594bf279d5a1849fcf9b5cb7c373e0 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 30 Jun 2023 13:02:19 +0000 Subject: [PATCH 07/29] remove http401 error testing for logout Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../auth/__unit__/Logout.apiml.unit.test.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts index 70e65749a5..1a03c47214 100644 --- a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts +++ b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts @@ -69,19 +69,6 @@ describe("Auth Logout APIML unit tests", () => { }); describe("Error handling tests - HTTP 401", () => { - // it("should be able to raise an error with HTTP 401", async () => { - // ZosmfRestClient.prototype.request = jest.fn(); - // (ZosmfRestClient.prototype as any).mResponse = badResponse401; - // let caughtError; - // try{ - // await Logout.apimlLogout(fakeSession); - // } catch (error) { - // caughtError = error; - // } - // expect(caughtError).toBeDefined(); - // expect(caughtError instanceof ImperativeError).toEqual(true); - // expect(caughtError.mDetails).toMatchSnapshot(); - // }); it("should not throw an error with HTTP 401", async () => { ZosmfRestClient.prototype.request = jest.fn(); (ZosmfRestClient.prototype as any).mResponse = badResponse401; From 49f6ef408131dbdb58078107321f5280e27ba0c9 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 30 Jun 2023 13:21:42 +0000 Subject: [PATCH 08/29] update snapshots Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap b/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap index 5c7c71b7ad..afa01c4a7f 100644 --- a/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap +++ b/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap @@ -2,4 +2,4 @@ exports[`LoginConstants Unit Test Should not have changed 1`] = `"{\\"APIML_V1_RESOURCE\\":\\"/gateway/api/v1/auth/login\\"}"`; -exports[`LogoutConstants Unit Test Should not have changed 1`] = `"{\\"APIML_V1_RESOURCE\\":\\"/gateway/api/v1/auth/logout\\",\\"APIML_V1_TOKEN_EXP_ERR\\":\\"TokenExpireException\\"}"`; +exports[`LogoutConstants Unit Test Should not have changed 1`] = `"{\\"APIML_V1_RESOURCE\\":\\"/gateway/api/v1/auth/logout\\",\\"APIML_V1_TOKEN_EXP_ERR\\":\\"TokenExpireException\\",\\"APIML_V2_LOGOUT_ERR_LIST\\":[\\"TokenExpireException\\",\\"org.zowe.apiml.security.expiredToken\\",\\"org.zowe.apiml.security.query.invalidToken\\",\\"org.zowe.apiml.security.query.tokenNotProvided\\"]}"`; From 20f8049820b2d3de4399d0276454304b60afd7a5 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 30 Jun 2023 13:36:50 +0000 Subject: [PATCH 09/29] update changelog Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/cli/CHANGELOG.md | 8 ++++++++ packages/core/CHANGELOG.md | 1 + 2 files changed, 9 insertions(+) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index a8ac362d9f..e49870eb60 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to the Zowe CLI package will be documented in this file. +## Recent changes + +- Enhancement: Updated the Imperative Framework to add support for unique cookie identifiers from API ML. [#1734](https://github.com/zowe/zowe-cli/pull/1734) +- Enhancement: Added support for mutliple `zowe auth login apiml` operations on a single `zowe config secure` call. [#1734](https://github.com/zowe/zowe-cli/pull/1734) +- BugFix: Allowed `logout` operations with invalid and/or expired tokens. [#1734](https://github.com/zowe/zowe-cli/pull/1734) +- BugFix: Prevented misleading `basePath error` when credentials are invalid. [#1734](https://github.com/zowe/zowe-cli/pull/1734) +- BugFix: Add check for invalid block size when creating a sequential dataset. [#1439](https://github.com/zowe/zowe-cli/issues/1439) + ## `7.16.5` - BugFix: Fixed `zowe files create data-set` failing when no additional options are specified. diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index f853cf3c57..a38f92d93c 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to the Zowe core SDK package will be documented in this file ## Recent Changes +- Enhancement: Added support for dynamic APIML tokens. [#1734](https://github.com/zowe/zowe-cli/pull/1734) - Enhancement: Set properties for z/OSMF REST errors for use in a more user-friendly format with the ZOWE_V3_ERR_FORMAT environment variable. [zowe-cli#935](https://github.com/zowe/zowe-cli/issues/935) - ## `7.16.5` From 2193a436e24b60f821008d19ca69891b8bae8120 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Tue, 11 Jul 2023 16:52:20 +0000 Subject: [PATCH 10/29] fix lint issue Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index d692cba23f..3144e9dcee 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -78,7 +78,10 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { session.ISession.tokenValue = await Login.apimlLogin(session); session.ISession.storeCookie = false; session.ISession.type = SessConstants.AUTH_TYPE_TOKEN; - session.ISession.base64EncodedAuth = session.ISession.user = session.ISession.password = session.ISession.cert = session.ISession.certKey = undefined; + + session.ISession.base64EncodedAuth = + session.ISession.user = session.ISession.password = + session.ISession.cert = session.ISession.certKey = undefined; } const restErrUnauthorized = 403; From 2bb26c77cff6e8752ea1dbf5aad94efac89b38ca Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:09:08 +0000 Subject: [PATCH 11/29] only set tokenType if undefined Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/cli/CHANGELOG.md | 2 +- packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index e49870eb60..6e9dad8382 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to the Zowe CLI package will be documented in this file. -## Recent changes +## Recent Changes - Enhancement: Updated the Imperative Framework to add support for unique cookie identifiers from API ML. [#1734](https://github.com/zowe/zowe-cli/pull/1734) - Enhancement: Added support for mutliple `zowe auth login apiml` operations on a single `zowe config secure` call. [#1734](https://github.com/zowe/zowe-cli/pull/1734) diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index 3144e9dcee..7edb4421b4 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -73,7 +73,9 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { if ((session.ISession.user && session.ISession.password) || (session.ISession.cert && session.ISession.certKey)) { // If it is basic authentication, we need to set the auth type. if (session.ISession.password) { session.ISession.type = SessConstants.AUTH_TYPE_TOKEN; } - session.ISession.tokenType = SessConstants.TOKEN_TYPE_APIML; + if (session.ISession.tokenType == null) { + session.ISession.tokenType = SessConstants.TOKEN_TYPE_APIML; + } session.ISession.storeCookie = true; session.ISession.tokenValue = await Login.apimlLogin(session); session.ISession.storeCookie = false; From 362ea58da537a6f6ff3a1e9dcaf96652296178d2 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:37:21 +0000 Subject: [PATCH 12/29] prevent new 'base' profile from being created if there is an active one already Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index 7edb4421b4..034d44b720 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -15,7 +15,7 @@ import * as lodash from "lodash"; import { ZosmfSession } from "@zowe/zosmf-for-zowe-sdk"; import { BaseAutoInitHandler, AbstractSession, ICommandArguments, IConfig, IConfigProfile, ISession, IHandlerResponseApi, IHandlerParameters, SessConstants, ImperativeConfig, - ImperativeError, RestClientError, TextUtils + ImperativeError, RestClientError, TextUtils, ConfigUtils } from "@zowe/imperative"; import { IApimlProfileInfo, IAutoInitRpt, IProfileRpt, Login, Services } from "@zowe/core-for-zowe-sdk"; @@ -104,8 +104,11 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { } const profileConfig = Services.convertApimlProfileInfoToProfileConfig(profileInfos); + // Check to see if there is an active base profile to avoid creating a new one named "base" + const activeBaseProfile = ConfigUtils.getActiveProfileName("base", params.arguments); + // Populate the config with base profile information - if (profileConfig.defaults.base == null && profileConfig.profiles.base == null) { + if (profileConfig.defaults.base == null && profileConfig.profiles.base == null && activeBaseProfile == null) { profileConfig.profiles.base = { type: "base", properties: { From 3abf0055a82c591fb85196a86ffdc9f727945904 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:38:10 +0000 Subject: [PATCH 13/29] revert basepath regardless of the statusCode and clear creds as soon as we get a token Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/src/auth/Login.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/core/src/auth/Login.ts b/packages/core/src/auth/Login.ts index 92a8c3f565..10116ea6ee 100644 --- a/packages/core/src/auth/Login.ts +++ b/packages/core/src/auth/Login.ts @@ -41,18 +41,17 @@ export class Login { request: "POST", resource: LoginConstants.APIML_V1_RESOURCE }); - + if (session.ISession.basePath === "/") { + session.ISession.basePath = AbstractSession.DEFAULT_BASE_PATH; + } if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { - if (session.ISession.basePath === "/") { - session.ISession.basePath = undefined; - } throw new ImperativeError((client as any).populateError({ msg: `REST API Failure with HTTP(S) status ${client.response.statusCode}`, causeErrors: client.dataString, source: SessConstants.HTTP_PROTOCOL })); } - + session.ISession.user = session.ISession.password = session.ISession.base64EncodedAuth = undefined; // return token to the caller return session.ISession.tokenValue; } From 0bdf77fd985d6ba9f75009f224500a92a6e5b60d Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Thu, 20 Jul 2023 12:58:14 +0000 Subject: [PATCH 14/29] fix unit tests and lint issues Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts | 7 ++++++- .../__unit__/__snapshots__/Login.apiml.unit.test.ts.snap | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index 034d44b720..bb42a581f3 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -105,7 +105,12 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { const profileConfig = Services.convertApimlProfileInfoToProfileConfig(profileInfos); // Check to see if there is an active base profile to avoid creating a new one named "base" - const activeBaseProfile = ConfigUtils.getActiveProfileName("base", params.arguments); + let activeBaseProfile: string; + try { + activeBaseProfile = ConfigUtils.getActiveProfileName("base", params.arguments); + } catch (err) { + // do nothing + } // Populate the config with base profile information if (profileConfig.defaults.base == null && profileConfig.profiles.base == null && activeBaseProfile == null) { diff --git a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap index d576559c55..599410d527 100644 --- a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap +++ b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap @@ -8,7 +8,7 @@ REST API Failure with HTTP(S) status 401 Host: undefined Port: undefined -Base Path: undefined +Base Path: Resource: undefined Request: undefined Headers: undefined From 5fe696b3d970709fa45dd0e08f46bed29a7f03da Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Mon, 24 Jul 2023 17:50:39 +0000 Subject: [PATCH 15/29] allow for 401 to be thrown Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/src/auth/Logout.ts | 38 ++++++++++++++++++----- packages/core/src/auth/LogoutConstants.ts | 14 ++++----- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/packages/core/src/auth/Logout.ts b/packages/core/src/auth/Logout.ts index 10e34f7e46..6b4b4518aa 100644 --- a/packages/core/src/auth/Logout.ts +++ b/packages/core/src/auth/Logout.ts @@ -35,24 +35,46 @@ export class Logout { ImperativeExpect.toNotBeNullOrUndefined(session.ISession.tokenValue, "Session token not populated. Unable to log out."); const client = new ZosmfRestClient(session); + if(!session.ISession.basePath) { + session.ISession.basePath = "/"; // prevent basepath requirement error on invalid credentials + } try{ await client.request({ request: "POST", resource: LogoutConstants.APIML_V1_RESOURCE }); } catch (err) { - let shouldThrow = true; - LogoutConstants.APIML_V2_LOGOUT_ERR_LIST.forEach((errorKey: string) => { - if (err.message.includes(errorKey)) { - shouldThrow = false; + let errorToThrow = err; + for (const errorKey in LogoutConstants.APIML_V2_LOGOUT_ERR_LIST) { + if (err.message.includes(LogoutConstants.APIML_V2_LOGOUT_ERR_LIST[errorKey])) { + switch (errorKey) { + case "V2_TOKEN_INVALID": // Token is invalid (logged out) + case "V2_TOKEN_EXPIRED": // Token expired (trully expired) + case "V2_TOKEN_MISSING": // Token type is not ^apimlAuthenticationToken.* + errorToThrow = new ImperativeError({ + msg: "Token is not valid or expired.\n" + + "For CLI usage, see `zowe auth logout apiml --help`", + errorCode: client.response.statusCode.toString() + }); + break; + case "V1_TOKEN_EXPIRED": + default: + errorToThrow = null; + break; + } } - }); - if (shouldThrow) { - throw err; + } + + if (errorToThrow) { + throw errorToThrow; + } + } finally { + if (session.ISession.basePath === "/") { + session.ISession.basePath = AbstractSession.DEFAULT_BASE_PATH; } } - if (client.response.statusCode !== RestConstants.HTTP_STATUS_204 && client.response.statusCode !== RestConstants.HTTP_STATUS_401) { + if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { if (!(client.response.statusCode === RestConstants.HTTP_STATUS_500 && client.dataString.includes(LogoutConstants.APIML_V1_TOKEN_EXP_ERR))) { throw new ImperativeError((client as any).populateError({ diff --git a/packages/core/src/auth/LogoutConstants.ts b/packages/core/src/auth/LogoutConstants.ts index 9b631c8318..6b68075e56 100644 --- a/packages/core/src/auth/LogoutConstants.ts +++ b/packages/core/src/auth/LogoutConstants.ts @@ -40,10 +40,10 @@ export class LogoutConstants { * @type {string} * @memberof LogoutConstants */ - public static readonly APIML_V2_LOGOUT_ERR_LIST: string[] = [ - LogoutConstants.APIML_V1_TOKEN_EXP_ERR, - "org.zowe.apiml.security.expiredToken", - "org.zowe.apiml.security.query.invalidToken", - "org.zowe.apiml.security.query.tokenNotProvided", - ]; -} + public static readonly APIML_V2_LOGOUT_ERR_LIST: {[key:string]: string} = { + V1_TOKEN_EXPIRED: LogoutConstants.APIML_V1_TOKEN_EXP_ERR, + V2_TOKEN_EXPIRED: "org.zowe.apiml.security.expiredToken", + V2_TOKEN_INVALID: "org.zowe.apiml.security.query.invalidToken", + V2_TOKEN_MISSING: "org.zowe.apiml.security.query.tokenNotProvided", + }; +} \ No newline at end of file From 2c6547f17598b8a8f4f8b46fc0d069c86291420f Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Tue, 25 Jul 2023 20:39:45 +0000 Subject: [PATCH 16/29] simplify activeBaseProfile check Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts | 3 ++- packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts | 2 +- .../core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts | 4 ++-- .../__unit__/__snapshots__/AuthConstants.unit.test.ts.snap | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts b/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts index 6d7e5b7e7a..392c30635f 100644 --- a/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts +++ b/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts @@ -10,7 +10,7 @@ */ import ApimlAutoInitHandler from "../../../../src/config/auto-init/ApimlAutoInitHandler"; -import { SessConstants, RestClientError, IRestClientError, ImperativeConfig, IConfig } from "@zowe/imperative"; +import { SessConstants, RestClientError, IRestClientError, ImperativeConfig, IConfig, ConfigUtils } from "@zowe/imperative"; import { ZosmfSession } from "@zowe/zosmf-for-zowe-sdk"; import { IApimlProfileInfo, IProfileRpt, Login, Services } from "@zowe/core-for-zowe-sdk"; import * as lodash from "lodash"; @@ -194,6 +194,7 @@ describe("ApimlAutoInitHandler", () => { const mockCreateZosmfSession = jest.fn(); const mockGetPluginApimlConfigs = jest.fn().mockReturnValue([]); const mockGetServicesByConfig = jest.fn().mockResolvedValue([]); + jest.spyOn(ConfigUtils, "getActiveProfileName").mockReturnValueOnce("base"); const mockConvertApimlProfileInfoToProfileConfig = jest.fn().mockReturnValue({ defaults: { base: "base"}, profiles: { diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index bb42a581f3..46928ef2ba 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -113,7 +113,7 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { } // Populate the config with base profile information - if (profileConfig.defaults.base == null && profileConfig.profiles.base == null && activeBaseProfile == null) { + if (activeBaseProfile == null) { profileConfig.profiles.base = { type: "base", properties: { diff --git a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts index 1a03c47214..b3e7b0a916 100644 --- a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts +++ b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts @@ -69,7 +69,7 @@ describe("Auth Logout APIML unit tests", () => { }); describe("Error handling tests - HTTP 401", () => { - it("should not throw an error with HTTP 401", async () => { + it("should throw an error with HTTP 401", async () => { ZosmfRestClient.prototype.request = jest.fn(); (ZosmfRestClient.prototype as any).mResponse = badResponse401; let caughtError; @@ -78,7 +78,7 @@ describe("Auth Logout APIML unit tests", () => { } catch (error) { caughtError = error; } - expect(caughtError).toBeUndefined(); + expect(caughtError).toBeDefined(); }); }); diff --git a/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap b/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap index afa01c4a7f..f9f330c91a 100644 --- a/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap +++ b/packages/core/__tests__/auth/__unit__/__snapshots__/AuthConstants.unit.test.ts.snap @@ -2,4 +2,4 @@ exports[`LoginConstants Unit Test Should not have changed 1`] = `"{\\"APIML_V1_RESOURCE\\":\\"/gateway/api/v1/auth/login\\"}"`; -exports[`LogoutConstants Unit Test Should not have changed 1`] = `"{\\"APIML_V1_RESOURCE\\":\\"/gateway/api/v1/auth/logout\\",\\"APIML_V1_TOKEN_EXP_ERR\\":\\"TokenExpireException\\",\\"APIML_V2_LOGOUT_ERR_LIST\\":[\\"TokenExpireException\\",\\"org.zowe.apiml.security.expiredToken\\",\\"org.zowe.apiml.security.query.invalidToken\\",\\"org.zowe.apiml.security.query.tokenNotProvided\\"]}"`; +exports[`LogoutConstants Unit Test Should not have changed 1`] = `"{\\"APIML_V1_RESOURCE\\":\\"/gateway/api/v1/auth/logout\\",\\"APIML_V1_TOKEN_EXP_ERR\\":\\"TokenExpireException\\",\\"APIML_V2_LOGOUT_ERR_LIST\\":{\\"V1_TOKEN_EXPIRED\\":\\"TokenExpireException\\",\\"V2_TOKEN_EXPIRED\\":\\"org.zowe.apiml.security.expiredToken\\",\\"V2_TOKEN_INVALID\\":\\"org.zowe.apiml.security.query.invalidToken\\",\\"V2_TOKEN_MISSING\\":\\"org.zowe.apiml.security.query.tokenNotProvided\\"}}"`; From 375c24a80334069c48f531dd72597d05fee5a111 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Wed, 26 Jul 2023 10:52:53 +0000 Subject: [PATCH 17/29] update imperative version to allow builds to run Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../__packages__/cli-test-utils/package.json | 2 +- npm-shrinkwrap.json | 62 +++++++++---------- package.json | 2 +- packages/cli/package.json | 2 +- packages/core/package.json | 2 +- packages/provisioning/package.json | 2 +- packages/workflows/package.json | 2 +- packages/zosconsole/package.json | 2 +- packages/zosfiles/package.json | 2 +- packages/zosjobs/package.json | 2 +- packages/zoslogs/package.json | 2 +- packages/zosmf/package.json | 2 +- packages/zostso/package.json | 2 +- packages/zosuss/package.json | 2 +- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/__tests__/__packages__/cli-test-utils/package.json b/__tests__/__packages__/cli-test-utils/package.json index 670356310e..7a3fb74392 100644 --- a/__tests__/__packages__/cli-test-utils/package.json +++ b/__tests__/__packages__/cli-test-utils/package.json @@ -44,7 +44,7 @@ "@types/js-yaml": "^4.0.0", "@types/node": "^14.18.28", "@types/uuid": "^8.3.0", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "typescript": "^4.0.0" }, diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index d886bd7476..398d7feb4b 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -11,7 +11,7 @@ "__tests__/__packages__/*" ], "dependencies": { - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/perf-timing": "1.0.7" }, "devDependencies": { @@ -65,7 +65,7 @@ "@types/js-yaml": "^4.0.0", "@types/node": "^14.18.28", "@types/uuid": "^8.3.0", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "typescript": "^4.0.0" }, @@ -7967,9 +7967,9 @@ "link": true }, "node_modules/@zowe/imperative": { - "version": "5.15.1", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.15.1.tgz", - "integrity": "sha512-I6SoJcJ3ebyueTMR9wAFrT4WxqOyxL68NjtjMLCBdUenCwKNLrpEWlM3DTPx4VV6NthDckxaYsvzEaYHVN2F+A==", + "version": "5.16.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.16.0.tgz", + "integrity": "sha512-fioRwpeAwIelEkDjIMQRkpXL/srSx/zhQ48A1BHiAGS4SNBYjagVrlZ3d5b+2XyvGuJ4FhsHzAEsjSpTSxgRMg==", "dependencies": { "@types/yargs": "13.0.4", "@zowe/perf-timing": "1.0.7", @@ -22609,7 +22609,7 @@ "license": "EPL-2.0", "dependencies": { "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.16.5", "@zowe/zos-console-for-zowe-sdk": "7.16.5", @@ -22684,7 +22684,7 @@ "devDependencies": { "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "chalk": "^4.1.0", "eslint": "^8.22.0", "madge": "^4.0.1", @@ -22708,7 +22708,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -22731,7 +22731,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -22751,7 +22751,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -22774,7 +22774,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/zos-uss-for-zowe-sdk": "7.16.5", "eslint": "^8.22.0", "madge": "^4.0.1", @@ -22817,7 +22817,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -22837,7 +22837,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -22857,7 +22857,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -22880,7 +22880,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -22903,7 +22903,7 @@ "@types/node": "^14.18.28", "@types/ssh2": "^1.11.0", "@zowe/cli-test-utils": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -29174,7 +29174,7 @@ "@types/which": "^2.0.1", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.16.5", "@zowe/zos-console-for-zowe-sdk": "7.16.5", @@ -29226,7 +29226,7 @@ "@types/js-yaml": "^4.0.0", "@types/node": "^14.18.28", "@types/uuid": "^8.3.0", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "find-up": "^5.0.0", "js-yaml": "^4.0.0", @@ -29250,7 +29250,7 @@ "requires": { "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "chalk": "^4.1.0", "comment-json": "4.1.1", "eslint": "^8.22.0", @@ -29262,9 +29262,9 @@ } }, "@zowe/imperative": { - "version": "5.15.1", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.15.1.tgz", - "integrity": "sha512-I6SoJcJ3ebyueTMR9wAFrT4WxqOyxL68NjtjMLCBdUenCwKNLrpEWlM3DTPx4VV6NthDckxaYsvzEaYHVN2F+A==", + "version": "5.16.0", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-local-release/@zowe/imperative/-/@zowe/imperative-5.16.0.tgz", + "integrity": "sha512-fioRwpeAwIelEkDjIMQRkpXL/srSx/zhQ48A1BHiAGS4SNBYjagVrlZ3d5b+2XyvGuJ4FhsHzAEsjSpTSxgRMg==", "requires": { "@types/yargs": "13.0.4", "@zowe/perf-timing": "1.0.7", @@ -29479,7 +29479,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "js-yaml": "4.1.0", "madge": "^4.0.1", @@ -29494,7 +29494,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -29508,7 +29508,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/zos-uss-for-zowe-sdk": "7.16.5", "eslint": "^8.22.0", "madge": "^4.0.1", @@ -29542,7 +29542,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/zos-files-for-zowe-sdk": "7.16.6", "eslint": "^8.22.0", "madge": "^4.0.1", @@ -29557,7 +29557,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -29571,7 +29571,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/zosmf-for-zowe-sdk": "7.16.5", "eslint": "^8.22.0", "madge": "^4.0.1", @@ -29586,7 +29586,7 @@ "@types/node": "^14.18.28", "@types/ssh2": "^1.11.0", "@zowe/cli-test-utils": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", @@ -29601,7 +29601,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/zos-files-for-zowe-sdk": "7.16.6", "eslint": "^8.22.0", "madge": "^4.0.1", @@ -29616,7 +29616,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/package.json b/package.json index 0cf38974f4..e7ec7aaf13 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "prepare": "husky install" }, "dependencies": { - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/perf-timing": "1.0.7" }, "devDependencies": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 9c97d32117..d59493cfa6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -59,7 +59,7 @@ }, "dependencies": { "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/perf-timing": "1.0.7", "@zowe/provisioning-for-zowe-sdk": "7.16.5", "@zowe/zos-console-for-zowe-sdk": "7.16.5", diff --git a/packages/core/package.json b/packages/core/package.json index 4a3d2a27be..b9a3aa6456 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -51,7 +51,7 @@ "devDependencies": { "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "chalk": "^4.1.0", "eslint": "^8.22.0", "madge": "^4.0.1", diff --git a/packages/provisioning/package.json b/packages/provisioning/package.json index 4c06cc79df..32e4f22ff3 100644 --- a/packages/provisioning/package.json +++ b/packages/provisioning/package.json @@ -52,7 +52,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/workflows/package.json b/packages/workflows/package.json index a3c6da9c9b..11d37749f1 100644 --- a/packages/workflows/package.json +++ b/packages/workflows/package.json @@ -51,7 +51,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosconsole/package.json b/packages/zosconsole/package.json index 7d1d654e66..b6b915bd2f 100644 --- a/packages/zosconsole/package.json +++ b/packages/zosconsole/package.json @@ -48,7 +48,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosfiles/package.json b/packages/zosfiles/package.json index dc2828b2a4..d6698f2bee 100644 --- a/packages/zosfiles/package.json +++ b/packages/zosfiles/package.json @@ -52,7 +52,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "@zowe/zos-uss-for-zowe-sdk": "7.16.5", "eslint": "^8.22.0", "madge": "^4.0.1", diff --git a/packages/zosjobs/package.json b/packages/zosjobs/package.json index 2bf7f76bf4..3876a13909 100644 --- a/packages/zosjobs/package.json +++ b/packages/zosjobs/package.json @@ -52,7 +52,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zoslogs/package.json b/packages/zoslogs/package.json index 51027b521a..91e7f5c691 100644 --- a/packages/zoslogs/package.json +++ b/packages/zoslogs/package.json @@ -48,7 +48,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosmf/package.json b/packages/zosmf/package.json index 41fb914cc2..54a13b05fb 100644 --- a/packages/zosmf/package.json +++ b/packages/zosmf/package.json @@ -47,7 +47,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zostso/package.json b/packages/zostso/package.json index 6276bcfe92..b15bebd761 100644 --- a/packages/zostso/package.json +++ b/packages/zostso/package.json @@ -51,7 +51,7 @@ "@types/node": "^14.18.28", "@zowe/cli-test-utils": "7.16.5", "@zowe/core-for-zowe-sdk": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", diff --git a/packages/zosuss/package.json b/packages/zosuss/package.json index 22b7d84f50..ed39949bc1 100644 --- a/packages/zosuss/package.json +++ b/packages/zosuss/package.json @@ -51,7 +51,7 @@ "@types/node": "^14.18.28", "@types/ssh2": "^1.11.0", "@zowe/cli-test-utils": "7.16.5", - "@zowe/imperative": "5.15.1", + "@zowe/imperative": "5.16.0", "eslint": "^8.22.0", "madge": "^4.0.1", "rimraf": "^2.6.3", From 278408f1c0864c8da3b2a03e83dd82954b7c125e Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Wed, 26 Jul 2023 11:05:44 +0000 Subject: [PATCH 18/29] fix integration test snapshot Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../__snapshots__/cli.auth.apiml.integration.test.ts.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cli/__tests__/auth/__integration__/__snapshots__/cli.auth.apiml.integration.test.ts.snap b/packages/cli/__tests__/auth/__integration__/__snapshots__/cli.auth.apiml.integration.test.ts.snap index b4072c85cd..adec432955 100644 --- a/packages/cli/__tests__/auth/__integration__/__snapshots__/cli.auth.apiml.integration.test.ts.snap +++ b/packages/cli/__tests__/auth/__integration__/__snapshots__/cli.auth.apiml.integration.test.ts.snap @@ -151,7 +151,7 @@ exports[`auth login/logout apiml help should display the logout help 1`] = ` The type of token to get and use for the API. Omit this option to use the default token type, which is provided by 'zowe auth login'. - Allowed values: apimlAuthenticationToken, jwtToken, LtpaToken2 + Allowed values: ^apimlAuthenticationToken.*, jwtToken, LtpaToken2 --token-value | --tv (string) @@ -206,8 +206,8 @@ exports[`auth login/logout apiml help should display the logout help 1`] = ` \\"success\\": true, \\"exitCode\\": 0, \\"message\\": \\"The help was constructed for command: apiml.\\", - \\"stdout\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n apiml\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Log out of the Zowe API Mediation Layer authentication service and revoke the\\\\n token so it can no longer authenticate. Also remove the token from the default\\\\n base profile, if it is stored on disk.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe auth logout apiml [options]\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n Host name of service on the mainframe.\\\\n\\\\n --port | -P (number)\\\\n\\\\n Port number of service on the mainframe.\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n Allowed values: apimlAuthenticationToken, jwtToken, LtpaToken2\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Log out of an API ML instance to revoke the token that was\\\\n in use and remove it from your base profile:\\\\n\\\\n $ zowe auth logout apiml\\\\n\\\\n - Log out of an API ML instance to revoke a token that was\\\\n not stored in a profile:\\\\n\\\\n $ zowe auth logout apiml --token-value \\\\n\\\\n\\", + \\"stdout\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n apiml\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Log out of the Zowe API Mediation Layer authentication service and revoke the\\\\n token so it can no longer authenticate. Also remove the token from the default\\\\n base profile, if it is stored on disk.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe auth logout apiml [options]\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n Host name of service on the mainframe.\\\\n\\\\n --port | -P (number)\\\\n\\\\n Port number of service on the mainframe.\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n Allowed values: ^apimlAuthenticationToken.*, jwtToken, LtpaToken2\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Log out of an API ML instance to revoke the token that was\\\\n in use and remove it from your base profile:\\\\n\\\\n $ zowe auth logout apiml\\\\n\\\\n - Log out of an API ML instance to revoke a token that was\\\\n not stored in a profile:\\\\n\\\\n $ zowe auth logout apiml --token-value \\\\n\\\\n\\", \\"stderr\\": \\"\\", - \\"data\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n apiml\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Log out of the Zowe API Mediation Layer authentication service and revoke the\\\\n token so it can no longer authenticate. Also remove the token from the default\\\\n base profile, if it is stored on disk.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe auth logout apiml [options]\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n Host name of service on the mainframe.\\\\n\\\\n --port | -P (number)\\\\n\\\\n Port number of service on the mainframe.\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n Allowed values: apimlAuthenticationToken, jwtToken, LtpaToken2\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Log out of an API ML instance to revoke the token that was\\\\n in use and remove it from your base profile:\\\\n\\\\n $ zowe auth logout apiml\\\\n\\\\n - Log out of an API ML instance to revoke a token that was\\\\n not stored in a profile:\\\\n\\\\n $ zowe auth logout apiml --token-value \\\\n\\\\n\\" + \\"data\\": \\"\\\\n COMMAND NAME\\\\n ------------\\\\n\\\\n apiml\\\\n\\\\n DESCRIPTION\\\\n -----------\\\\n\\\\n Log out of the Zowe API Mediation Layer authentication service and revoke the\\\\n token so it can no longer authenticate. Also remove the token from the default\\\\n base profile, if it is stored on disk.\\\\n\\\\n USAGE\\\\n -----\\\\n\\\\n zowe auth logout apiml [options]\\\\n\\\\n BASE CONNECTION OPTIONS\\\\n -----------------------\\\\n\\\\n --host | -H (string)\\\\n\\\\n Host name of service on the mainframe.\\\\n\\\\n --port | -P (number)\\\\n\\\\n Port number of service on the mainframe.\\\\n\\\\n --token-type | --tt (string)\\\\n\\\\n The type of token to get and use for the API. Omit this option to use the\\\\n default token type, which is provided by 'zowe auth login'.\\\\n\\\\n Allowed values: ^apimlAuthenticationToken.*, jwtToken, LtpaToken2\\\\n\\\\n --token-value | --tv (string)\\\\n\\\\n The value of the token to pass to the API.\\\\n\\\\n --reject-unauthorized | --ru (boolean)\\\\n\\\\n Reject self-signed certificates.\\\\n\\\\n Default value: true\\\\n\\\\n PROFILE OPTIONS\\\\n ---------------\\\\n\\\\n --base-profile | --base-p (string)\\\\n\\\\n The name of a (base) profile to load for this command execution.\\\\n\\\\n GLOBAL OPTIONS\\\\n --------------\\\\n\\\\n --show-inputs-only (boolean)\\\\n\\\\n Show command inputs and do not run the command\\\\n\\\\n --response-format-json | --rfj (boolean)\\\\n\\\\n Produce JSON formatted data from a command\\\\n\\\\n --help | -h (boolean)\\\\n\\\\n Display help text\\\\n\\\\n --help-web | --hw (boolean)\\\\n\\\\n Display HTML help in browser\\\\n\\\\n EXAMPLES\\\\n --------\\\\n\\\\n - Log out of an API ML instance to revoke the token that was\\\\n in use and remove it from your base profile:\\\\n\\\\n $ zowe auth logout apiml\\\\n\\\\n - Log out of an API ML instance to revoke a token that was\\\\n not stored in a profile:\\\\n\\\\n $ zowe auth logout apiml --token-value \\\\n\\\\n\\" }" `; From ad4b7e8fd3a0752962eb225abde6bc586da082a4 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:17:23 +0000 Subject: [PATCH 19/29] add unit tests for logout Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../auth/__unit__/Logout.apiml.unit.test.ts | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts index b3e7b0a916..0f62db38d1 100644 --- a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts +++ b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts @@ -31,12 +31,14 @@ const badDataExpired = { "Token is expired. caused by: TokenExpireException: Token is expired.", messageKey: "org.zowe.apiml.common.internalRequestError" } - ]}; + ] +}; +const realErrorText = "Token is not valid or expired"; const mockErrorText = "Fake error for Auth Logout APIML unit tests"; const throwImperativeError = async () => { - throw new ImperativeError({msg: mockErrorText}); + throw new ImperativeError({ msg: mockErrorText }); }; const fakeSession: any = { ISession: { @@ -73,13 +75,55 @@ describe("Auth Logout APIML unit tests", () => { ZosmfRestClient.prototype.request = jest.fn(); (ZosmfRestClient.prototype as any).mResponse = badResponse401; let caughtError; - try{ + try { await Logout.apimlLogout(fakeSession); } catch (error) { caughtError = error; } expect(caughtError).toBeDefined(); }); + + it("should be able to catch 401 errors from apimlLogout", async () => { + const runTest = async (errorString: string): Promise => { + ZosmfRestClient.prototype.request = jest.fn(async () => { throw new Error(errorString) }); + let caughtError; + try { + await Logout.apimlLogout(fakeSession); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeDefined(); + expect(caughtError.message).toContain(realErrorText); + expect(caughtError instanceof ImperativeError).toEqual(true); + return caughtError; + } + // Token is invalid (logged out bu tnot expired) + let caughtError = await runTest("org.zowe.apiml.security.query.invalidToken"); + // Token is expored (old token) + caughtError = await runTest("org.zowe.apiml.security.expiredToken"); + // Token is not APIML token + caughtError = await runTest("org.zowe.apiml.security.query.tokenNotProvided"); + + expect(caughtError).toBeDefined(); + }); + }); + + describe("Error handling tests - Token Expired - HTTP 500 - Zowe V1 APIML", () => { + it("should not throw and be able to catch 500 errors when a expired token was provided", async () => { + ZosmfRestClient.prototype.request = jest.fn(async function() { + this.mData = Buffer.from(JSON.stringify(badDataExpired)); + throw new Error("TokenExpireException"); + }); + (ZosmfRestClient.prototype as any).mResponse = badResponse500; + + let caughtError: ImperativeError = undefined as any; + try { + await Logout.apimlLogout(fakeSession); + } catch (error) { + caughtError = error; + } + expect(caughtError).toBeUndefined(); + }); }); describe("Error handling tests - async/await", () => { From b5cbee97cb60d4928de7de25f9646bbeac7da418 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:23:41 +0000 Subject: [PATCH 20/29] address gh code scanning comments Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../auth/__unit__/Logout.apiml.unit.test.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts index 0f62db38d1..30c76a735e 100644 --- a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts +++ b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts @@ -85,7 +85,7 @@ describe("Auth Logout APIML unit tests", () => { it("should be able to catch 401 errors from apimlLogout", async () => { const runTest = async (errorString: string): Promise => { - ZosmfRestClient.prototype.request = jest.fn(async () => { throw new Error(errorString) }); + ZosmfRestClient.prototype.request = jest.fn(async () => { throw new Error(errorString); }); let caughtError; try { await Logout.apimlLogout(fakeSession); @@ -96,15 +96,13 @@ describe("Auth Logout APIML unit tests", () => { expect(caughtError.message).toContain(realErrorText); expect(caughtError instanceof ImperativeError).toEqual(true); return caughtError; - } + }; // Token is invalid (logged out bu tnot expired) - let caughtError = await runTest("org.zowe.apiml.security.query.invalidToken"); + expect(await runTest("org.zowe.apiml.security.query.invalidToken")).toBeDefined(); // Token is expored (old token) - caughtError = await runTest("org.zowe.apiml.security.expiredToken"); + expect(await runTest("org.zowe.apiml.security.expiredToken")).toBeDefined(); // Token is not APIML token - caughtError = await runTest("org.zowe.apiml.security.query.tokenNotProvided"); - - expect(caughtError).toBeDefined(); + expect(await runTest("org.zowe.apiml.security.query.tokenNotProvided")).toBeDefined(); }); }); From 423931325333cf0a66fa9493b6ca81142c4acb6a Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:31:53 +0000 Subject: [PATCH 21/29] update changelog Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 8ae3a5dafd..82190fd3a2 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -2,9 +2,12 @@ All notable changes to the Zowe core SDK package will be documented in this file. -## `7.17.0` +## Recent Changes - Enhancement: Added support for dynamic APIML tokens. [#1734](https://github.com/zowe/zowe-cli/pull/1734) + +## `7.17.0` + - Enhancement: Set properties for z/OSMF REST errors for use in a more user-friendly format with the ZOWE_V3_ERR_FORMAT environment variable. [zowe-cli#935](https://github.com/zowe/zowe-cli/issues/935) - ## `7.16.5` From a62e4b44ed4cf8f04f64db708d332b3f12643f4a Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Thu, 27 Jul 2023 11:51:01 +0000 Subject: [PATCH 22/29] make script executable files Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../dsclp/__scripts__/command/command_copy_data_set_cross_lpar.sh | 0 .../__system__/edit/ds/__scripts__/command/ds_edit_success.sh | 0 .../__system__/edit/ds/__scripts__/command/edit_nonexistent_ds.sh | 0 .../edit/uss/__scripts__/command/edit_nonexistent_uss.sh | 0 .../__system__/edit/uss/__scripts__/command/uss_edit_success.sh | 0 .../zosjobs/__system__/modify/__scripts__/job/bogus_jobclass.sh | 0 .../zosjobs/__system__/modify/__scripts__/job/bogus_jobid.sh | 0 .../zosjobs/__system__/modify/__scripts__/job/hold_job.sh | 0 .../zosjobs/__system__/modify/__scripts__/job/real_jobclass.sh | 0 .../zosjobs/__system__/modify/__scripts__/job/real_jobid.sh | 0 .../zosjobs/__system__/modify/__scripts__/job/release_job.sh | 0 11 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 packages/cli/__tests__/zosfiles/__system__/copy/dsclp/__scripts__/command/command_copy_data_set_cross_lpar.sh mode change 100644 => 100755 packages/cli/__tests__/zosfiles/__system__/edit/ds/__scripts__/command/ds_edit_success.sh mode change 100644 => 100755 packages/cli/__tests__/zosfiles/__system__/edit/ds/__scripts__/command/edit_nonexistent_ds.sh mode change 100644 => 100755 packages/cli/__tests__/zosfiles/__system__/edit/uss/__scripts__/command/edit_nonexistent_uss.sh mode change 100644 => 100755 packages/cli/__tests__/zosfiles/__system__/edit/uss/__scripts__/command/uss_edit_success.sh mode change 100644 => 100755 packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/bogus_jobclass.sh mode change 100644 => 100755 packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/bogus_jobid.sh mode change 100644 => 100755 packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/hold_job.sh mode change 100644 => 100755 packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/real_jobclass.sh mode change 100644 => 100755 packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/real_jobid.sh mode change 100644 => 100755 packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/release_job.sh diff --git a/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/__scripts__/command/command_copy_data_set_cross_lpar.sh b/packages/cli/__tests__/zosfiles/__system__/copy/dsclp/__scripts__/command/command_copy_data_set_cross_lpar.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/ds/__scripts__/command/ds_edit_success.sh b/packages/cli/__tests__/zosfiles/__system__/edit/ds/__scripts__/command/ds_edit_success.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/ds/__scripts__/command/edit_nonexistent_ds.sh b/packages/cli/__tests__/zosfiles/__system__/edit/ds/__scripts__/command/edit_nonexistent_ds.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/uss/__scripts__/command/edit_nonexistent_uss.sh b/packages/cli/__tests__/zosfiles/__system__/edit/uss/__scripts__/command/edit_nonexistent_uss.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosfiles/__system__/edit/uss/__scripts__/command/uss_edit_success.sh b/packages/cli/__tests__/zosfiles/__system__/edit/uss/__scripts__/command/uss_edit_success.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/bogus_jobclass.sh b/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/bogus_jobclass.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/bogus_jobid.sh b/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/bogus_jobid.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/hold_job.sh b/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/hold_job.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/real_jobclass.sh b/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/real_jobclass.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/real_jobid.sh b/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/real_jobid.sh old mode 100644 new mode 100755 diff --git a/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/release_job.sh b/packages/cli/__tests__/zosjobs/__system__/modify/__scripts__/job/release_job.sh old mode 100644 new mode 100755 From 992691b12bf5a8ede8d0d9b836d7e8ecb2871cdc Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 28 Jul 2023 13:59:15 +0000 Subject: [PATCH 23/29] address some system test issues Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../cli.auth.login.apiml.system.test.ts | 8 ++- .../ApimlAutoInitHandler.unit.test.ts | 9 +-- .../config/auto-init/ApimlAutoInitHandler.ts | 57 ++++++++++++------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/packages/cli/__tests__/auth/__system__/cli.auth.login.apiml.system.test.ts b/packages/cli/__tests__/auth/__system__/cli.auth.login.apiml.system.test.ts index 6c3c499a3f..ddc4db9991 100644 --- a/packages/cli/__tests__/auth/__system__/cli.auth.login.apiml.system.test.ts +++ b/packages/cli/__tests__/auth/__system__/cli.auth.login.apiml.system.test.ts @@ -49,7 +49,8 @@ describe("auth login/logout apiml with profile", () => { expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Logout successful."); - expect(response.stdout.toString()).toContain("The authentication token has been revoked and removed"); + expect(response.stdout.toString()).toContain("The authentication token has been revoked"); + expect(response.stdout.toString()).toContain("Token was removed from your"); // ${name} base profile }); }); @@ -153,7 +154,7 @@ describe("auth login/logout apiml create profile", () => { expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); expect(response.stdout.toString()).toContain("Login successful."); - expect(response.stdout.toString()).toContain("The authentication token is stored in the 'default' base profile"); + expect(response.stdout.toString()).toContain("The authentication token is stored in the"); // ${name} base profile }); it("should successfully issue the logout command with a created profile", () => { @@ -161,7 +162,8 @@ describe("auth login/logout apiml create profile", () => { TEST_ENVIRONMENT_CREATE_PROF); expect(response.stderr.toString()).toBe(""); expect(response.status).toBe(0); - expect(response.stdout.toString()).toContain("Logout successful. The authentication token has been revoked and removed"); + expect(response.stdout.toString()).toContain("Logout successful. The authentication token has been revoked"); + expect(response.stdout.toString()).toContain("Token was removed from your"); // ${name} base profile }); }); diff --git a/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts b/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts index 392c30635f..fc1d33edfe 100644 --- a/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts +++ b/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts @@ -27,7 +27,7 @@ function mockConfigApi(properties: IConfig | undefined): any { }) }, profiles: { - expandPath: (name: string) => `profiles.${name}` + getProfilePathFromName: (name: string) => `profiles.${name}` } }, exists: true, @@ -191,6 +191,7 @@ describe("ApimlAutoInitHandler", () => { }); it("should not have changed - user & password with existing base profile", async () => { + // NOTE: Token type and token value will be stored, but user and password will still be present in the base profile const mockCreateZosmfSession = jest.fn(); const mockGetPluginApimlConfigs = jest.fn().mockReturnValue([]); const mockGetServicesByConfig = jest.fn().mockResolvedValue([]); @@ -244,9 +245,9 @@ describe("ApimlAutoInitHandler", () => { expect(mockGetServicesByConfig).toHaveBeenCalledTimes(1); expect(mockConvertApimlProfileInfoToProfileConfig).toHaveBeenCalledTimes(1); expect(mockLogin).toHaveBeenCalledTimes(1); - expect(response.profiles.base.secure).not.toContain("tokenValue"); - expect(response.profiles.base.properties.tokenType).not.toBeDefined(); - expect(response.profiles.base.properties.tokenValue).not.toBeDefined(); + expect(response.profiles.base.secure).toContain("tokenValue"); + expect(response.profiles.base.properties.tokenType).toBeDefined(); + expect(response.profiles.base.properties.tokenValue).toBeDefined(); }); it("should not have changed - rejectUnauthorized flag true", async () => { diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index 46928ef2ba..ed8e086121 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -15,7 +15,7 @@ import * as lodash from "lodash"; import { ZosmfSession } from "@zowe/zosmf-for-zowe-sdk"; import { BaseAutoInitHandler, AbstractSession, ICommandArguments, IConfig, IConfigProfile, ISession, IHandlerResponseApi, IHandlerParameters, SessConstants, ImperativeConfig, - ImperativeError, RestClientError, TextUtils, ConfigUtils + ImperativeError, RestClientError, TextUtils } from "@zowe/imperative"; import { IApimlProfileInfo, IAutoInitRpt, IProfileRpt, Login, Services } from "@zowe/core-for-zowe-sdk"; @@ -72,7 +72,6 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { // Login with token authentication first, so we can support certificates if ((session.ISession.user && session.ISession.password) || (session.ISession.cert && session.ISession.certKey)) { // If it is basic authentication, we need to set the auth type. - if (session.ISession.password) { session.ISession.type = SessConstants.AUTH_TYPE_TOKEN; } if (session.ISession.tokenType == null) { session.ISession.tokenType = SessConstants.TOKEN_TYPE_APIML; } @@ -104,18 +103,14 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { } const profileConfig = Services.convertApimlProfileInfoToProfileConfig(profileInfos); + const config = ImperativeConfig.instance.config; // Check to see if there is an active base profile to avoid creating a new one named "base" - let activeBaseProfile: string; - try { - activeBaseProfile = ConfigUtils.getActiveProfileName("base", params.arguments); - } catch (err) { - // do nothing - } + let activeBaseProfile = params.arguments[`${this.mProfileType}-profile`] || config?.properties?.defaults?.[this.mProfileType]; // Populate the config with base profile information if (activeBaseProfile == null) { - profileConfig.profiles.base = { - type: "base", + profileConfig.profiles[this.mProfileType] = { + type: this.mProfileType, properties: { host: session.ISession.hostname, port: session.ISession.port, @@ -123,16 +118,40 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { }, secure: [] }; - profileConfig.defaults.base = "base"; + profileConfig.defaults[this.mProfileType] = this.mProfileType; + activeBaseProfile = this.mProfileType; + } else { + lodash.set(profileConfig, config.api.profiles.getProfilePathFromName(activeBaseProfile), { + type: this.mProfileType, + properties: { + ...config.api.profiles.get(activeBaseProfile), + host: session.ISession.hostname ?? params.arguments.host, + port: session.ISession.port ?? params.arguments.port, + rejectUnauthorized: session.ISession.rejectUnauthorized ?? params.arguments.rejectUnauthorized + }, + secure: [] + }); + } - if (session.ISession.tokenType != null && session.ISession.tokenValue != null) { - profileConfig.profiles.base.properties.tokenType = session.ISession.tokenType; - profileConfig.profiles.base.properties.tokenValue = session.ISession.tokenValue; - profileConfig.profiles.base.secure.push("tokenValue"); - } + if (session.ISession.tokenType != null && session.ISession.tokenValue != null) { + const expandedBaseProfilePath = config.api.profiles.getProfilePathFromName(activeBaseProfile); + lodash.get(profileConfig, expandedBaseProfilePath).properties.tokenType = session.ISession.tokenType; + lodash.get(profileConfig, expandedBaseProfilePath).properties.tokenValue = session.ISession.tokenValue; + lodash.get(profileConfig, expandedBaseProfilePath).secure.push("tokenValue"); } this.recordProfilesFound(profileInfos); + + // Report whether or not we created a base profile in this auto-init execution + this.mAutoInitReport.profileRpts.push({ + profName: this.mProfileType, + profType: this.mProfileType, + changeForProf: activeBaseProfile == null ? "created" : "modified", + basePath: null, + pluginNms: [], + altProfiles: [], + baseOverrides: [] + }) return profileConfig; } @@ -186,7 +205,7 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { // report plugins using this profile (except for base profiles) let loopCount: number; if (nextProfRpt.pluginNms.length > 0) { - if (nextProfRpt.profType !== "base") { + if (nextProfRpt.profType !== this.mProfileType) { loopCount = 1; for (const pluginNm of nextProfRpt.pluginNms) { if (loopCount == 1) { @@ -469,14 +488,14 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { return; // default base profile is undefined } - const baseProfile = lodash.get(configJson, configApi.profiles.expandPath(baseProfileName)) as IConfigProfile; + const baseProfile = lodash.get(configJson, configApi.profiles.getProfilePathFromName(baseProfileName)) as IConfigProfile; if (baseProfile == null) { return; // default base profile is invalid } for (const profileRpt of this.mAutoInitReport.profileRpts) { if (profileRpt.changeForProf === this.MODIFIED_MSG && profileRpt.profType !== "base") { - const serviceProfile = lodash.get(configJson, configApi.profiles.expandPath(profileRpt.profName)) as IConfigProfile; + const serviceProfile = lodash.get(configJson, configApi.profiles.getProfilePathFromName(profileRpt.profName)) as IConfigProfile; for (const [name, value] of Object.entries(baseProfile.properties)) { if (serviceProfile.properties[name] != null && serviceProfile.properties[name] !== baseProfile.properties[name]) { profileRpt.baseOverrides.push({ From c2d5a706419900bedc3fa00cf0c97a493f56ad03 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 28 Jul 2023 13:58:50 +0000 Subject: [PATCH 24/29] change wording to fix #1341 Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../__tests__/rest/__unit__/ZosmfRestClient.unit.test.ts | 3 ++- packages/core/src/rest/ZosmfRestClient.ts | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/core/__tests__/rest/__unit__/ZosmfRestClient.unit.test.ts b/packages/core/__tests__/rest/__unit__/ZosmfRestClient.unit.test.ts index 684795227f..e566b660d0 100644 --- a/packages/core/__tests__/rest/__unit__/ZosmfRestClient.unit.test.ts +++ b/packages/core/__tests__/rest/__unit__/ZosmfRestClient.unit.test.ts @@ -160,7 +160,8 @@ describe("ZosmfRestClient tests", () => { expect(processedError.msg).toContain("Fake token error"); expect(processedError.msg).toContain("This operation requires authentication."); expect(processedError.msg).toContain("Token is not valid or expired"); - expect(processedError.msg).toContain("For CLI usage, see `zowe auth login apiml --help`"); + expect(processedError.msg).toContain("To obtain a new valid token, use the following command: `zowe config secure`"); + expect(processedError.msg).toContain("For CLI usage, see `zowe config secure --help`"); expect(processedError.causeErrors).toEqual('{"Error": "Fake token error"}'); expect(processedError.additionalDetails).not.toBeDefined(); }); diff --git a/packages/core/src/rest/ZosmfRestClient.ts b/packages/core/src/rest/ZosmfRestClient.ts index c9aa4f8981..3a421e9ce9 100644 --- a/packages/core/src/rest/ZosmfRestClient.ts +++ b/packages/core/src/rest/ZosmfRestClient.ts @@ -123,7 +123,8 @@ export class ZosmfRestClient extends RestClient { "You must either connect with username and password or provide a base path."; } else { original.msg += "\nToken is not valid or expired.\n" + - "For CLI usage, see `zowe auth login apiml --help`"; + "To obtain a new valid token, use the following command: `zowe config secure`\n" + + "For CLI usage, see `zowe config secure --help`"; } // TODO: Add PFX support in the future } else if (this.session.ISession.type === SessConstants.AUTH_TYPE_CERT_PEM) { @@ -147,8 +148,9 @@ export class ZosmfRestClient extends RestClient { original.additionalDetails = `Token type "${SessConstants.TOKEN_TYPE_APIML}" requires base path to be defined.\n\n` + "You must either connect with username and password or provide a base path."; } else { - original.additionalDetails = "Token is not valid or expired.\n\n" + - "For CLI usage, see `zowe auth login apiml --help`"; + original.additionalDetails = "Token is not valid or expired.\n" + "To obtain a new valid token, use the following command: `zowe config secure`\n" + + "For CLI usage, see `zowe config secure --help`"; } // TODO: Add PFX support in the future } else if (this.session.ISession.type === SessConstants.AUTH_TYPE_CERT_PEM) { From 0dab8dc81579758aaf96d83535a21dc238bee081 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Fri, 28 Jul 2023 14:14:59 +0000 Subject: [PATCH 25/29] address PR comments and lint issues Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../src/config/auto-init/ApimlAutoInitHandler.ts | 2 +- .../auth/__unit__/Logout.apiml.unit.test.ts | 4 ++-- .../__snapshots__/Login.apiml.unit.test.ts.snap | 2 +- packages/core/src/auth/Login.ts | 15 +++++++++------ packages/core/src/rest/ZosmfRestClient.ts | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index ed8e086121..ffb5761cff 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -151,7 +151,7 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { pluginNms: [], altProfiles: [], baseOverrides: [] - }) + }); return profileConfig; } diff --git a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts index 30c76a735e..82589feb72 100644 --- a/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts +++ b/packages/core/__tests__/auth/__unit__/Logout.apiml.unit.test.ts @@ -97,9 +97,9 @@ describe("Auth Logout APIML unit tests", () => { expect(caughtError instanceof ImperativeError).toEqual(true); return caughtError; }; - // Token is invalid (logged out bu tnot expired) + // Token is invalid (logged out but not expired) expect(await runTest("org.zowe.apiml.security.query.invalidToken")).toBeDefined(); - // Token is expored (old token) + // Token is expired (old token) expect(await runTest("org.zowe.apiml.security.expiredToken")).toBeDefined(); // Token is not APIML token expect(await runTest("org.zowe.apiml.security.query.tokenNotProvided")).toBeDefined(); diff --git a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap index 599410d527..d576559c55 100644 --- a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap +++ b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap @@ -8,7 +8,7 @@ REST API Failure with HTTP(S) status 401 Host: undefined Port: undefined -Base Path: +Base Path: undefined Resource: undefined Request: undefined Headers: undefined diff --git a/packages/core/src/auth/Login.ts b/packages/core/src/auth/Login.ts index 10116ea6ee..22d0e4e4ae 100644 --- a/packages/core/src/auth/Login.ts +++ b/packages/core/src/auth/Login.ts @@ -37,12 +37,15 @@ export class Login { if(!session.ISession.basePath) { session.ISession.basePath = "/"; // prevent basepath requirement error on invalid credentials } - await client.request({ - request: "POST", - resource: LoginConstants.APIML_V1_RESOURCE - }); - if (session.ISession.basePath === "/") { - session.ISession.basePath = AbstractSession.DEFAULT_BASE_PATH; + try { + await client.request({ + request: "POST", + resource: LoginConstants.APIML_V1_RESOURCE + }); + } finally { + if (session.ISession.basePath === "/") { + session.ISession.basePath = undefined; + } } if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { throw new ImperativeError((client as any).populateError({ diff --git a/packages/core/src/rest/ZosmfRestClient.ts b/packages/core/src/rest/ZosmfRestClient.ts index 3a421e9ce9..32ebf73c1a 100644 --- a/packages/core/src/rest/ZosmfRestClient.ts +++ b/packages/core/src/rest/ZosmfRestClient.ts @@ -148,7 +148,7 @@ export class ZosmfRestClient extends RestClient { original.additionalDetails = `Token type "${SessConstants.TOKEN_TYPE_APIML}" requires base path to be defined.\n\n` + "You must either connect with username and password or provide a base path."; } else { - original.additionalDetails = "Token is not valid or expired.\n" + original.additionalDetails = "Token is not valid or expired.\n" + "To obtain a new valid token, use the following command: `zowe config secure`\n" + "For CLI usage, see `zowe config secure --help`"; } From 7a26ab944af6cbc678f012e5e5dd97003bcd8ebb Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:26:09 +0000 Subject: [PATCH 26/29] add note and commented code-block for clarity Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- packages/core/src/auth/Logout.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/core/src/auth/Logout.ts b/packages/core/src/auth/Logout.ts index 6b4b4518aa..e5e15b60c4 100644 --- a/packages/core/src/auth/Logout.ts +++ b/packages/core/src/auth/Logout.ts @@ -65,6 +65,17 @@ export class Logout { } } + /** + * NOTE: We will continue to check for `V2_TOKEN_...` keys until we know for sure that + * invalid credentials do not return a 403 on certain APIML configurations with ACF2 + */ + // if (client.response.statusCode.toString() === "401") { + // errorToThrow = new ImperativeError({ + // msg: "Token is not valid or expired.\n" + + // "For CLI usage, see `zowe auth logout apiml --help`", + // errorCode: client.response.statusCode.toString() + // }); + // } if (errorToThrow) { throw errorToThrow; } From 096a1f46ddf69a920a0ece02e2093210f00d2776 Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:55:55 +0000 Subject: [PATCH 27/29] revert basePath with empty string after login Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap | 2 +- packages/core/src/auth/Login.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap index d576559c55..599410d527 100644 --- a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap +++ b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap @@ -8,7 +8,7 @@ REST API Failure with HTTP(S) status 401 Host: undefined Port: undefined -Base Path: undefined +Base Path: Resource: undefined Request: undefined Headers: undefined diff --git a/packages/core/src/auth/Login.ts b/packages/core/src/auth/Login.ts index 22d0e4e4ae..782e8382fb 100644 --- a/packages/core/src/auth/Login.ts +++ b/packages/core/src/auth/Login.ts @@ -44,7 +44,7 @@ export class Login { }); } finally { if (session.ISession.basePath === "/") { - session.ISession.basePath = undefined; + session.ISession.basePath = AbstractSession.DEFAULT_BASE_PATH; } } if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { From 3c9b388d39d47d7f9f049bf5fdae6ecd8ef9526f Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Tue, 1 Aug 2023 13:56:38 +0000 Subject: [PATCH 28/29] test cleanup and fix reporting bug on created vs modified for base profiles Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../__unit__/ApimlAutoInitHandler.unit.test.ts | 10 ++++++---- .../cli/src/config/auto-init/ApimlAutoInitHandler.ts | 11 ++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts b/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts index fc1d33edfe..8ab3deaff5 100644 --- a/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts +++ b/packages/cli/__tests__/config/auto-init/__unit__/ApimlAutoInitHandler.unit.test.ts @@ -27,7 +27,8 @@ function mockConfigApi(properties: IConfig | undefined): any { }) }, profiles: { - getProfilePathFromName: (name: string) => `profiles.${name}` + getProfilePathFromName: (name: string) => `profiles.${name}`, + get: jest.fn() } }, exists: true, @@ -196,7 +197,7 @@ describe("ApimlAutoInitHandler", () => { const mockGetPluginApimlConfigs = jest.fn().mockReturnValue([]); const mockGetServicesByConfig = jest.fn().mockResolvedValue([]); jest.spyOn(ConfigUtils, "getActiveProfileName").mockReturnValueOnce("base"); - const mockConvertApimlProfileInfoToProfileConfig = jest.fn().mockReturnValue({ + const mockConfigValue: any = { defaults: { base: "base"}, profiles: { "base": { @@ -209,9 +210,10 @@ describe("ApimlAutoInitHandler", () => { } }, plugins: [] - }); + }; + const mockConvertApimlProfileInfoToProfileConfig = jest.fn().mockReturnValue(mockConfigValue); const mockLogin = jest.fn().mockResolvedValue("fakeToken"); - jest.spyOn(ImperativeConfig.instance, "config", "get").mockReturnValue(mockConfigApi(undefined)); + jest.spyOn(ImperativeConfig.instance, "config", "get").mockReturnValue(mockConfigApi(mockConfigValue)); ZosmfSession.createSessCfgFromArgs = mockCreateZosmfSession; Services.getPluginApimlConfigs = mockGetPluginApimlConfigs; diff --git a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts index ffb5761cff..771f060630 100644 --- a/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts +++ b/packages/cli/src/config/auto-init/ApimlAutoInitHandler.ts @@ -106,7 +106,7 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { const config = ImperativeConfig.instance.config; // Check to see if there is an active base profile to avoid creating a new one named "base" let activeBaseProfile = params.arguments[`${this.mProfileType}-profile`] || config?.properties?.defaults?.[this.mProfileType]; - + let baseProfileCreated = false; // Populate the config with base profile information if (activeBaseProfile == null) { profileConfig.profiles[this.mProfileType] = { @@ -120,14 +120,15 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { }; profileConfig.defaults[this.mProfileType] = this.mProfileType; activeBaseProfile = this.mProfileType; + baseProfileCreated = true; } else { lodash.set(profileConfig, config.api.profiles.getProfilePathFromName(activeBaseProfile), { type: this.mProfileType, properties: { ...config.api.profiles.get(activeBaseProfile), - host: session.ISession.hostname ?? params.arguments.host, - port: session.ISession.port ?? params.arguments.port, - rejectUnauthorized: session.ISession.rejectUnauthorized ?? params.arguments.rejectUnauthorized + host: session.ISession.hostname, + port: session.ISession.port, + rejectUnauthorized: session.ISession.rejectUnauthorized, }, secure: [] }); @@ -146,7 +147,7 @@ export default class ApimlAutoInitHandler extends BaseAutoInitHandler { this.mAutoInitReport.profileRpts.push({ profName: this.mProfileType, profType: this.mProfileType, - changeForProf: activeBaseProfile == null ? "created" : "modified", + changeForProf: baseProfileCreated ? "created" : "modified", basePath: null, pluginNms: [], altProfiles: [], From f1660b8d364cada363609027082c264c932922ec Mon Sep 17 00:00:00 2001 From: zFernand0 <37381190+zFernand0@users.noreply.github.com> Date: Tue, 1 Aug 2023 15:39:38 +0000 Subject: [PATCH 29/29] remove hacky basepath workaround Signed-off-by: zFernand0 <37381190+zFernand0@users.noreply.github.com> --- .../Login.apiml.unit.test.ts.snap | 2 +- packages/core/src/auth/Login.ts | 18 +++++------------- packages/core/src/auth/Logout.ts | 7 ------- packages/core/src/rest/ZosmfRestClient.ts | 2 +- 4 files changed, 7 insertions(+), 22 deletions(-) diff --git a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap index 599410d527..d576559c55 100644 --- a/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap +++ b/packages/core/__tests__/auth/__unit__/__snapshots__/Login.apiml.unit.test.ts.snap @@ -8,7 +8,7 @@ REST API Failure with HTTP(S) status 401 Host: undefined Port: undefined -Base Path: +Base Path: undefined Resource: undefined Request: undefined Headers: undefined diff --git a/packages/core/src/auth/Login.ts b/packages/core/src/auth/Login.ts index 782e8382fb..78d6825ec4 100644 --- a/packages/core/src/auth/Login.ts +++ b/packages/core/src/auth/Login.ts @@ -34,19 +34,11 @@ export class Login { `Token type (${session.ISession.tokenType}) for API ML token login must start with 'apimlAuthenticationToken'.`); const client = new ZosmfRestClient(session); - if(!session.ISession.basePath) { - session.ISession.basePath = "/"; // prevent basepath requirement error on invalid credentials - } - try { - await client.request({ - request: "POST", - resource: LoginConstants.APIML_V1_RESOURCE - }); - } finally { - if (session.ISession.basePath === "/") { - session.ISession.basePath = AbstractSession.DEFAULT_BASE_PATH; - } - } + await client.request({ + request: "POST", + resource: LoginConstants.APIML_V1_RESOURCE + }); + if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { throw new ImperativeError((client as any).populateError({ msg: `REST API Failure with HTTP(S) status ${client.response.statusCode}`, diff --git a/packages/core/src/auth/Logout.ts b/packages/core/src/auth/Logout.ts index e5e15b60c4..dcb94659eb 100644 --- a/packages/core/src/auth/Logout.ts +++ b/packages/core/src/auth/Logout.ts @@ -35,9 +35,6 @@ export class Logout { ImperativeExpect.toNotBeNullOrUndefined(session.ISession.tokenValue, "Session token not populated. Unable to log out."); const client = new ZosmfRestClient(session); - if(!session.ISession.basePath) { - session.ISession.basePath = "/"; // prevent basepath requirement error on invalid credentials - } try{ await client.request({ request: "POST", @@ -79,10 +76,6 @@ export class Logout { if (errorToThrow) { throw errorToThrow; } - } finally { - if (session.ISession.basePath === "/") { - session.ISession.basePath = AbstractSession.DEFAULT_BASE_PATH; - } } if (client.response.statusCode !== RestConstants.HTTP_STATUS_204) { diff --git a/packages/core/src/rest/ZosmfRestClient.ts b/packages/core/src/rest/ZosmfRestClient.ts index 32ebf73c1a..0f64ffad7c 100644 --- a/packages/core/src/rest/ZosmfRestClient.ts +++ b/packages/core/src/rest/ZosmfRestClient.ts @@ -143,7 +143,7 @@ export class ZosmfRestClient extends RestClient { ; if (this.session.ISession.type === SessConstants.AUTH_TYPE_BASIC) { original.additionalDetails = "Username or password are not valid or expired.\n\n"; - } else if (this.session.ISession.type === SessConstants.AUTH_TYPE_TOKEN) { + } else if (this.session.ISession.type === SessConstants.AUTH_TYPE_TOKEN && this.session.ISession.tokenValue != null) { if (this.session.ISession.tokenType === SessConstants.TOKEN_TYPE_APIML && !this.session.ISession.basePath) { original.additionalDetails = `Token type "${SessConstants.TOKEN_TYPE_APIML}" requires base path to be defined.\n\n` + "You must either connect with username and password or provide a base path.";