Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ltpa token #219

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to the IBM® CICS® Plug-in for Zowe CLI will be documented in this file.


## Recent Changes

- Enhancement: Use LTPA tokens to allow CMCI "sessions". [#217](https://github.com/zowe/cics-for-zowe-client/issues/217)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure adding some constants to the package warrants a changelog entry talking about LTPA tokens. I think we should change this to be something along the lines of...

Suggested change
- Enhancement: Use LTPA tokens to allow CMCI "sessions". [#217](https://github.com/zowe/cics-for-zowe-client/issues/217)
- Enhancement: Added CICS resource names to available constants. [#217](https://github.com/zowe/cics-for-zowe-client/issues/217)


## `6.3.3`

- Enhancement: Add requestOptions to getResource and getCache method. [#220](https://github.com/zowe/cics-for-zowe-client/issues/220)
Expand Down
15 changes: 15 additions & 0 deletions packages/sdk/src/constants/CicsCmci.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export const CicsCmciConstants = {
*/
CICS_SYSTEM_MANAGEMENT: "CICSSystemManagement",

/**
* Specifies the required part of the REST interface URI to access initialization parameter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Specifies the required part of the REST interface URI to access initialization parameter
* Specifies the required part of the REST interface URI to access system initialization parameters

*/
CICS_SYSTEM_PARAMETER: "CICSSystemParameter",

/**
* Specifies the required part of the REST interface URI to access program definitions
*/
Expand All @@ -38,6 +43,11 @@ export const CicsCmciConstants = {
*/
CICS_PROGRAM_RESOURCE: "CICSProgram",

/**
* Specifies the required part of the REST interface URI to access library resources
*/
CICS_LIBRARY_RESOURCE: "CICSLibrary",

/**
* Specifies the required part of the REST interface URI to access URIMap definitions
*/
Expand All @@ -48,6 +58,11 @@ export const CicsCmciConstants = {
*/
CICS_DEFINITION_WEBSERVICE: "CICSDefinitionWebService",

/**
* Specifies the required part of the REST interface URI to access tcp/ip service definitions
*/
CICS_DEFINITION_TCPIPSERVICE: "CICSTCPIPService",

Comment on lines +62 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not accurate. The comment and constant name suggests definitions, but the actual resource name suggests the installed resource. Which do you need here?

/*
* Specifies the required part of the REST interface URI to access URIMaps
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/vsce/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ All notable changes to the "cics-extension-for-zowe" extension will be documente

## Recent Changes

- Enhancement:Use LTPA tokens to allow CMCI "sessions" [#217](https://github.com/zowe/cics-for-zowe-client/issues/217)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Enhancement:Use LTPA tokens to allow CMCI "sessions" [#217](https://github.com/zowe/cics-for-zowe-client/issues/217)
- Enhancement: Use LTPA tokens to allow CMCI "sessions" [#217](https://github.com/zowe/cics-for-zowe-client/issues/217)

- Enhancement: Create icons for library and Web resources. [#229](https://github.com/zowe/cics-for-zowe-client/issues/229)

## `3.3.3`

- BugFix: Duplicate CICSplex exist when connecting to a multi-CMAS system. [#227](https://github.com/zowe/cics-for-zowe-client/issues/227)
- Enhancement: Show CMCI error response codes when failing to make requests. [#220](https://github.com/zowe/cics-for-zowe-client/issues/220)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ describe("Test suite for CICSRegionsContainer", () => {

await sut.loadRegionsInCICSGroup(CICSTreeMock as any as CICSTree);

expect(getResourceMock).toHaveBeenCalledWith(sut.getParent().getParent().getSession(), testData);
expect(getResourceMock).toHaveBeenCalledWith(sut.getParent().getParent().getSession(), testData,
{ failOnNoData: false, useCICSCmciRestError: true });
expect(sut.label).toBe("Regions (cics) [1/1]");
expect(sut.collapsibleState).toBe(2);
});
Expand All @@ -103,7 +104,7 @@ describe("Test suite for CICSRegionsContainer", () => {

it("Should load all regions of plex", async () => {
await sut.loadRegionsInPlex();

expect(getRegionInfoInPlexMock).toHaveBeenCalledTimes(1);
expect(sut.label).toBe("Regions [2/2]");
expect(sut.collapsibleState).toBe(2);
Expand Down
78 changes: 41 additions & 37 deletions packages/vsce/__tests__/__unit__/trees/CICSSessionTree.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,66 @@ import { CICSRegionTree } from "../../../src/trees/CICSRegionTree";
import { CICSSessionTree } from "../../../src/trees/CICSSessionTree";
import * as globalMocks from "../../__utils__/globalMocks";


jest.mock("@zowe/zowe-explorer-api");
jest.mock("../../../src/utils/iconUtils", () => {
return { getIconFilePathFromName: getIconFilePathFromNameMock };
});
const cicsTreeMock = jest.fn();
const cisutreeMock = jest.fn();
const treeResourceMock = globalMocks.getDummyTreeResources("cicsmanagedregion", "fileName*");
const profile = {
profile: { user: "user", password: "pwd", hostname: "hostname", protocol: "https", type: "basic", rejectUnauthorized: false, port: 8080 },
};
describe("Test suite for CICSSessionTree", () => {
let sut: CICSSessionTree;

beforeEach(() => {
getIconFilePathFromNameMock.mockReturnValue(treeResourceMock.iconPath);
describe("Validation", () => {

sut = new CICSSessionTree(profile);
sut.isUnauthorized = true;
expect(getIconFilePathFromNameMock).toHaveBeenCalledWith("profile-unverified");
});
beforeEach(() => {
getIconFilePathFromNameMock.mockReturnValue(treeResourceMock.iconPath);

afterEach(() => {
jest.resetAllMocks();
});
sut = new CICSSessionTree(profile);
sut.isUnauthorized = true;
expect(getIconFilePathFromNameMock).toHaveBeenCalledWith("profile-unverified");
});

describe("Test suite for addRegion", () => {
it("should push CICSRegionTree object into children", () => {
sut.addRegion(cicsTreeMock as any as CICSRegionTree);
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);
afterEach(() => {
jest.resetAllMocks();
});
});
describe("Test suite for addPlex", () => {
it("should push CICSPlexTree object into children", () => {
sut.addPlex(cicsTreeMock as any as CICSPlexTree);
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);

describe("Test suite for addRegion", () => {
it("should push CICSRegionTree object into children", () => {
sut.addRegion(cisutreeMock as any as CICSRegionTree);
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);
});
});
});
describe("Test suite for getChildren", () => {
it("should return an array of childrens", () => {
expect(sut.getChildren().length).toBeGreaterThanOrEqual(0);
describe("Test suite for addPlex", () => {
it("should push CICSPlexTree object into children", () => {
sut.addPlex(cisutreeMock as any as CICSPlexTree);
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);
});
});
});
describe("Test suite for setUnauthorized", () => {
it("should set isUnauthorized to true", () => {
sut.setUnauthorized();
expect(sut.isUnauthorized).toBeTruthy();
describe("Test suite for getChildren", () => {
it("should return an array of childrens", () => {
expect(sut.getChildren().length).toBeGreaterThanOrEqual(0);
});
});
});
describe("Test suite for setAuthorized", () => {
it("should set isUnauthorized to false", () => {
sut.setAuthorized();
expect(sut.isUnauthorized).toBeFalsy();
describe("Test suite for setUnauthorized", () => {
it("should set isUnauthorized to true", () => {
sut.setUnauthorized();
expect(sut.isUnauthorized).toBeTruthy();
});
});
});
describe("Test suite for getIsUnauthorized", () => {
it("should return the object of isUnauthorized", () => {
expect(sut.getIsUnauthorized()).toBeTruthy();
describe("Test suite for setAuthorized", () => {
it("should set isUnauthorized to false", () => {
sut.setAuthorized();
expect(sut.isUnauthorized).toBeFalsy();
});
});
describe("Test suite for getIsUnauthorized", () => {
it("should return the object of isUnauthorized", () => {
expect(sut.getIsUnauthorized()).toBeTruthy();
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/

const getIconFilePathFromNameMock = jest.fn();

import { imperative } from "@zowe/zowe-explorer-api";
import { CICSSessionTree } from "../../../src/trees/CICSSessionTree";

jest.mock("../../../src/utils/iconUtils", () => {
return { getIconFilePathFromName: getIconFilePathFromNameMock };
});

describe("Test suite for CICSSessionTree", () => {
let sut: CICSSessionTree;
let ses: imperative.Session;

const cicsProfileMock = {
failNotFound: false,
message: "",
name: "A NAME",
profile: {
host: "a.b.c.d",
port: 12345,
rejectUnauthorized: false,
protocol: "http",
user: "A USER",
password: "A PASSWORD",
},
type: "cics"
};

describe("cookies", () => {

beforeEach(() => {
sut = new CICSSessionTree(cicsProfileMock);
});

afterEach(() => {
jest.resetAllMocks();
});

it("Should not store invalid cookie", () => {
const cookie = {
Cookie: "blah=hello"
};

ses = sut.getSession();
ses.storeCookie(cookie);

expect(ses.ISession.tokenType).toEqual("LtpaToken2");
expect(ses.ISession.tokenValue).toBeUndefined();
});

it("Should store valid cookie", () => {
const cookies = {
Cookie: "LtpaToken2=testValue"
};

sut = new CICSSessionTree(cicsProfileMock);
ses = sut.getSession();

ses.storeCookie(cookies);

expect(ses.ISession.tokenType).toEqual("LtpaToken2");
expect(ses.ISession.tokenValue).toEqual("testValue");
});

it("Should store valid cookie if more the one returned", () => {
const cookies = {
Cookie: "blah=hello;LtpaToken2=testValue"
};

sut = new CICSSessionTree(cicsProfileMock);
ses = sut.getSession();

ses.storeCookie(cookies);

expect(ses.ISession.tokenType).toEqual("LtpaToken2");
expect(ses.ISession.tokenValue).toEqual("testValue");
});
});
});
25 changes: 11 additions & 14 deletions packages/vsce/src/commands/closeLocalFileCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/

import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk";
import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
import { imperative } from "@zowe/zowe-explorer-api";
import { commands, ProgressLocation, TreeView, window } from "vscode";
import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree";
Expand All @@ -19,6 +19,7 @@ import { CICSTree } from "../trees/CICSTree";
import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem";
import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils";
import { ICommandParams } from "./ICommandParams";
import { runPutResource } from "../utils/resourceUtils";
import constants from "../utils/constants";

export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
Expand Down Expand Up @@ -116,12 +117,18 @@ export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView<any>
});
}

function closeLocalFile(
async function closeLocalFile(
session: imperative.AbstractSession,
parms: ICommandParams,
busyDecision: string
): Promise<ICMCIApiResponse> {
const requestBody: any = {
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
cicsPlex: parms.cicsPlex,
regionName: parms.regionName,
params: {"criteria": `FILE='${parms.name}'`}
}, {
request: {
action: {
$: {
Expand All @@ -135,15 +142,5 @@ function closeLocalFile(
},
},
},
};

const options: IGetResourceUriOptions = {
"cicsPlex": parms.cicsPlex,
"regionName": parms.regionName,
"criteria": `FILE='${parms.name}'`
};

const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options);

return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/

import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk";
import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
import { imperative } from "@zowe/zowe-explorer-api";
import { commands, ProgressLocation, TreeView, window } from "vscode";
import { CICSCombinedLocalFileTree } from "../../trees/CICSCombinedTrees/CICSCombinedLocalFileTree";
Expand All @@ -20,6 +20,7 @@ import { findSelectedNodes } from "../../utils/commandUtils";
import { ICommandParams } from "../ICommandParams";
import { CICSLocalFileTreeItem } from "../../trees/treeItems/CICSLocalFileTreeItem";
import constants from "../../utils/constants";
import { runPutResource } from "../../utils/resourceUtils";

export function getDisableLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
return commands.registerCommand("cics-extension-for-zowe.disableLocalFile", async (clickedNode) => {
Expand Down Expand Up @@ -110,7 +111,13 @@ function disableLocalFile(
parms: ICommandParams,
busyDecision: string
): Promise<ICMCIApiResponse> {
const requestBody: any = {
return runPutResource({
session: session,
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
cicsPlex: parms.cicsPlex,
regionName: parms.regionName,
params: {"criteria": `FILE='${parms.name}'`}
}, {
request: {
action: {
$: {
Expand All @@ -123,16 +130,6 @@ function disableLocalFile(
},
},
},
},
};

const options: IGetResourceUriOptions = {
"cicsPlex": parms.cicsPlex,
"regionName": parms.regionName,
"criteria": `FILE='${parms.name}'`
};

const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options);

return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody);
}
});
}
Loading
Loading