Skip to content

Commit 8474805

Browse files
jace-roellanaxcerontraeok
authored
Fix auth check for ssh profiles (#3891)
* init Signed-off-by: jace-roell <[email protected]> * setting configuration Signed-off-by: jace-roell <[email protected]> * refactor retry Signed-off-by: jace-roell <[email protected]> * test updates Signed-off-by: jace-roell <[email protected]> * fix dataset provider function buff builder location Signed-off-by: jace-roell <[email protected]> * ds text fix Signed-off-by: jace-roell <[email protected]> * remove ds handleAuthCall Signed-off-by: jace-roell <[email protected]> * fix fs tests Signed-off-by: jace-roell <[email protected]> * usstree fix Signed-off-by: jace-roell <[email protected]> * fix zoom test Signed-off-by: jace-roell <[email protected]> * auth handler init test Signed-off-by: jace-roell <[email protected]> * test Signed-off-by: jace-roell <[email protected]> * update main Signed-off-by: jace-roell <[email protected]> * patch coverage Signed-off-by: jace-roell <[email protected]> * changelog Signed-off-by: jace-roell <[email protected]> * test fix and unused map Signed-off-by: jace-roell <[email protected]> * fix broken mock Signed-off-by: jace-roell <[email protected]> * fix Signed-off-by: jace-roell <[email protected]> * remove only Signed-off-by: jace-roell <[email protected]> * unused import Signed-off-by: jace-roell <[email protected]> * move maxExtenderRetry to a setting instead of under table Signed-off-by: jace-roell <[email protected]> * track prompts by profile Signed-off-by: jace-roell <[email protected]> * rework to handle no profile object on profile uri Signed-off-by: jace-roell <[email protected]> * remove log statement Signed-off-by: jace-roell <[email protected]> * fix token check Signed-off-by: jace-roell <[email protected]> * init Signed-off-by: jace-roell <[email protected]> * fix inital auth prompt Signed-off-by: jace-roell <[email protected]> * test Signed-off-by: jace-roell <[email protected]> * fix void for init workspace Signed-off-by: jace-roell <[email protected]> * implement comment fixes, search after sso login Signed-off-by: jace-roell <[email protected]> * sso login after search dataset filter Signed-off-by: jace-roell <[email protected]> * shared init test fix Signed-off-by: jace-roell <[email protected]> * check before changing node collapisbleState Signed-off-by: jace-roell <[email protected]> * existing test fixes Signed-off-by: jace-roell <[email protected]> * patch cov Signed-off-by: jace-roell <[email protected]> * log statement Signed-off-by: jace-roell <[email protected]> * remove auth type none check Signed-off-by: jace-roell <[email protected]> * unused import Signed-off-by: jace-roell <[email protected]> * duplicate prompt Signed-off-by: jace-roell <[email protected]> * changelog Signed-off-by: jace-roell <[email protected]> * direct FS calls check profile type for auth prompt Signed-off-by: jace-roell <[email protected]> * remove timeout by default Signed-off-by: jace-roell <[email protected]> * address feedback Signed-off-by: jace-roell <[email protected]> * update setting name to Max Request Retry Signed-off-by: jace-roell <[email protected]> * init Signed-off-by: jace-roell <[email protected]> * unused import Signed-off-by: jace-roell <[email protected]> * changelog Signed-off-by: jace-roell <[email protected]> * Update packages/zowe-explorer/CHANGELOG.md Co-authored-by: anaxceron <[email protected]> Signed-off-by: Jace Roell <[email protected]> * awaitTimeout removal for some UssFs calls, retry wait, handleAuthError dont wait Signed-off-by: jace-roell <[email protected]> * test fixes Signed-off-by: jace-roell <[email protected]> * test commit Signed-off-by: jace-roell <[email protected]> * refactor: Wait for active request to resolve auth prompt Signed-off-by: Trae Yelovich <[email protected]> * update prompting behavior in FS to adhere to prompt description Signed-off-by: Trae Yelovich <[email protected]> * fix: remove extra lockProfile call in retry logic Signed-off-by: Trae Yelovich <[email protected]> * respect retry count Signed-off-by: jace-roell <[email protected]> * change timeout to 30s Signed-off-by: jace-roell <[email protected]> * wip(refactor): Queue FS requests until one succeeds for a profile Signed-off-by: Trae Yelovich <[email protected]> * fix: finish activating before fetching workspaces Signed-off-by: Trae Yelovich <[email protected]> * refactor: skip .vscode calls in data set FS Signed-off-by: Trae Yelovich <[email protected]> * fix failing tests Signed-off-by: jace-roell <[email protected]> * add tests & typedoc for sequential/parallel handling Signed-off-by: Trae Yelovich <[email protected]> * fix: add preceding slash to .vscode check in DS FS Signed-off-by: Trae Yelovich <[email protected]> * refactor: release queued reqs after parallel mode re-enabled Signed-off-by: Trae Yelovich <[email protected]> * address lint errors Signed-off-by: Trae Yelovich <[email protected]> * refactor: waitForUnlock no longer times out >30s Signed-off-by: Trae Yelovich <[email protected]> Co-authored-by: Jace Roell <[email protected]> * wip: remove request retry setting Signed-off-by: jace-roell <[email protected]> * remove try catch on canceled prompt Signed-off-by: jace-roell <[email protected]> * remove check for state of authentication - only consider cancellation Signed-off-by: jace-roell <[email protected]> * fix merge conflict and unused import Signed-off-by: jace-roell <[email protected]> * remove duplication in runSequentialIfEnabled catch block Signed-off-by: Trae Yelovich <[email protected]> * fix workspace extra prmopts Signed-off-by: jace-roell <[email protected]> * changelog update Signed-off-by: jace-roell <[email protected]> * move hasNoAuthType Signed-off-by: jace-roell <[email protected]> * fix tests Signed-off-by: jace-roell <[email protected]> * fix hasNoAuthType reference Signed-off-by: jace-roell <[email protected]> --------- Signed-off-by: jace-roell <[email protected]> Signed-off-by: Jace Roell <[email protected]> Signed-off-by: Trae Yelovich <[email protected]> Co-authored-by: anaxceron <[email protected]> Co-authored-by: Trae Yelovich <[email protected]>
1 parent 4331cf4 commit 8474805

File tree

7 files changed

+60
-10
lines changed

7 files changed

+60
-10
lines changed

packages/zowe-explorer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
1414

1515
### Bug fixes
1616

17+
- Fixed an issue where `ssh` type profiles were throwing errors when making file system calls. [#3891](https://github.com/zowe/zowe-explorer-vscode/pull/3891)
1718
- Fixed duplicate credential prompts that occurred when logging out of SSO with multiple virtual workspaces open. [#3858](https://github.com/zowe/zowe-explorer-vscode/issues/3858)
1819
- Fixed race conditions in parallel file system calls made with invalid credentials. [#3830](https://github.com/zowe/zowe-explorer-vscode/pull/3830)
1920
- Fixed issues seen when user is prompted, having v1 profiles and chooses convert or create new config options.[#3757](https://github.com/zowe/zowe-explorer-vscode/issues/3757)

packages/zowe-explorer/__tests__/__unit__/utils/ProfilesUtils.unit.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ import { SettingsConfig } from "../../../src/configuration/SettingsConfig";
2828
import { Profiles } from "../../../src/configuration/Profiles";
2929
import { ZoweExplorerExtender } from "../../../src/extending/ZoweExplorerExtender";
3030
import { FilterItem } from "../../../src/management/FilterManagement";
31-
import { ProfilesConvertStatus, ProfilesUtils } from "../../../src/utils/ProfilesUtils";
31+
import { ProfilesUtils } from "../../../src/utils/ProfilesUtils";
3232
import { AuthUtils } from "../../../src/utils/AuthUtils";
3333
import { ZoweLocalStorage } from "../../../src/tools/ZoweLocalStorage";
3434
import { Definitions } from "../../../src/configuration/Definitions";
3535
import { createDatasetSessionNode } from "../../__mocks__/mockCreators/datasets";
3636
import { SharedTreeProviders } from "../../../src/trees/shared/SharedTreeProviders";
37+
import { SessConstants } from "@zowe/imperative";
3738

3839
jest.mock("../../../src/tools/ZoweLogger");
3940
jest.mock("../../../src/tools/ZoweLocalStorage");
@@ -42,6 +43,9 @@ jest.mock("vscode");
4243
jest.mock("@zowe/imperative");
4344

4445
describe("ProfilesUtils unit tests", () => {
46+
beforeAll(() => {
47+
(SessConstants as any).AUTH_TYPE_NONE = "none";
48+
});
4549
afterEach(() => {
4650
jest.clearAllMocks();
4751
});
@@ -1501,4 +1505,40 @@ describe("ProfilesUtils unit tests", () => {
15011505
expect(executeCommandMock).toHaveBeenCalledWith("zowe.setupRemoteWorkspaceFolders", "test");
15021506
});
15031507
});
1508+
describe("Profiles unit tests - function hasNoAuthType", () => {
1509+
it("should determine if an ssh profile has an auth type", () => {
1510+
const session = {
1511+
hostname: "example.com",
1512+
port: 22,
1513+
privateKey: "path/to/id_rsa",
1514+
type: "none",
1515+
user: "user123",
1516+
} as any;
1517+
const profile = {
1518+
name: "ssh123",
1519+
type: "ssh",
1520+
message: "",
1521+
failNotFound: false,
1522+
profile: {},
1523+
};
1524+
expect(ProfilesUtils.hasNoAuthType(session, profile)).toBeFalsy();
1525+
});
1526+
1527+
it("should determine if a profile has an auth type", () => {
1528+
const session = {
1529+
hostname: "example.com",
1530+
port: 443,
1531+
type: "none",
1532+
user: "user123",
1533+
} as any;
1534+
const profile = {
1535+
name: "profile123",
1536+
type: "",
1537+
message: "",
1538+
failNotFound: false,
1539+
profile: {},
1540+
};
1541+
expect(ProfilesUtils.hasNoAuthType(session, profile)).toBeTruthy();
1542+
});
1543+
});
15041544
});

packages/zowe-explorer/src/configuration/Profiles.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ export class Profiles extends ProfilesCache {
175175
break;
176176
}
177177

178-
if (usingTokenAuth || (await this.profileHasSecureToken(theProfile))) {
178+
let tokenType: string;
179+
try {
180+
tokenType = ZoweExplorerApiRegister.getInstance().getCommonApi(theProfile).getTokenTypeName();
181+
} catch {}
182+
183+
if (usingTokenAuth || ((await this.profileHasSecureToken(theProfile)) && tokenType)) {
179184
// The profile will need to be reactivated, so remove it from profilesForValidation
180185
this.profilesForValidation = this.profilesForValidation.filter(
181186
(profile) => !(profile.name === theProfile.name && profile.status !== "unverified")

packages/zowe-explorer/src/trees/dataset/DatasetFSProvider.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
9393

9494
const session = ZoweExplorerApiRegister.getInstance().getCommonApi(uriInfo.profile).getSession(uriInfo.profile);
9595
if (
96-
isFetching &&
97-
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_NONE ||
98-
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_TOKEN && !uriInfo.profile.profile.tokenValue))
96+
(isFetching && ProfilesUtils.hasNoAuthType(session.ISession, uriInfo.profile)) ||
97+
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_TOKEN && !uriInfo.profile.profile.tokenValue)
9998
) {
10099
throw vscode.FileSystemError.Unavailable("Profile is using token type but missing a token");
101100
}
@@ -274,7 +273,7 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
274273
const session = ZoweExplorerApiRegister.getInstance().getCommonApi(uriInfo.profile).getSession(uriInfo.profile);
275274

276275
if (
277-
session.ISession.type === imperative.SessConstants.AUTH_TYPE_NONE ||
276+
ProfilesUtils.hasNoAuthType(session.ISession, uriInfo.profile) ||
278277
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_TOKEN && !uriInfo.profile.profile.tokenValue)
279278
) {
280279
throw vscode.FileSystemError.Unavailable("Profile is using token type but missing a token");
@@ -556,7 +555,7 @@ export class DatasetFSProvider extends BaseProvider implements vscode.FileSystem
556555

557556
const session = ZoweExplorerApiRegister.getInstance().getCommonApi(uriInfo.profile).getSession(uriInfo.profile);
558557
if (
559-
session.ISession.type === imperative.SessConstants.AUTH_TYPE_NONE ||
558+
ProfilesUtils.hasNoAuthType(session.ISession, uriInfo.profile) ||
560559
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_TOKEN && !uriInfo.profile.profile.tokenValue)
561560
) {
562561
throw vscode.FileSystemError.Unavailable("Profile is using token type but missing a token");

packages/zowe-explorer/src/trees/shared/SharedInit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ export class SharedInit {
474474
const session = ZoweExplorerApiRegister.getInstance().getCommonApi(uriInfo.profile).getSession(uriInfo.profile);
475475
try {
476476
if (
477-
session.ISession.type === imperative.SessConstants.AUTH_TYPE_NONE ||
477+
ProfilesUtils.hasNoAuthType(session.ISession, uriInfo.profile) ||
478478
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_TOKEN && !uriInfo.profile.profile.tokenValue)
479479
) {
480480
continue;

packages/zowe-explorer/src/trees/uss/UssFSProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
8282
const uriInfo = FsAbstractUtils.getInfoForUri(uri, Profiles.getInstance());
8383
const session = ZoweExplorerApiRegister.getInstance().getCommonApi(uriInfo.profile).getSession(uriInfo.profile);
8484
if (
85-
session.ISession.type === imperative.SessConstants.AUTH_TYPE_NONE ||
85+
ProfilesUtils.hasNoAuthType(session.ISession, uriInfo.profile) ||
8686
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_TOKEN && !uriInfo.profile.profile.tokenValue)
8787
) {
8888
throw vscode.FileSystemError.Unavailable("Profile is using token type but missing a token");
@@ -218,7 +218,7 @@ export class UssFSProvider extends BaseProvider implements vscode.FileSystemProv
218218
const entryExists = this.exists(uri);
219219
const session = ZoweExplorerApiRegister.getInstance().getCommonApi(uriInfo.profile).getSession(uriInfo.profile);
220220
if (
221-
session.ISession.type === imperative.SessConstants.AUTH_TYPE_NONE ||
221+
ProfilesUtils.hasNoAuthType(session.ISession, uriInfo.profile) ||
222222
(session.ISession.type === imperative.SessConstants.AUTH_TYPE_TOKEN && !uriInfo.profile.profile.tokenValue)
223223
) {
224224
throw vscode.FileSystemError.Unavailable("Profile is using token type but missing a token");

packages/zowe-explorer/src/utils/ProfilesUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { AuthUtils } from "./AuthUtils";
2929
import { ZoweLocalStorage } from "../tools/ZoweLocalStorage";
3030
import { Definitions } from "../configuration/Definitions";
3131
import { SharedTreeProviders } from "../trees/shared/SharedTreeProviders";
32+
import { IProfileLoaded, ISession, SessConstants } from "@zowe/imperative";
3233

3334
export class ProfilesUtils {
3435
public static PROFILE_SECURITY: string | boolean = Constants.ZOWE_CLI_SCM;
@@ -752,4 +753,8 @@ export class ProfilesUtils {
752753
}
753754
await vscode.commands.executeCommand("zowe.setupRemoteWorkspaceFolders", extenderType);
754755
}
756+
757+
public static hasNoAuthType(session: ISession, profile: IProfileLoaded): boolean {
758+
return session.type === SessConstants.AUTH_TYPE_NONE && profile.type !== "ssh";
759+
}
755760
}

0 commit comments

Comments
 (0)