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

fix(error): Check if session is valid before calling proxy setup fn #3428

Merged
merged 8 commits into from
Feb 3, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -90,37 +90,43 @@ async function expectApiWithSession<T>({ name, spy, args, transform }: ITestApi<
expect(spy).toHaveBeenCalledWith(fakeSession, ...params);
}

describe("CommonApi", () => {
describe("getSession", () => {
it("returns undefined and does not throw error if the session was not created", () => {
const api = new ZoweExplorerZosmf.CommonApi();
let session: imperative.Session;
expect(() => (session = api.getSession())).not.toThrow();
expect(session).toBe(undefined);
});
it("returns a built session from _getSession and does not throw error", () => {
const api = new ZoweExplorerZosmf.CommonApi(loadedProfile);
let session: imperative.Session;
const _getSessionSpy = jest.spyOn(api as any, "_getSession");
expect(() => (session = api.getSession())).not.toThrow();
expect(_getSessionSpy).toHaveBeenCalledTimes(1);
expect(session).not.toBeUndefined();
});
});
});

describe("ZosmfUssApi", () => {
afterEach(() => {
jest.clearAllMocks();
});

describe("_getSession", () => {
const exampleProfile = {
message: "",
type: "zosmf",
failNotFound: false,
name: "test.zosmf",
profile: {
host: "localhost",
password: "password",
protocol: "http",
user: "aZosmfUser",
...fakeProperties,
},
} as imperative.IProfileLoaded;
const exampleSession = imperative.Session.createFromUrl(new URL("http://localhost"));
exampleSession.ISession.password = exampleProfile.profile?.password;
exampleSession.ISession.user = exampleProfile.profile?.user;
jest.spyOn(ProfilesCache, "getProfileSessionWithVscProxy").mockReturnValueOnce(exampleSession as any);
const exampleSession = Object.assign(Object.create(Object.getPrototypeOf(fakeSession)), fakeSession);
exampleSession.ISession.password = loadedProfile.profile?.password;
exampleSession.ISession.user = loadedProfile.profile?.user;
jest.spyOn(ProfilesCache, "getProfileSessionWithVscProxy").mockReturnValueOnce(exampleSession);

it("should include profile properties in the built session object", () => {
const api = new ZoweExplorerZosmf.UssApi(loadedProfile);

const transformedProps: Record<string, any> = { ...exampleProfile.profile, hostname: exampleProfile.profile?.host, ...fakeProperties };
const transformedProps: Record<string, any> = { ...loadedProfile.profile, hostname: loadedProfile.profile?.host, ...fakeProperties };
delete transformedProps["host"];
delete transformedProps["responseTimeout"];
expect((api as any)._getSession(exampleProfile).mISession).toMatchObject(transformedProps);
expect((api as any)._getSession(loadedProfile).mISession).toMatchObject(transformedProps);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export namespace ZoweExplorerZosmf {
/**
* An implementation of the Zowe Explorer API Common interface for zOSMF.
*/
class CommonApi implements MainframeInteraction.ICommon {
export class CommonApi implements MainframeInteraction.ICommon {
public static getProfileTypeName(): string {
return zosmf.ZosmfProfile.type;
}
Expand All @@ -55,7 +55,7 @@ export namespace ZoweExplorerZosmf {
// todo: initialize and use logging
imperative.Logger.getAppLogger().error(error as string);
}
return ProfilesCache.getProfileSessionWithVscProxy(this.session);
return this.session ? ProfilesCache.getProfileSessionWithVscProxy(this.session) : undefined;
}

private _getSession(serviceProfile: imperative.IProfileLoaded): imperative.Session {
Expand Down
13 changes: 11 additions & 2 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen

### New features and enhancements

- Added Time Started, Time Ended, and Time Submitted job properties to the Jobs table view. [#3055](https://github.com/zowe/zowe-explorer-vscode/issues/3055)
- Implemented copy/paste functionality of data sets within and across LPARs. [#3012](https://github.com/zowe/zowe-explorer-vscode/issues/3012)

### Bug fixes

- Fixed an issue where a TypeError occurred when applying VS Code proxy settings to an invalid session. [#3425](https://github.com/zowe/zowe-explorer-vscode/issues/3425)

## `3.1.0`

### New features and enhancements

- Updated Zowe SDKs to `8.10.4` for technical currency. [#3306](https://github.com/zowe/zowe-explorer-vscode/pull/3306)
- Added expired JSON web token detection for profiles in each tree view (Data Sets, USS, Jobs). When a user performs a search on a profile, they are prompted to log in if their token expired. [#3175](https://github.com/zowe/zowe-explorer-vscode/issues/3175)
- Added integrated terminals for z/OS Unix, TSO, and MVS commands which can be enabled via the `Zowe › Commands: Use Integrated Terminals` setting. [#3079](https://github.com/zowe/zowe-explorer-vscode/pull/3079)
Expand All @@ -19,8 +30,6 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- You can now add multiple partitioned data sets or USS directories to your workspace at once using the "Add to Workspace" feature. [#3324](https://github.com/zowe/zowe-explorer-vscode/issues/3324)
- Exposed read and write access to local storage keys for Zowe Explorer extenders. [#3180](https://github.com/zowe/zowe-explorer-vscode/issues/3180)
- Added `Open with Encoding` to the context menu of Job Spool files. [#1941](https://github.com/zowe/zowe-explorer-vscode/issues/1941)
- Added Time Started, Time Ended, and Time Submitted job properties to the Jobs table view. [#3055](https://github.com/zowe/zowe-explorer-vscode/issues/3055)
- Implemented copy/paste functionality of data sets within and across LPARs. [#3012](https://github.com/zowe/zowe-explorer-vscode/issues/3012)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,8 @@ describe("Profiles Unit Tests - Function createZoweSchema", () => {
});

jest.spyOn(globalMocks.mockProfileInstance, "createNonSecureProfile").mockImplementation();
const expectedValue =
process.platform === "win32"
? "file:\\globalPath\\.zowe\\zowe.config.json"
: "file:/globalPath/.zowe/zowe.config.json".split(path.sep).join(path.posix.sep);

const expectedValue = path.join("file:", "globalPath", ".zowe", "zowe.config.json");

const spyConfig = jest.spyOn(Profiles.getInstance(), "openConfigFile").mockImplementation();
await Profiles.getInstance().createZoweSchema(blockMocks.testDatasetTree);
Expand Down