Skip to content

Commit

Permalink
Merge branch 'main' into fix/list-members-control-chars
Browse files Browse the repository at this point in the history
  • Loading branch information
zFernand0 authored Jun 20, 2023
2 parents e984ccd + 0349fb6 commit 4217a16
Show file tree
Hide file tree
Showing 23 changed files with 288 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
with:
node-version: '16.x'

- name: Install Yarn
run: npm install -g yarn
- name: Install Yarn and Lerna
run: npm install -g yarn lerna@6

- name: Build Source
run: yarn
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.9.0-SNAPSHOT",
"version": "2.10.0-SNAPSHOT",
"command": {
"version": {
"forcePublish": true,
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-plugin-zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to the "eslint-plugin-zowe-explorer" package will be documen

### Bug fixes

## `2.9.0`

### New features and enhancements

### Bug fixes

## `2.8.1`

### New features and enhancements
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-zowe-explorer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-zowe-explorer",
"version": "2.9.0-SNAPSHOT",
"version": "2.10.0-SNAPSHOT",
"description": "Custom ESLint Rules for ZOWE Explorer",
"keywords": [
"eslint",
Expand Down
24 changes: 17 additions & 7 deletions packages/zowe-explorer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t

### New features and enhancements

- Added new optional IZoweTree functions, `addDsTemplate` and `getDSTemplates`.
- Added a new type `DataSetAllocTemplate` that is used for data set creation templates.
- Added optional `cancelJob` function to `ZoweExplorerApi.IJes` interface.
- Added z/OSMF API implementation for `cancelJob` function.
- Added optional `profile` parameter to `IPromptCredentialsOptions` so developers can choose to skip rebuilding the profile with ProfilesCache.
- Fixed error when an extender's extension attempts to access the keyring in a remote VSCode session [#324](https://github.com/zowe/vscode-extension-for-cics/issues/324).

### Bug fixes

- Fixed issue where profiles with authentication tokens were breaking functionality for direct-to-service profiles after user interaction. [#2111](https://github.com/zowe/vscode-extension-for-zowe/issues/2111)

## `2.9.0`

### New features and enhancements

- Added optional IZoweTree functions, `addDsTemplate` and `getDSTemplates`.
- Added a new type `DataSetAllocTemplate` for data set attributes.
- Added optional `cancelJob` function to `ZoweExplorerApi.IJes` interface.
- Added z/OSMF API implementation for `cancelJob` function.
- Added optional `id` variable to `IZoweTreeNode` interface, which can be used to designate a unique ID for a tree node. [#2215](https://github.com/zowe/vscode-extension-for-zowe/issues/2215)
- Fixed error shown by API when accessing the `name` and `type` property of a profile when updating the profile arrays [#2334](https://github.com/zowe/vscode-extension-for-zowe/issues/2334).

## `2.8.1`

### Bug fixes
Expand All @@ -30,9 +41,8 @@ All notable changes to the "zowe-explorer-api" extension will be documented in t
- Added `ZoweVsCodeExtension.customLoggingPath` that can be used to get custom logging path defined in VS Code settings. [#2186](https://github.com/zowe/vscode-extension-for-zowe/issues/2186)
- Added `Poller` utility singleton for handling continuous poll requests: see `Poller.addRequest, Poller.removeRequest` functions.
- Added `pollData` optional function to `IZoweTree` class.
- Added `ZosmfJesApi.downloadSingleSpool` optional api that can be used to download a single spool file in text or binary formats. [#2060](https://github.com/zowe/vscode-extension-for-zowe/issues/2060)
- Added optional `id` variable to `IZoweTreeNode` interface, which can be used to designate a unique ID for a tree node. [#2215](https://github.com/zowe/vscode-extension-for-zowe/issues/2215)
- Added new optional API, `IJes.downloadSingleSpool`, that can be used to download a single spool file in text or binary formats. [#2060](https://github.com/zowe/vscode-extension-for-zowe/issues/2060)
- Created a new optional API, `IJes.downloadSingleSpool`, that can be used to download a single spool file in text or binary formats. [#2060](https://github.com/zowe/vscode-extension-for-zowe/issues/2060)
- Added capability to download a single spool file to in text or binary formats for zOSMF profiles by adopting the new api, `ZosmfJesApi.downloadSingleSpool`. [#2060](https://github.com/zowe/vscode-extension-for-zowe/issues/2060)

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ describe("ProfilesCache", () => {
const fakeLogger = { debug: jest.fn() };
const fakeZoweDir = zowe.getZoweDir();
const readProfilesFromDiskSpy = jest.spyOn(zowe.imperative.ProfileInfo.prototype, "readProfilesFromDisk");
const defaultCredMgrWithKeytarSpy = jest.spyOn(zowe.imperative.ProfileCredentials, "defaultCredMgrWithKeytar");

afterEach(() => {
jest.clearAllMocks();
Expand All @@ -132,6 +133,7 @@ describe("ProfilesCache", () => {
it("getProfileInfo should initialize ProfileInfo API", async () => {
const profInfo = await new ProfilesCache(fakeLogger as unknown as zowe.imperative.Logger, __dirname).getProfileInfo();
expect(readProfilesFromDiskSpy).toHaveBeenCalledTimes(1);
expect(defaultCredMgrWithKeytarSpy).toHaveBeenCalledTimes(1);
const teamConfig = profInfo.getTeamConfig();
expect(teamConfig.appName).toBe("zowe");
expect(teamConfig.paths).toEqual([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { Gui } from "../../../src/globals/Gui";
import { MessageSeverity, IZoweLogger } from "../../../src/logger/IZoweLogger";
import { IProfileLoaded } from "@zowe/imperative";
import { IPromptCredentialsOptions, ZoweVsCodeExtension } from "../../../src/vscode";
import { ZoweExplorerApi } from "../../../src";
import { ProfilesCache, ZoweExplorerApi } from "../../../src";
import { imperative } from "@zowe/cli";

describe("ZoweVsCodeExtension", () => {
const fakeVsce = {
Expand Down Expand Up @@ -328,5 +329,50 @@ describe("ZoweVsCodeExtension", () => {
expect(showInputBoxSpy).toHaveBeenCalledTimes(2);
expect(mockUpdateProperty).toHaveBeenCalledTimes(0);
});

it("should do nothing if profile and sessionName args are not provided", async () => {
const mockUpdateProperty = jest.fn();
jest.spyOn(ZoweVsCodeExtension as any, "profilesCache", "get").mockReturnValue({
getLoadedProfConfig: jest.fn().mockReturnValue({
profile: {},
}),
getProfileInfo: jest.fn().mockReturnValue({
isSecured: jest.fn().mockReturnValue(true),
updateProperty: mockUpdateProperty,
}),
refresh: jest.fn(),
});
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce(undefined);
const profileLoaded = await ZoweVsCodeExtension.updateCredentials({}, undefined as unknown as ZoweExplorerApi.IApiRegisterClient);
expect(profileLoaded).toBeUndefined();
expect(showInputBoxSpy).not.toHaveBeenCalled();
expect(mockUpdateProperty).not.toHaveBeenCalled();
});

it("should not call ProfilesCache.getLoadedProfConfig if profile object is provided", async () => {
const mockUpdateProperty = jest.fn();
jest.spyOn(ZoweVsCodeExtension as any, "profilesCache", "get").mockReturnValue({
getLoadedProfConfig: jest.fn().mockReturnValue({
profile: {
name: "someExampleProfile",
profile: {
user: "testUser",
password: "testPassword",
} as imperative.IProfile,
} as imperative.IProfileLoaded,
}),
getProfileInfo: jest.fn().mockReturnValue({
isSecured: jest.fn().mockReturnValue(true),
updateProperty: mockUpdateProperty,
}),
refresh: jest.fn(),
});
const getLoadedProfConfigSpy = jest.spyOn(ProfilesCache.prototype, "getLoadedProfConfig");
const showInputBoxSpy = jest.spyOn(Gui, "showInputBox").mockResolvedValueOnce("fakeUser").mockResolvedValueOnce(undefined);
const profileLoaded = await ZoweVsCodeExtension.updateCredentials({}, undefined as unknown as ZoweExplorerApi.IApiRegisterClient);
expect(profileLoaded).toBeUndefined();
expect(getLoadedProfConfigSpy).not.toHaveBeenCalled();
expect(showInputBoxSpy).not.toHaveBeenCalled();
});
});
});
2 changes: 1 addition & 1 deletion packages/zowe-explorer-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zowe/zowe-explorer-api",
"version": "2.9.0-SNAPSHOT",
"version": "2.10.0-SNAPSHOT",
"description": "Extensibility API for Zowe Explorer.",
"publisher": "Zowe",
"author": "Zowe",
Expand Down
17 changes: 11 additions & 6 deletions packages/zowe-explorer-api/src/profiles/ProfilesCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { URL } from "url";

import * as zowe from "@zowe/cli";
import { ZoweExplorerApi } from "./ZoweExplorerApi";
import { getSecurityModules } from "../security";

// TODO: find a home for constants
export const CONTEXT_PREFIX = "_";
Expand Down Expand Up @@ -72,8 +73,10 @@ export class ProfilesCache {
this.cwd = cwd != null ? getFullPath(cwd) : undefined;
}

public async getProfileInfo(): Promise<zowe.imperative.ProfileInfo> {
const mProfileInfo = new zowe.imperative.ProfileInfo("zowe");
public async getProfileInfo(envTheia = false): Promise<zowe.imperative.ProfileInfo> {
const mProfileInfo = new zowe.imperative.ProfileInfo("zowe", {
credMgrOverride: zowe.imperative.ProfileCredentials.defaultCredMgrWithKeytar(() => getSecurityModules("keytar", envTheia)),

Check warning on line 78 in packages/zowe-explorer-api/src/profiles/ProfilesCache.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer-api/src/profiles/ProfilesCache.ts#L78

Added line #L78 was not covered by tests
});
await mProfileInfo.readProfilesFromDisk({ homeDir: getZoweDir(), projectDir: this.cwd ?? undefined });
return mProfileInfo;
}
Expand Down Expand Up @@ -104,12 +107,14 @@ export class ProfilesCache {
*/
public updateProfilesArrays(profileLoaded: zowe.imperative.IProfileLoaded): void {
// update allProfiles array
const promptedTypeIndex = this.allProfiles.findIndex((profile) => profile.type === profileLoaded.type && profile.name === profileLoaded.name);
const promptedTypeIndex = this.allProfiles.findIndex(
(profile) => profile?.type === profileLoaded?.type && profile?.name === profileLoaded?.name
);
this.allProfiles[promptedTypeIndex] = profileLoaded;
// checks if default, if true update defaultProfileByType
const defaultProf = this.defaultProfileByType.get(profileLoaded.type);
if (defaultProf.name === profileLoaded.name) {
this.defaultProfileByType.set(profileLoaded.type, profileLoaded);
const defaultProf = this.defaultProfileByType.get(profileLoaded?.type);
if (defaultProf?.name === profileLoaded?.name) {
this.defaultProfileByType.set(profileLoaded?.type, profileLoaded);
}
}

Expand Down
19 changes: 14 additions & 5 deletions packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class ZoweVsCodeExtension {
* @deprecated
*/
public static async promptCredentials(options: IPromptCredentialsOptions): Promise<imperative.IProfileLoaded> {
const loadProfile = await this.profilesCache.getLoadedProfConfig(options.sessionName.trim());
const loadProfile = options.sessionName ? await this.profilesCache.getLoadedProfConfig(options.sessionName.trim()) : options.profile;
if (loadProfile == null) {
return undefined;
}
Expand All @@ -92,7 +92,7 @@ export class ZoweVsCodeExtension {
loadProfile.profile.user = loadSession.user = creds[0];
loadProfile.profile.password = loadSession.password = creds[1];

const upd = { profileName: loadProfile.name, profileType: loadProfile.type };
const upd = { profileName: loadProfile?.name, profileType: loadProfile.type };
await (
await this.profilesCache.getProfileInfo()
).updateProperty({ ...upd, property: "user", value: creds[0], setSecure: options.secure });
Expand All @@ -117,8 +117,17 @@ export class ZoweVsCodeExtension {
const cache = this.profilesCache;
const profInfo = await cache.getProfileInfo();
const setSecure = options.secure ?? profInfo.isSecured();
const loadProfile = await cache.getLoadedProfConfig(options.sessionName, options.sessionType);
const loadSession = loadProfile.profile as imperative.ISession;

if (options.profile == null && options.sessionName == null) {
return undefined;
}

const loadProfile = options.sessionName ? await cache.getLoadedProfConfig(options.sessionName) : options.profile;
const loadSession = loadProfile?.profile as imperative.ISession;

if (loadProfile == null || loadSession == null) {
return undefined;

Check warning on line 129 in packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer-api/src/vscode/ZoweVsCodeExtension.ts#L129

Added line #L129 was not covered by tests
}
const creds = await ZoweVsCodeExtension.promptUserPass({ session: loadSession, ...options });

if (creds && creds.length > 0) {
Expand All @@ -132,7 +141,7 @@ export class ZoweVsCodeExtension {

if (shouldSave || profInfo.usingTeamConfig) {
// v1 write changes to the file, v2 autoStore value determines if written to file
const upd = { profileName: loadProfile.name, profileType: loadProfile.type };
const upd = { profileName: loadProfile?.name, profileType: loadProfile.type };
await profInfo.updateProperty({ ...upd, property: "user", value: creds[0], setSecure });
await profInfo.updateProperty({ ...upd, property: "password", value: creds[1], setSecure });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export interface IPromptCredentialsCommonOptions {
}

export interface IPromptCredentialsOptions extends IPromptCredentialsCommonOptions {
sessionName: string;
profile?: imperative.IProfileLoaded;
sessionName?: string;
sessionType?: string;
secure?: boolean;
}
Expand Down
10 changes: 6 additions & 4 deletions packages/zowe-explorer-ftp-extension/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ All notable changes to the "zowe-explorer-ftp-extension" extension will be docum

### Bug fixes

## `2.9.0`

### Bug fixes

- Fixed an issue with mismatch etag, correcting error message sent to Zowe Explorer to trigger diff editor. [#2277](https://github.com/zowe/vscode-extension-for-zowe/issues/2277)
- Renamed instances of "dataset" to "data set" for consistency across Zowe Explorer.
- Fixed an issue with prompting for credentials by correcting the 401 error when throwing an auth error. [#2334](https://github.com/zowe/vscode-extension-for-zowe/issues/2334)

## `2.8.1`

Expand All @@ -21,10 +27,6 @@ All notable changes to the "zowe-explorer-ftp-extension" extension will be docum
- Updated linter rules and addressed linter errors. [#2184](https://github.com/zowe/vscode-extension-for-zowe/issues/2184)
- Added support for new setting `zowe.files.logsFolder.path` that can be used to override Zowe Explorer logs folder. [#2186](https://github.com/zowe/vscode-extension-for-zowe/issues/2186)

### Bug fixes

- Renamed instances of "dataset" to "data set" for consistency across Zowe Explorer.

## `2.7.0`

### New features and enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AbstractFtpApi } from "../../../src/ZoweExplorerAbstractFtpApi";
import { FtpSession } from "../../../src/ftpSession";
import { FTPConfig, IZosFTPProfile } from "@zowe/zos-ftp-for-zowe-cli";
import { Gui, MessageSeverity } from "@zowe/zowe-explorer-api";
import { imperative } from "@zowe/cli";

jest.mock("zos-node-accessor");

Expand Down Expand Up @@ -75,6 +76,10 @@ describe("AbstractFtpApi", () => {
throw new Error("Failed: missing credentials");
})
);
const imperativeError = new imperative.ImperativeError({
msg: "Rest API failure with HTTP(S) status 401 Authentication error.",
errorCode: `${imperative.RestConstants.HTTP_STATUS_401}`,
});
const instance = new Dummy();
instance.profile = {
profile: {},
Expand All @@ -85,14 +90,9 @@ describe("AbstractFtpApi", () => {
try {
await instance.getStatus(undefined, "zftp");
} catch (err) {
expect(Gui.errorMessage).toHaveBeenCalledWith(
"Invalid Credentials. Please ensure the username and password for undefined are valid or this may lead to a lock-out.",
{
logger: ZoweLogger,
}
);
expect(err).not.toBeUndefined();
expect(err).toBeInstanceOf(Error);
expect(err).toEqual(imperativeError);
}
});

Expand All @@ -104,6 +104,10 @@ describe("AbstractFtpApi", () => {
})
);
const instance = new Dummy();
const imperativeError = new imperative.ImperativeError({
msg: "Rest API failure with HTTP(S) status 401 Authentication error.",
errorCode: `${imperative.RestConstants.HTTP_STATUS_401}`,
});
instance.profile = {
profile: {},
message: undefined,
Expand All @@ -113,11 +117,9 @@ describe("AbstractFtpApi", () => {
try {
await instance.getStatus(undefined, "zftp");
} catch (err) {
expect(Gui.errorMessage).toHaveBeenCalledWith("Something happened", {
logger: ZoweLogger,
});
expect(err).not.toBeUndefined();
expect(err).toBeInstanceOf(Error);
expect(err).toEqual(imperativeError);
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/zowe-explorer-ftp-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Zowe",
"license": "EPL-2.0",
"description": "Adds zFTP support to Zowe Explorer demonstrating how to extend the Zowe Explorer using its extensibility API.",
"version": "2.9.0-SNAPSHOT",
"version": "2.10.0-SNAPSHOT",
"icon": "resources/zowe-ftp-color.png",
"repository": {
"url": "https://github.com/zowe/vscode-extension-for-zowe"
Expand Down Expand Up @@ -48,7 +48,7 @@
},
"dependencies": {
"@zowe/zos-ftp-for-zowe-cli": "2.1.2",
"@zowe/zowe-explorer-api": "2.9.0-SNAPSHOT",
"@zowe/zowe-explorer-api": "2.10.0-SNAPSHOT",
"tmp": "0.2.1"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,11 @@ export abstract class AbstractFtpApi implements ZoweExplorerApi.ICommon {
try {
sessionStatus = await this.ftpClient(this.checkedProfile());
} catch (e) {
if (e instanceof Error) {
/* The errMsg should be consistent with the errMsg in ProfilesUtils.ts of zowe-explorer */
if (e.message.indexOf("failed") !== -1 || e.message.indexOf("missing") !== -1) {
const errMsg =
"Invalid Credentials. Please ensure the username and password for " +
validateProfile?.name +
" are valid or this may lead to a lock-out.";
await Gui.errorMessage(errMsg, { logger: ZoweLogger });
throw new Error();
} else {
await Gui.errorMessage(e.message, { logger: ZoweLogger });
throw new Error();
}
}
const imperativeError = new imperative.ImperativeError({
msg: "Rest API failure with HTTP(S) status 401 Authentication error.",
errorCode: `${imperative.RestConstants.HTTP_STATUS_401}`,
});
throw imperativeError;
}
if (sessionStatus) {
return "active";
Expand Down
Loading

0 comments on commit 4217a16

Please sign in to comment.