diff --git a/CHANGELOG.md b/CHANGELOG.md index afd655ac..1fa6c3ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the z/OS FTP Plug-in for Zowe CLI will be documented in this file. +## Recent Changes + +- Add checking the uss file path when upload file or stdin to uss file. + ## `2.1.4` - BugFix: Provide new utility function that checks file names for valid characters [143](https://github.com/zowe/zowe-cli-ftp-plugin/issues/143). diff --git a/__tests__/__unit__/api/UssUtils.test.ts b/__tests__/__unit__/api/UssUtils.test.ts index b607067d..3d378003 100644 --- a/__tests__/__unit__/api/UssUtils.test.ts +++ b/__tests__/__unit__/api/UssUtils.test.ts @@ -9,6 +9,7 @@ * */ +import { ImperativeError } from "@zowe/imperative"; import { UssUtils } from "../../../src/api/UssUtils"; describe("UssUtils", () => { @@ -28,4 +29,12 @@ describe("UssUtils", () => { path = UssUtils.normalizeUnixPath("//home/user1/hello.text"); expect(path).toBe("/home/user1/hello.text"); }); + + it("should throw error when the uss file path is not absolute file Path", () => { + const path = "test.txt"; + const result = () => { + UssUtils.checkAbsoluteFilePath(path); + }; + expect(result).toThrow(ImperativeError); + }); }); diff --git a/__tests__/__unit__/cli/upload/file-to-uss-file/FileToUssFile.Handler.test.ts b/__tests__/__unit__/cli/upload/file-to-uss-file/FileToUssFile.Handler.test.ts index 547b17b7..e745c75a 100644 --- a/__tests__/__unit__/cli/upload/file-to-uss-file/FileToUssFile.Handler.test.ts +++ b/__tests__/__unit__/cli/upload/file-to-uss-file/FileToUssFile.Handler.test.ts @@ -38,5 +38,4 @@ describe("Upload file to data set handler", () => { expect(mockResponse.console.log.mock.calls[0][1]).toBe("local file '/u/user/file1'"); expect(mockResponse.console.log.mock.calls[0][2]).toBe("/u/user/ussfile1"); }); - }); diff --git a/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts b/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts index 09a87630..bb39b238 100644 --- a/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts +++ b/__tests__/__unit__/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts @@ -36,5 +36,4 @@ describe("Upload file to data set handler", () => { expect(mockResponse.console.log.mock.calls[0][1]).toBe("stdin"); expect(mockResponse.console.log.mock.calls[0][2]).toBe("/u/user/ussfile1"); }); - }); diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index eabed1f2..69fa478f 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -20,7 +20,7 @@ "@typescript-eslint/eslint-plugin": "^5.33.0", "@typescript-eslint/parser": "^5.33.0", "@zowe/cli": "^7.18.8", - "@zowe/cli-test-utils": "^7.18.7", + "@zowe/cli-test-utils": "^7.18.11", "@zowe/imperative": "^5.18.3", "chalk": "^2.3.0", "env-cmd": "^10.1.0", @@ -2469,9 +2469,9 @@ } }, "node_modules/@zowe/cli-test-utils": { - "version": "7.18.7", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@zowe/cli-test-utils/-/@zowe/cli-test-utils-7.18.7.tgz", - "integrity": "sha512-1o4nNi7r/rrGngEomGdEVfMRDKdVzEki4M4wEgJCfraCeIG8vr/3INaWUHJX5vjpEIp+yvHH4NN+wSkNzQ7OQw==", + "version": "7.18.11", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@zowe/cli-test-utils/-/@zowe/cli-test-utils-7.18.11.tgz", + "integrity": "sha512-uaCd+u2vYKonN47wRNseX8YQypjfaCO1+q3DXPkatXPWuAPuUOxpDKmPWq42fXdzKJoBdycmarKe4SwkbjEsvw==", "dev": true, "dependencies": { "find-up": "^5.0.0", @@ -15351,9 +15351,9 @@ } }, "@zowe/cli-test-utils": { - "version": "7.18.7", - "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@zowe/cli-test-utils/-/@zowe/cli-test-utils-7.18.7.tgz", - "integrity": "sha512-1o4nNi7r/rrGngEomGdEVfMRDKdVzEki4M4wEgJCfraCeIG8vr/3INaWUHJX5vjpEIp+yvHH4NN+wSkNzQ7OQw==", + "version": "7.18.11", + "resolved": "https://zowe.jfrog.io/zowe/api/npm/npm-release/@zowe/cli-test-utils/-/@zowe/cli-test-utils-7.18.11.tgz", + "integrity": "sha512-uaCd+u2vYKonN47wRNseX8YQypjfaCO1+q3DXPkatXPWuAPuUOxpDKmPWq42fXdzKJoBdycmarKe4SwkbjEsvw==", "dev": true, "requires": { "find-up": "^5.0.0", diff --git a/package.json b/package.json index cf330a57..97ccd94d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@typescript-eslint/eslint-plugin": "^5.33.0", "@typescript-eslint/parser": "^5.33.0", "@zowe/cli": "^7.18.8", - "@zowe/cli-test-utils": "^7.18.7", + "@zowe/cli-test-utils": "^7.18.11", "@zowe/imperative": "^5.18.3", "chalk": "^2.3.0", "env-cmd": "^10.1.0", diff --git a/src/api/UssUtils.ts b/src/api/UssUtils.ts index a56552a3..4a70ffb5 100644 --- a/src/api/UssUtils.ts +++ b/src/api/UssUtils.ts @@ -12,7 +12,7 @@ import * as PATH from "path"; import * as fs from "fs"; -import { IHandlerResponseConsoleApi, IO, Logger } from "@zowe/imperative"; +import { IHandlerResponseConsoleApi, IO, ImperativeError, Logger } from "@zowe/imperative"; import { CoreUtils, TRANSFER_TYPE_ASCII } from "./CoreUtils"; import { StreamUtils } from "./StreamUtils"; import { IDeleteFileOption, IDownloadFileOption, IUploadFileOption } from "./UssInterface"; @@ -201,6 +201,14 @@ export class UssUtils { } } + public static checkAbsoluteFilePath(filePath: string) { + if (!filePath.startsWith('/')) { + throw new ImperativeError({ msg: "Please check the uss file path. The full file path is required."}); + } else { + return filePath; + } + } + private static get log(): Logger { return Logger.getAppLogger(); } diff --git a/src/cli/upload/file-to-uss-file/FileToUssFile.Handler.ts b/src/cli/upload/file-to-uss-file/FileToUssFile.Handler.ts index 2f83650f..b263532c 100644 --- a/src/cli/upload/file-to-uss-file/FileToUssFile.Handler.ts +++ b/src/cli/upload/file-to-uss-file/FileToUssFile.Handler.ts @@ -17,6 +17,7 @@ export default class UploadFileToUssFileHandler extends FTPBaseHandler { public async processFTP(params: IFTPHandlerParams): Promise { const ussFile = UssUtils.normalizeUnixPath(params.arguments.ussFile); + UssUtils.checkAbsoluteFilePath(ussFile); const options = { localFile: params.arguments.file, transferType: params.arguments.binary ? TRANSFER_TYPE_BINARY : TRANSFER_TYPE_ASCII, diff --git a/src/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.ts b/src/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.ts index 942cd23e..11c4c522 100644 --- a/src/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.ts +++ b/src/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler.ts @@ -18,6 +18,7 @@ export default class UploadStdinToUssFileHandler extends FTPBaseHandler { public async processFTP(params: IFTPHandlerParams): Promise { const ussFile = UssUtils.normalizeUnixPath(params.arguments.ussFile); + UssUtils.checkAbsoluteFilePath(ussFile); const content: Buffer | string = await CoreUtils.readStdin(params.stdin); const options = { @@ -30,7 +31,7 @@ export default class UploadStdinToUssFileHandler extends FTPBaseHandler { const successMsg = params.response.console.log("Uploaded from %s to %s ", uploadSource, ussFile); params.response.data.setMessage(successMsg); this.log.info(successMsg); - } + }