Skip to content

Add decompress support #623

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

Merged
merged 7 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions bin/helpers/buildArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
const fs = require('fs'),
path = require('path');

const unzipper = require('unzipper');

const logger = require('./logger').winstonLogger,
utils = require("./utils"),
Constants = require("./constants"),
config = require("./config");

const request = require('request');
const decompress = require('decompress');


let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
Expand Down Expand Up @@ -127,10 +126,13 @@ const downloadAndUnzip = async (filePath, fileName, url) => {

const unzipFile = async (filePath, fileName) => {
return new Promise( async (resolve, reject) => {
await unzipper.Open.file(path.join(filePath, fileName))
.then(d => d.extract({path: filePath, concurrency: 5}))
.catch((err) => reject(err));
resolve();
await decompress(path.join(filePath, fileName), filePath)

Check warning

Code scanning / Semgrep

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

Detected possible user input going into a `path.join` or `path.resolve` function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Check warning

Code scanning / Semgrep

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

Detected possible user input going into a `path.join` or `path.resolve` function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.
.then((files) => {
resolve();
})
.catch((error) => {
reject(error);
});
});
}

Expand Down
17 changes: 9 additions & 8 deletions bin/helpers/reporterHTML.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require('fs'),
path = require('path'),
request = require('request'),
unzipper = require('unzipper'),
logger = require('./logger').winstonLogger,
utils = require("./utils"),
Constants = require('./constants'),
config = require("./config");
config = require("./config"),
decompress = require('decompress');

let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
let options = {
Expand Down Expand Up @@ -150,14 +150,15 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {

const unzipFile = async (filePath, fileName) => {
return new Promise( async (resolve, reject) => {
await unzipper.Open.file(path.join(filePath, fileName))
.then(d => d.extract({path: filePath, concurrency: 5}))
.catch((err) => {
reject(err);
process.exitCode = Constants.ERROR_EXIT_CODE;
});
await decompress(path.join(filePath, fileName), filePath)

Check warning

Code scanning / Semgrep

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

Detected possible user input going into a `path.join` or `path.resolve` function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.

Check warning

Code scanning / Semgrep

Semgrep Finding: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal

Detected possible user input going into a `path.join` or `path.resolve` function. This could possibly lead to a path traversal vulnerability, where the attacker can access arbitrary files stored in the file system. Instead, be sure to sanitize or validate user input first.
.then((files) => {
let message = "Unzipped the json and html successfully."
resolve(message);
})
.catch((error) => {
reject(error);
process.exitCode = Constants.ERROR_EXIT_CODE;
});
});
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
"request": "2.88.2",
"requestretry": "7.1.0",
"table": "5.4.6",
"unzipper": "0.10.11",
"update-notifier": "5.1.0",
"uuid": "8.3.2",
"windows-release": "^5.1.0",
"winston": "2.4.4",
"yargs": "14.2.3"
"yargs": "14.2.3",
"decompress": "4.2.1"
},
"repository": {
"type": "git",
Expand Down
36 changes: 35 additions & 1 deletion test/unit/bin/helpers/reporterHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const chai = require("chai"),
const fs = require('fs'),
path = require('path'),
request = require('request'),
unzipper = require('unzipper');
decompress = require('decompress');
Constants = require("../../../../bin/helpers/constants"),
logger = require("../../../../bin/helpers/logger").winstonLogger,
testObjects = require("../../support/fixtures/testObjects"),
Expand Down Expand Up @@ -241,6 +241,40 @@ describe("calls API to generate report", () => {
});
});

describe("unzipFile", () => {
var sandbox;
beforeEach(() => {
sandbox = sinon.createSandbox();
});

afterEach(() => {
sandbox.restore();
sinon.restore();
});

it("calls unzip and resolves with success message", () => {
let pathStub = sinon.stub(path, 'join');
pathStub.calledOnceWith('abc','efg.txt');
let decompressStub = sandbox.stub().returns(Promise.resolve("Unzipped the json and html successfully."));
let rewireReporterHTML = rewire('../../../../bin/helpers/reporterHTML');
rewireReporterHTML.__set__('decompress', decompressStub);
let unzipFile = rewireReporterHTML.__get__('unzipFile')
unzipFile('abc', 'efg');
});

it("calls unzip and rejects with error message on failure", () => {
let pathStub = sinon.stub(path, 'join');
pathStub.calledOnceWith('abc','efg.txt');
let processStub = sinon.stub(process, 'exit');
processStub.returns(Constants.ERROR_EXIT_CODE)
let decompressStub = sandbox.stub().returns(Promise.reject("Error"));
let rewireReporterHTML = rewire('../../../../bin/helpers/reporterHTML');
rewireReporterHTML.__set__('decompress', decompressStub);
let unzipFile = rewireReporterHTML.__get__('unzipFile')
unzipFile('abc', 'efg');
});
});

describe("generateCypressBuildReport", () => {
var sandbox;
beforeEach(() => {
Expand Down