From 0aa6e7a7b98dfe3081809f9bc2cb827c518f43b1 Mon Sep 17 00:00:00 2001 From: Qi Liang Date: Thu, 1 Feb 2024 13:59:47 +0800 Subject: [PATCH 1/3] Upload dataset using Buffer Signed-off-by: Qi Liang --- CHANGELOG.md | 6 ++++++ npm-shrinkwrap.json | 4 ++-- package.json | 2 +- src/api/DataSetUtils.ts | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 923c0599..a2912c96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to the z/OS FTP Plug-in for Zowe CLI will be documented in this file. + +## Recent Changes + +- BugFix: Upload dataset using Buffer, stead of string. [2533](https://github.com/zowe/vscode-extension-for-zowe/issues/2533) + + ## `2.1.7` - Update the version of zos-node-accessor to 1.0.16 diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f05bc369..0fe02762 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "@zowe/zos-ftp-for-zowe-cli", - "version": "2.1.7", + "version": "2.1.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@zowe/zos-ftp-for-zowe-cli", - "version": "2.1.7", + "version": "2.1.8", "license": "EPL-2.0", "dependencies": { "zos-node-accessor": "1.0.16" diff --git a/package.json b/package.json index c0db9fec..623dc347 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zowe/zos-ftp-for-zowe-cli", - "version": "2.1.7", + "version": "2.1.8", "author": "Zowe", "repository": { "type": "git", diff --git a/src/api/DataSetUtils.ts b/src/api/DataSetUtils.ts index 78bd45e2..26bb017d 100644 --- a/src/api/DataSetUtils.ts +++ b/src/api/DataSetUtils.ts @@ -142,7 +142,7 @@ export class DataSetUtils { this.log.debug("Attempting to upload to data set '%s' in transfer mode '%s'", dsn, option.transferType); } if (transferType === TRANSFER_TYPE_ASCII) { - content = CoreUtils.addCarriageReturns(content.toString()); + content = Buffer.from(CoreUtils.addCarriageReturns(content.toString())); } await connection.uploadDataset(content, "'" + dsn + "'", transferType, siteparm); } From fb672b3688059a4f30616a4d45bae481a49e17d6 Mon Sep 17 00:00:00 2001 From: Qi Liang Date: Fri, 2 Feb 2024 14:57:31 +0800 Subject: [PATCH 2/3] Change to test uploadDataset from UT Signed-off-by: Qi Liang --- .../StdinToDataSet.Handler.test.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts index 032ec87d..6e9426ef 100644 --- a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts +++ b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts @@ -13,7 +13,7 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils"; import UploadStdinToDataSetHandler from "../../../../../src/cli/upload/stdin-to-data-set/StdinToDataSet.Handler"; import TestUtils from "../../TestUtils"; -describe("Upload file to data set handler", () => { +describe("Upload stdio to data set handler", () => { it("should return no data set if the data set is not found.", async () => { const handler = new UploadStdinToDataSetHandler(); @@ -37,4 +37,31 @@ describe("Upload file to data set handler", () => { expect(mockResponse.console.log.mock.calls[0][2]).toBe("DS1"); }); + it("should upload contents with Buffer.", async () => { + // This case is added to verify https://github.com/zowe/vscode-extension-for-zowe/issues/2533 + // FTP client checks whether the string to put is a local file path first. + // If yes, it puts the whole file; otherwise, it puts the string as the contents. + // On windows, error is thrown when FTP client uses fs.stat() with the file path starting with "//". + + const handler = new UploadStdinToDataSetHandler(); + + CoreUtils.readStdin = jest.fn().mockReturnValue(Promise.resolve(Buffer.from("sss"))); + CoreUtils.addCarriageReturns = jest.fn().mockReturnValue(("sss")); + const mockResponse = TestUtils.getMockResponse(); + const mockUploadDataset = jest.fn(); + const mockParams: any = { + arguments: { + dataSet: "ds1" + }, + connection: { + uploadDataset: mockUploadDataset + }, + response: mockResponse + }; + await handler.processFTP(mockParams); + // The contents to upload must be Buffer. FTP client tries to fs.stat() first, + // if the contents is string. + expect(mockUploadDataset.mock.calls[0][0] instanceof Buffer).toBeTruthy(); + }); + }); From 47c834c0778707a82344d063cc6b6a6329b0a29d Mon Sep 17 00:00:00 2001 From: Qi Liang Date: Fri, 2 Feb 2024 19:26:14 +0800 Subject: [PATCH 3/3] Fix test case title Signed-off-by: Qi Liang --- .../upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts | 2 +- .../upload/stdin-to-uss-file/StdinToUssFile.Handler.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts index 6e9426ef..c682e1f6 100644 --- a/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts +++ b/__tests__/__unit__/cli/upload/stdin-to-data-set/StdinToDataSet.Handler.test.ts @@ -13,7 +13,7 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils"; import UploadStdinToDataSetHandler from "../../../../../src/cli/upload/stdin-to-data-set/StdinToDataSet.Handler"; import TestUtils from "../../TestUtils"; -describe("Upload stdio to data set handler", () => { +describe("Upload stdin to data set handler", () => { it("should return no data set if the data set is not found.", async () => { const handler = new UploadStdinToDataSetHandler(); 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 bb39b238..f45fd362 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 @@ -13,9 +13,9 @@ import { CoreUtils } from "../../../../../src/api/CoreUtils"; import UploadStdinToUssFileHandler from "../../../../../src/cli/upload/stdin-to-uss-file/StdinToUssFile.Handler"; import TestUtils from "../../TestUtils"; -describe("Upload file to data set handler", () => { +describe("Upload stdin to USS file handler", () => { - it("should return no data set if the data set is not found.", async () => { + it("should return no data set if the USS file is not found.", async () => { const handler = new UploadStdinToUssFileHandler(); CoreUtils.readStdin = jest.fn().mockReturnValue(Promise.resolve(Buffer.from("sss")));