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

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions packages/vsce/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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)
- BugFix: Update documentation to reflect changes to fully support V3 profiles. [#209](https://github.com/zowe/cics-for-zowe-client/issues/209)

## `3.3.1`
Expand Down
138 changes: 138 additions & 0 deletions packages/vsce/__tests__/__unit__/trees/CICSSessionTree.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* 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.
*
*/

import { imperative } from "@zowe/zowe-explorer-api";
import { CICSSessionTree } from "../../../src/trees/CICSSessionTree";
import { getIconFilePathFromName } from "../../../src/utils/iconUtils";
import { SessConstants } from "@zowe/imperative";
Fixed Show fixed Hide fixed
import { CICSRegionTree } from "../../../src/trees/CICSRegionTree";

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

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

describe("validation", () => {
beforeEach(() => {
cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.getSession();
});

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

it("Should contain the correct hostname", () => {
expect(ses).toBeInstanceOf(imperative.Session)
expect(ses.ISession.hostname).toEqual(cicsProfileMock.profile.host);
});

it("Should contain the correct port", () => {
expect(ses).toBeInstanceOf(imperative.Session)
expect(ses.ISession.port).toEqual(cicsProfileMock.profile.port);
});

it("Should contain the correct username", () => {
expect(ses).toBeInstanceOf(imperative.Session)
expect(ses.ISession.user).toEqual(cicsProfileMock.profile.user);
});

it("Should contain the correct password", () => {
expect(ses).toBeInstanceOf(imperative.Session)
expect(ses.ISession.password).toEqual(cicsProfileMock.profile.password);
});

it("Should be able to add a region", () => {
const mockRegion = new CICSRegionTree("testRegion", {cicsstate: true}, cst, undefined, undefined);

cst.addRegion(mockRegion);
expect(cst.getChildren().length).toEqual(1);
expect(cst.getChildren()[0].label).toEqual("testRegion");
});

it("Should be able to check if authorized", () => {

cst.setUnauthorized();
expect(cst.getIsUnauthorized()).toBeTruthy();
cst.setAuthorized();
expect(cst.getIsUnauthorized()).toBeFalsy();
cst.setUnauthorized();
expect(cst.getIsUnauthorized()).toBeTruthy();
});

it("Should return null or getParent", () => {
expect(cst.getParent()).toBeNull();
});
});

describe("cookies", () => {

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

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

cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.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"
};

cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.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"
};

cst = new CICSSessionTree(cicsProfileMock, getIconFilePathFromName("profile"));
ses = cst.getSession();

ses.storeCookie(cookies);

expect(ses.ISession.tokenType).toEqual("LtpaToken2");
expect(ses.ISession.tokenValue).toEqual("testValue");
});
});
});
3 changes: 1 addition & 2 deletions packages/vsce/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ export async function activate(context: ExtensionContext) {
try {
plexExpansionHandler(node.element, treeDataProv);
} catch (error) {
const newSessionTree = new CICSSessionTree(node.element.getParent().profile, getIconFilePathFromName("profile-disconnected"));
treeDataProv.loadedProfiles.splice(treeDataProv.getLoadedProfiles().indexOf(node.element.getParent()), 1, newSessionTree);
node.element.getParent().iconPath = getIconFilePathFromName("profile-disconnected");
treeDataProv._onDidChangeTreeData.fire(undefined);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class CICSCombinedLibraryTree extends TreeItem {
let count;
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
criteria,
Expand All @@ -72,6 +73,7 @@ export class CICSCombinedLibraryTree extends TreeItem {
if (recordsCount <= this.incrementCount) {
allLibraries = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand All @@ -80,6 +82,7 @@ export class CICSCombinedLibraryTree extends TreeItem {
} else {
allLibraries = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand Down Expand Up @@ -148,6 +151,7 @@ export class CICSCombinedLibraryTree extends TreeItem {
}
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
criteria,
Expand All @@ -159,6 +163,7 @@ export class CICSCombinedLibraryTree extends TreeItem {
const count = recordsCount;
const allLibraries = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
this.currentCount + 1,
Expand Down Expand Up @@ -203,4 +208,8 @@ export class CICSCombinedLibraryTree extends TreeItem {
public getParent() {
return this.parentPlex;
}

public getSession() {
return this.getParent().getParent().getSession();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class CICSCombinedLocalFileTree extends TreeItem {
try {
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
criteria,
Expand All @@ -72,6 +73,7 @@ export class CICSCombinedLocalFileTree extends TreeItem {
if (recordsCount <= this.incrementCount) {
allLocalFiles = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand All @@ -80,6 +82,7 @@ export class CICSCombinedLocalFileTree extends TreeItem {
} else {
allLocalFiles = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand Down Expand Up @@ -144,6 +147,7 @@ export class CICSCombinedLocalFileTree extends TreeItem {
async () => {
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
this.getParent().getGroupName(),
Expand All @@ -154,6 +158,7 @@ export class CICSCombinedLocalFileTree extends TreeItem {
const count = recordsCount;
const allLocalFiles = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
this.currentCount + 1,
Expand Down Expand Up @@ -198,4 +203,8 @@ export class CICSCombinedLocalFileTree extends TreeItem {
public getParent() {
return this.parentPlex;
}

public getSession() {
return this.getParent().getParent().getSession();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class CICSCombinedPipelineTree extends TreeItem {
let count;
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
criteria,
Expand All @@ -72,6 +73,7 @@ export class CICSCombinedPipelineTree extends TreeItem {
if (recordsCount <= this.incrementCount) {
allPipelines = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand All @@ -80,6 +82,7 @@ export class CICSCombinedPipelineTree extends TreeItem {
} else {
allPipelines = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand Down Expand Up @@ -148,6 +151,7 @@ export class CICSCombinedPipelineTree extends TreeItem {
}
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
criteria,
Expand All @@ -159,6 +163,7 @@ export class CICSCombinedPipelineTree extends TreeItem {
const count = recordsCount;
const allPipelines = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
this.currentCount + 1,
Expand Down Expand Up @@ -203,4 +208,8 @@ export class CICSCombinedPipelineTree extends TreeItem {
public getParent() {
return this.parentPlex;
}

public getSession() {
return this.getParent().getParent().getSession();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class CICSCombinedProgramTree extends TreeItem {
let count;
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
criteria,
Expand All @@ -75,6 +76,7 @@ export class CICSCombinedProgramTree extends TreeItem {
if (recordsCount <= this.incrementCount) {
allPrograms = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand All @@ -83,6 +85,7 @@ export class CICSCombinedProgramTree extends TreeItem {
} else {
allPrograms = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
1,
Expand Down Expand Up @@ -160,6 +163,7 @@ export class CICSCombinedProgramTree extends TreeItem {
}
const cacheTokenInfo = await ProfileManagement.generateCacheToken(
this.parentPlex.getProfile(),
this.getSession(),
this.parentPlex.getPlexName(),
this.constant,
criteria,
Expand All @@ -171,6 +175,7 @@ export class CICSCombinedProgramTree extends TreeItem {
const count = recordsCount;
const allPrograms = await ProfileManagement.getCachedResources(
this.parentPlex.getProfile(),
this.getSession(),
cacheTokenInfo.cacheToken,
this.constant,
this.currentCount + 1,
Expand Down Expand Up @@ -215,4 +220,8 @@ export class CICSCombinedProgramTree extends TreeItem {
public getParent() {
return this.parentPlex;
}

public getSession() {
return this.getParent().getParent().getSession();
}
}
Loading
Loading