Skip to content

Commit 39c0aa9

Browse files
committed
resolved conflicts
2 parents efcb0da + b9f6455 commit 39c0aa9

File tree

6 files changed

+105
-14
lines changed

6 files changed

+105
-14
lines changed

bin/helpers/constants.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ const LATEST_VERSION_SYNTAX_REGEX = /\d*.latest(.\d*)?/gm
236236

237237
const AUTH_REGEX = /"auth" *: *{[\s\S]*?}/g
238238

239+
const CLI_ARGS_REGEX = /(?<=("u"|"username"|"k"|"key") *: *)"[^,}]*/g
240+
241+
const RAW_ARGS_REGEX = /(?<=("-u"|"-username"|"-k"|"-key") *, *)"[^,\]]*/g
242+
239243
const ERROR_EXIT_CODE = 1;
240244

241245
const BUILD_FAILED_EXIT_CODE = 3;
@@ -265,6 +269,8 @@ module.exports = Object.freeze({
265269
LATEST_VERSION_SYNTAX_REGEX,
266270
ERROR_EXIT_CODE,
267271
AUTH_REGEX,
272+
CLI_ARGS_REGEX,
273+
RAW_ARGS_REGEX,
268274
REDACTED_AUTH,
269275
REDACTED,
270276
BUILD_FAILED_EXIT_CODE,

bin/helpers/packageInstaller.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
Constants = require('./constants'),
88
process = require('process'),
99
utils = require('./utils'),
10-
{ spawn } = require('child_process');
10+
{ spawn } = require('child_process'),
11+
util = require('util');
1112

1213
let nodeProcess;
1314

@@ -54,16 +55,18 @@ const packageInstall = (packageDir) => {
5455
return new Promise(function (resolve, reject) {
5556
const nodeProcessCloseCallback = (code) => {
5657
if(code == 0) {
58+
logger.info(`Packages were installed locally successfully.`);
5759
resolve('Packages were installed successfully.');
5860
} else {
59-
reject('Packages were not installed successfully.');
61+
logger.error(`Some error occurred while installing packages. Error code ${code}`);
62+
reject('Packages were not installed successfully. Error code ${code}');
6063
}
6164
};
6265
const nodeProcessErrorCallback = (error) => {
63-
logger.error(`Some error occurred while installing packages: ${error}`);
64-
reject(`Packages were not installed successfully.`);
66+
logger.error(`Some error occurred while installing packages: ${util.inspect(error)}`);
67+
reject(`Packages were not installed successfully. Error Description ${util.inspect(error)}`);
6568
};
66-
nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install'], {cwd: packageDir});
69+
nodeProcess = spawn(/^win/.test(process.platform) ? 'npm.cmd' : 'npm', ['install', '--loglevel', 'verbose', '>', '../npm_install_debug.log', '2>&1'], {cwd: packageDir, shell: true});
6770
nodeProcess.on('close', nodeProcessCloseCallback);
6871
nodeProcess.on('error', nodeProcessErrorCallback);
6972
});

bin/helpers/usageReporting.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const cp = require("child_process"),
88
const config = require('./config'),
99
fileLogger = require('./logger').fileLogger,
1010
utils = require('./utils');
11-
12-
const { AUTH_REGEX, REDACTED_AUTH, REDACTED } = require("./constants");
11+
12+
const { AUTH_REGEX, REDACTED_AUTH, REDACTED, CLI_ARGS_REGEX, RAW_ARGS_REGEX } = require("./constants");
1313

1414
function get_version(package_name) {
1515
try {
@@ -193,6 +193,10 @@ function redactRecordCaps(bsConfig, args) {
193193
redactArgs(args);
194194
}
195195

196+
function redactKeys(str, regex, redact) {
197+
return str.replace(regex, redact);
198+
}
199+
196200
function send(args) {
197201
if (isUsageReportingEnabled() === "true") return;
198202

@@ -208,10 +212,12 @@ function send(args) {
208212
runSettings = bsConfig.run_settings;
209213
data.cypress_version = bsConfig.run_settings.cypress_version;
210214
}
211-
212-
sanitizedbsConfig = `${(typeof bsConfig === 'string') ? bsConfig :
213-
JSON.stringify(bsConfig)}`.replace(AUTH_REGEX, REDACTED_AUTH);
214-
215+
216+
sanitizedbsConfig = redactKeys(`${(typeof bsConfig === 'string') ? bsConfig :
217+
JSON.stringify(bsConfig)}`, AUTH_REGEX, REDACTED_AUTH);
218+
args.cli_args = args.cli_args && redactKeys(JSON.stringify(args.cli_args), CLI_ARGS_REGEX, REDACTED);
219+
args.raw_args = args.raw_args && redactKeys(JSON.stringify(args.raw_args), RAW_ARGS_REGEX, REDACTED);
220+
215221
delete args.bstack_config;
216222

217223
let zipUploadDetails = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "browserstack-cypress-cli",
3-
"version": "1.13.0",
3+
"version": "1.13.1",
44
"description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
55
"main": "index.js",
66
"scripts": {

test/unit/bin/helpers/packageInstaller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ describe("packageInstaller", () => {
256256
})
257257
.catch((error) => {
258258
spawnStub.restore();
259-
chai.assert.equal(error, "Packages were not installed successfully.")
259+
chai.assert.equal(error, "Packages were not installed successfully. Error code 1")
260260
});
261261
});
262262
});

test/unit/bin/helpers/usageReporting.js

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const cp = require("child_process"),
22
fs = require("fs");
3+
const { CLI_ARGS_REGEX, REDACTED } = require("../../../../bin/helpers/constants");
34

45
const chai = require("chai"),
56
expect = chai.expect,
@@ -9,7 +10,8 @@ const chai = require("chai"),
910
rewire = require("rewire");
1011

1112
const logger = require("../../../../bin/helpers/logger").winstonLogger,
12-
testObjects = require("../../support/fixtures/testObjects");
13+
testObjects = require("../../support/fixtures/testObjects"),
14+
constant = require('../../../../bin/helpers/constants');
1315

1416
const usageReporting = rewire("../../../../bin/helpers/usageReporting");
1517

@@ -27,6 +29,7 @@ bstack_json_found_in_pwd = usageReporting.__get__("bstack_json_found_in_pwd");
2729
cypress_json_found_in_pwd = usageReporting.__get__("cypress_json_found_in_pwd");
2830
npm_global_path = usageReporting.__get__("npm_global_path");
2931
cli_version_and_path = usageReporting.__get__("cli_version_and_path");
32+
redactKeys = usageReporting.__get__("redactKeys");
3033

3134
describe("usageReporting", () => {
3235
describe("_os", () => {
@@ -408,4 +411,77 @@ describe("usageReporting", () => {
408411
expect(ci_environment()).to.be.null;
409412
});
410413
});
414+
415+
describe("redactKeys", () => {
416+
it("filters username and access_key from bstack_config", () => {
417+
const bstack_config = { auth: { username: "test_123", access_key: "test_key" } };
418+
const sanitizedbsConfig = redactKeys(JSON.stringify(bstack_config), constant.AUTH_REGEX, constant.REDACTED_AUTH);
419+
expect(sanitizedbsConfig.includes("[REDACTED]")).to.be.true;
420+
expect(sanitizedbsConfig.includes("test_123")).to.be.false;
421+
expect(sanitizedbsConfig.includes("test_key")).to.be.false;
422+
});
423+
424+
it("filters keys from cli_args", () => {
425+
const cli_args = {
426+
_: [ 'generate-report', 'ceb31f07eb386706ae7ab52ebe5d9b2ebf2fdebf' ],
427+
u: 'test_123',
428+
username: 'test_123',
429+
k: 'test_key',
430+
key: 'test_key',
431+
cf: 'browserstack.json',
432+
'config-file': 'browserstack.json',
433+
configFile: 'browserstack.json',
434+
'$0': 'browserstack-cypress'
435+
}
436+
const sanitizedCliArgs = redactKeys(JSON.stringify(cli_args), constant.CLI_ARGS_REGEX, constant.REDACTED);
437+
expect(sanitizedCliArgs.includes("[REDACTED]")).to.be.true;
438+
expect(sanitizedCliArgs.includes("test_123")).to.be.false;
439+
expect(sanitizedCliArgs.includes("test_key")).to.be.false;
440+
expect(sanitizedCliArgs).to.be.equal("{\"_\":[\"generate-report\",\"ceb31f07eb386706ae7ab52ebe5d9b2ebf2fdebf\"],\"u\":[REDACTED],\"username\":[REDACTED],\"k\":[REDACTED],\"key\":[REDACTED],\"cf\":\"browserstack.json\",\"config-file\":\"browserstack.json\",\"configFile\":\"browserstack.json\",\"$0\":\"browserstack-cypress\"}");
441+
expect(redactKeys(JSON.stringify({
442+
u: 'test_123',
443+
username: 'test_123',
444+
k: 'test_key',
445+
key: 'test_key',
446+
cf: 'browserstack.json',
447+
'config-file': 'browserstack.json',
448+
configFile: 'browserstack.json',
449+
'$0': 'browserstack-cypress'
450+
}), CLI_ARGS_REGEX, REDACTED)).to.be.equal("{\"u\":[REDACTED],\"username\":[REDACTED],\"k\":[REDACTED],\"key\":[REDACTED],\"cf\":\"browserstack.json\",\"config-file\":\"browserstack.json\",\"configFile\":\"browserstack.json\",\"$0\":\"browserstack-cypress\"}");
451+
expect(redactKeys(JSON.stringify({
452+
u: 'test_123',
453+
username: 'test_123',
454+
k: 'test_key',
455+
key: 'test_key'
456+
}), CLI_ARGS_REGEX, REDACTED)).to.be.equal("{\"u\":[REDACTED],\"username\":[REDACTED],\"k\":[REDACTED],\"key\":[REDACTED]}");
457+
});
458+
459+
it("filters keys from raw_args", () => {
460+
const raw_args = [
461+
'generate-report',
462+
'ceb31f07eb386706ae7ab52ebe5d9b2ebf2fdebf',
463+
'-u',
464+
'test_123',
465+
'-k',
466+
'test_key'
467+
]
468+
let sanitizedRawArgs = redactKeys(JSON.stringify(raw_args), constant.RAW_ARGS_REGEX, constant.REDACTED);
469+
expect(sanitizedRawArgs.includes("[REDACTED]")).to.be.true;
470+
expect(sanitizedRawArgs.includes("test_123")).to.be.false;
471+
expect(sanitizedRawArgs.includes("test_key")).to.be.false;
472+
expect(sanitizedRawArgs).to.be.equal("[\"generate-report\",\"ceb31f07eb386706ae7ab52ebe5d9b2ebf2fdebf\",\"-u\",[REDACTED],\"-k\",[REDACTED]]");
473+
raw_args.push('-files', "test.txt");
474+
sanitizedRawArgs = redactKeys(JSON.stringify(raw_args), constant.RAW_ARGS_REGEX, constant.REDACTED);
475+
expect(sanitizedRawArgs.includes("[REDACTED]")).to.be.true;
476+
expect(sanitizedRawArgs.includes("test_123")).to.be.false;
477+
expect(sanitizedRawArgs.includes("test_key")).to.be.false;
478+
expect(sanitizedRawArgs).to.be.equal("[\"generate-report\",\"ceb31f07eb386706ae7ab52ebe5d9b2ebf2fdebf\",\"-u\",[REDACTED],\"-k\",[REDACTED],\"-files\",\"test.txt\"]");
479+
raw_args.shift(); raw_args.shift();
480+
sanitizedRawArgs = redactKeys(JSON.stringify(raw_args), constant.RAW_ARGS_REGEX, constant.REDACTED);
481+
expect(sanitizedRawArgs.includes("[REDACTED]")).to.be.true;
482+
expect(sanitizedRawArgs.includes("test_123")).to.be.false;
483+
expect(sanitizedRawArgs.includes("test_key")).to.be.false;
484+
expect(sanitizedRawArgs).to.be.equal("[\"-u\",[REDACTED],\"-k\",[REDACTED],\"-files\",\"test.txt\"]");
485+
});
486+
})
411487
});

0 commit comments

Comments
 (0)