Skip to content

Commit e4447ab

Browse files
committed
Added support for the ltpa token
Signed-off-by: enam-khan <[email protected]>
1 parent 3ff6d32 commit e4447ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+665
-479
lines changed

packages/vsce/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ All notable changes to the "cics-extension-for-zowe" extension will be documente
44

55
## Recent Changes
66

7-
- Enhancement: Create icons for library and Web resources. [#229](https://github.com/zowe/cics-for-zowe-client/issues/229)
7+
- Enhancement: Use LTPA tokens to allow CMCI "sessions". [#217](https://github.com/zowe/
8+
- Enhancement: Create icons for library and Web resources. [#229](https://github.com/zowe/
89

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

packages/vsce/__tests__/__unit__/trees/CICSRegionsContainer.unit.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ describe("Test suite for CICSRegionsContainer", () => {
8787

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

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

104105
it("Should load all regions of plex", async () => {
105106
await sut.loadRegionsInPlex();
106-
107+
107108
expect(getRegionInfoInPlexMock).toHaveBeenCalledTimes(1);
108109
expect(sut.label).toBe("Regions [2/2]");
109110
expect(sut.collapsibleState).toBe(2);

packages/vsce/__tests__/__unit__/trees/CICSSessionTree.unit.test.ts

+43-37
Original file line numberDiff line numberDiff line change
@@ -11,67 +11,73 @@
1111

1212
const getIconFilePathFromNameMock = jest.fn();
1313

14+
import { imperative } from "@zowe/zowe-explorer-api";
1415
import { CICSPlexTree } from "../../../src/trees/CICSPlexTree";
1516
import { CICSRegionTree } from "../../../src/trees/CICSRegionTree";
1617
import { CICSSessionTree } from "../../../src/trees/CICSSessionTree";
1718
import * as globalMocks from "../../__utils__/globalMocks";
1819

20+
1921
jest.mock("@zowe/zowe-explorer-api");
2022
jest.mock("../../../src/utils/iconUtils", () => {
2123
return { getIconFilePathFromName: getIconFilePathFromNameMock };
2224
});
23-
const cicsTreeMock = jest.fn();
25+
const cisutreeMock = jest.fn();
2426
const treeResourceMock = globalMocks.getDummyTreeResources("cicsmanagedregion", "fileName*");
2527
const profile = {
2628
profile: { user: "user", password: "pwd", hostname: "hostname", protocol: "https", type: "basic", rejectUnauthorized: false, port: 8080 },
2729
};
2830
describe("Test suite for CICSSessionTree", () => {
2931
let sut: CICSSessionTree;
32+
let ses: imperative.Session;
3033

31-
beforeEach(() => {
32-
getIconFilePathFromNameMock.mockReturnValue(treeResourceMock.iconPath);
34+
describe("Validation", () => {
3335

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

39-
afterEach(() => {
40-
jest.resetAllMocks();
41-
});
39+
sut = new CICSSessionTree(profile);
40+
sut.isUnauthorized = true;
41+
expect(getIconFilePathFromNameMock).toHaveBeenCalledWith("profile-unverified");
42+
});
4243

43-
describe("Test suite for addRegion", () => {
44-
it("should push CICSRegionTree object into children", () => {
45-
sut.addRegion(cicsTreeMock as any as CICSRegionTree);
46-
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);
44+
afterEach(() => {
45+
jest.resetAllMocks();
4746
});
48-
});
49-
describe("Test suite for addPlex", () => {
50-
it("should push CICSPlexTree object into children", () => {
51-
sut.addPlex(cicsTreeMock as any as CICSPlexTree);
52-
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);
47+
48+
describe("Test suite for addRegion", () => {
49+
it("should push CICSRegionTree object into children", () => {
50+
sut.addRegion(cisutreeMock as any as CICSRegionTree);
51+
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);
52+
});
5353
});
54-
});
55-
describe("Test suite for getChildren", () => {
56-
it("should return an array of childrens", () => {
57-
expect(sut.getChildren().length).toBeGreaterThanOrEqual(0);
54+
describe("Test suite for addPlex", () => {
55+
it("should push CICSPlexTree object into children", () => {
56+
sut.addPlex(cisutreeMock as any as CICSPlexTree);
57+
expect(sut.getChildren().length).toBeGreaterThanOrEqual(1);
58+
});
5859
});
59-
});
60-
describe("Test suite for setUnauthorized", () => {
61-
it("should set isUnauthorized to true", () => {
62-
sut.setUnauthorized();
63-
expect(sut.isUnauthorized).toBeTruthy();
60+
describe("Test suite for getChildren", () => {
61+
it("should return an array of childrens", () => {
62+
expect(sut.getChildren().length).toBeGreaterThanOrEqual(0);
63+
});
6464
});
65-
});
66-
describe("Test suite for setAuthorized", () => {
67-
it("should set isUnauthorized to false", () => {
68-
sut.setAuthorized();
69-
expect(sut.isUnauthorized).toBeFalsy();
65+
describe("Test suite for setUnauthorized", () => {
66+
it("should set isUnauthorized to true", () => {
67+
sut.setUnauthorized();
68+
expect(sut.isUnauthorized).toBeTruthy();
69+
});
7070
});
71-
});
72-
describe("Test suite for getIsUnauthorized", () => {
73-
it("should return the object of isUnauthorized", () => {
74-
expect(sut.getIsUnauthorized()).toBeTruthy();
71+
describe("Test suite for setAuthorized", () => {
72+
it("should set isUnauthorized to false", () => {
73+
sut.setAuthorized();
74+
expect(sut.isUnauthorized).toBeFalsy();
75+
});
76+
});
77+
describe("Test suite for getIsUnauthorized", () => {
78+
it("should return the object of isUnauthorized", () => {
79+
expect(sut.getIsUnauthorized()).toBeTruthy();
80+
});
7581
});
7682
});
7783
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*
10+
*/
11+
12+
const getIconFilePathFromNameMock = jest.fn();
13+
14+
import { imperative } from "@zowe/zowe-explorer-api";
15+
import { CICSSessionTree } from "../../../src/trees/CICSSessionTree";
16+
17+
jest.mock("../../../src/utils/iconUtils", () => {
18+
return { getIconFilePathFromName: getIconFilePathFromNameMock };
19+
});
20+
21+
describe("Test suite for CICSSessionTree", () => {
22+
let sut: CICSSessionTree;
23+
let ses: imperative.Session;
24+
25+
const cicsProfileMock = {
26+
failNotFound: false,
27+
message: "",
28+
name: "A NAME",
29+
profile: {
30+
host: "a.b.c.d",
31+
port: 12345,
32+
rejectUnauthorized: false,
33+
protocol: "http",
34+
user: "A USER",
35+
password: "A PASSWORD",
36+
},
37+
type: "cics"
38+
};
39+
40+
describe("cookies", () => {
41+
42+
beforeEach(() => {
43+
sut = new CICSSessionTree(cicsProfileMock);
44+
});
45+
46+
afterEach(() => {
47+
jest.resetAllMocks();
48+
});
49+
50+
it("Should not store invalid cookie", () => {
51+
const cookie = {
52+
Cookie: "blah=hello"
53+
};
54+
55+
ses = sut.getSession();
56+
ses.storeCookie(cookie);
57+
58+
expect(ses.ISession.tokenType).toEqual("LtpaToken2");
59+
expect(ses.ISession.tokenValue).toBeUndefined();
60+
});
61+
62+
it("Should store valid cookie", () => {
63+
const cookies = {
64+
Cookie: "LtpaToken2=testValue"
65+
};
66+
67+
sut = new CICSSessionTree(cicsProfileMock);
68+
ses = sut.getSession();
69+
70+
ses.storeCookie(cookies);
71+
72+
expect(ses.ISession.tokenType).toEqual("LtpaToken2");
73+
expect(ses.ISession.tokenValue).toEqual("testValue");
74+
});
75+
76+
it("Should store valid cookie if more the one returned", () => {
77+
const cookies = {
78+
Cookie: "blah=hello;LtpaToken2=testValue"
79+
};
80+
81+
sut = new CICSSessionTree(cicsProfileMock);
82+
ses = sut.getSession();
83+
84+
ses.storeCookie(cookies);
85+
86+
expect(ses.ISession.tokenType).toEqual("LtpaToken2");
87+
expect(ses.ISession.tokenValue).toEqual("testValue");
88+
});
89+
});
90+
});

packages/vsce/src/commands/closeLocalFileCommand.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*/
1111

12-
import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk";
12+
import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
1313
import { imperative } from "@zowe/zowe-explorer-api";
1414
import { commands, ProgressLocation, TreeView, window } from "vscode";
1515
import { CICSCombinedLocalFileTree } from "../trees/CICSCombinedTrees/CICSCombinedLocalFileTree";
@@ -19,6 +19,7 @@ import { CICSTree } from "../trees/CICSTree";
1919
import { CICSLocalFileTreeItem } from "../trees/treeItems/CICSLocalFileTreeItem";
2020
import { findSelectedNodes, splitCmciErrorMessage } from "../utils/commandUtils";
2121
import { ICommandParams } from "./ICommandParams";
22+
import { runPutResource } from "../utils/resourceUtils";
2223
import constants from "../utils/constants";
2324

2425
export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
@@ -116,12 +117,18 @@ export function getCloseLocalFileCommand(tree: CICSTree, treeview: TreeView<any>
116117
});
117118
}
118119

119-
function closeLocalFile(
120+
async function closeLocalFile(
120121
session: imperative.AbstractSession,
121122
parms: ICommandParams,
122123
busyDecision: string
123124
): Promise<ICMCIApiResponse> {
124-
const requestBody: any = {
125+
return runPutResource({
126+
session: session,
127+
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
128+
cicsPlex: parms.cicsPlex,
129+
regionName: parms.regionName,
130+
params: {"criteria": `FILE='${parms.name}'`}
131+
}, {
125132
request: {
126133
action: {
127134
$: {
@@ -135,15 +142,5 @@ function closeLocalFile(
135142
},
136143
},
137144
},
138-
};
139-
140-
const options: IGetResourceUriOptions = {
141-
"cicsPlex": parms.cicsPlex,
142-
"regionName": parms.regionName,
143-
"criteria": `FILE='${parms.name}'`
144-
};
145-
146-
const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options);
147-
148-
return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody);
145+
});
149146
}

packages/vsce/src/commands/disableCommands/disableLocalFileCommand.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*/
1111

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

2425
export function getDisableLocalFileCommand(tree: CICSTree, treeview: TreeView<any>) {
2526
return commands.registerCommand("cics-extension-for-zowe.disableLocalFile", async (clickedNode) => {
@@ -110,7 +111,13 @@ function disableLocalFile(
110111
parms: ICommandParams,
111112
busyDecision: string
112113
): Promise<ICMCIApiResponse> {
113-
const requestBody: any = {
114+
return runPutResource({
115+
session: session,
116+
resourceName: CicsCmciConstants.CICS_CMCI_LOCAL_FILE,
117+
cicsPlex: parms.cicsPlex,
118+
regionName: parms.regionName,
119+
params: {"criteria": `FILE='${parms.name}'`}
120+
}, {
114121
request: {
115122
action: {
116123
$: {
@@ -123,16 +130,6 @@ function disableLocalFile(
123130
},
124131
},
125132
},
126-
},
127-
};
128-
129-
const options: IGetResourceUriOptions = {
130-
"cicsPlex": parms.cicsPlex,
131-
"regionName": parms.regionName,
132-
"criteria": `FILE='${parms.name}'`
133-
};
134-
135-
const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_CMCI_LOCAL_FILE, options);
136-
137-
return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody);
133+
}
134+
});
138135
}

packages/vsce/src/commands/disableCommands/disableProgramCommand.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*/
1111

12-
import { CicsCmciConstants, CicsCmciRestClient, ICMCIApiResponse, Utils, IGetResourceUriOptions } from "@zowe/cics-for-zowe-sdk";
12+
import { CicsCmciConstants, ICMCIApiResponse } from "@zowe/cics-for-zowe-sdk";
1313
import { imperative } from "@zowe/zowe-explorer-api";
1414
import { commands, ProgressLocation, TreeView, window } from "vscode";
1515
import { CICSCombinedProgramTree } from "../../trees/CICSCombinedTrees/CICSCombinedProgramTree";
@@ -20,6 +20,7 @@ import { findSelectedNodes } from "../../utils/commandUtils";
2020
import { CICSProgramTreeItem } from "../../trees/treeItems/CICSProgramTreeItem";
2121
import { ICommandParams } from "../ICommandParams";
2222
import constants from "../../utils/constants";
23+
import { runPutResource } from "../../utils/resourceUtils";
2324

2425
/**
2526
* Performs disable on selected CICSProgram nodes.
@@ -102,23 +103,19 @@ export function getDisableProgramCommand(tree: CICSTree, treeview: TreeView<any>
102103
}
103104

104105
function disableProgram(session: imperative.AbstractSession, parms: ICommandParams): Promise<ICMCIApiResponse> {
105-
const requestBody: any = {
106+
return runPutResource({
107+
session: session,
108+
resourceName: CicsCmciConstants.CICS_PROGRAM_RESOURCE,
109+
cicsPlex: parms.cicsPlex,
110+
regionName: parms.regionName,
111+
params: {"criteria": `PROGRAM='${parms.name}'`}
112+
}, {
106113
request: {
107114
action: {
108115
$: {
109116
name: "DISABLE",
110117
},
111118
},
112119
},
113-
};
114-
115-
const options: IGetResourceUriOptions = {
116-
"cicsPlex": parms.cicsPlex,
117-
"regionName": parms.regionName,
118-
"criteria": `PROGRAM='${parms.name}'`
119-
};
120-
121-
const cmciResource = Utils.getResourceUri(CicsCmciConstants.CICS_PROGRAM_RESOURCE, options);
122-
123-
return CicsCmciRestClient.putExpectParsedXml(session, cmciResource, [], requestBody);
120+
});
124121
}

0 commit comments

Comments
 (0)