Skip to content

Commit 0c57235

Browse files
committed
resolved comments
1 parent efaeef2 commit 0c57235

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

bin/helpers/capabilityHelper.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,11 @@ const validate = (bsConfig, args) => {
241241
logger.warn(Constants.validationMessages.SPEC_TIMEOUT_NOT_PASSED_ERROR);
242242
}
243243

244-
if(!Utils.isUndefined(bsConfig.run_settings["record"])) {
245-
if(Utils.isUndefined(bsConfig.run_settings.projectId)) {
244+
if(!Utils.isUndefined(bsConfig.run_settings["record"]) && String(bsConfig.run_settings["record"]) != 'false') {
245+
if(Utils.isUndefined(bsConfig.run_settings.projectId) && Utils.isUndefined(bsConfig.run_settings["record-key"])) {
246+
logger.warn(Constants.validationMessages.PROJECT_ID_MISSING);
247+
logger.warn(Constants.validationMessages.RECORD_KEY_MISSING);
248+
} else if(Utils.isUndefined(bsConfig.run_settings.projectId)) {
246249
logger.warn(Constants.validationMessages.PROJECT_ID_MISSING);
247250
} else if (Utils.isUndefined(bsConfig.run_settings["record-key"])) {
248251
logger.warn(Constants.validationMessages.RECORD_KEY_MISSING);

bin/helpers/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ module.exports = Object.freeze({
266266
ERROR_EXIT_CODE,
267267
AUTH_REGEX,
268268
REDACTED_AUTH,
269+
REDACTED,
269270
BUILD_FAILED_EXIT_CODE,
270271
SPEC_TIMEOUT_LIMIT
271272
});

bin/helpers/usageReporting.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const config = require('./config'),
99
fileLogger = require('./logger').fileLogger,
1010
utils = require('./utils');
1111

12-
const { AUTH_REGEX, REDACTED_AUTH } = require("./constants");
12+
const { AUTH_REGEX, REDACTED_AUTH, REDACTED } = require("./constants");
1313

1414
function get_version(package_name) {
1515
try {
@@ -172,15 +172,38 @@ function isUsageReportingEnabled() {
172172
return process.env.DISABLE_USAGE_REPORTING;
173173
}
174174

175+
function redactBsConfig(bsConfig) {
176+
if(typeof bsConfig === 'object' && !utils.isUndefined(bsConfig.run_settings)) {
177+
if(!utils.isUndefined(bsConfig.run_settings["projectId"])) { bsConfig.run_settings["projectId"] = REDACTED }
178+
if(!utils.isUndefined(bsConfig.run_settings["record-key"])) { bsConfig.run_settings["record-key"] = REDACTED }
179+
}
180+
}
181+
182+
function redactArgs(args) {
183+
if(typeof args === 'object' && !utils.isUndefined(args.cli_args)) {
184+
if(!utils.isUndefined(args.cli_args["projectId"])) { args.cli_args["projectId"] = REDACTED }
185+
if(!utils.isUndefined(args.cli_args["project-id"])) { args.cli_args["project-id"] = REDACTED }
186+
if(!utils.isUndefined(args.cli_args["record-key"])) { args.cli_args["record-key"] = REDACTED }
187+
if(!utils.isUndefined(args.cli_args["recordKey"])) { args.cli_args["recordKey"] = REDACTED }
188+
}
189+
}
190+
191+
function redactRecordCaps(bsConfig, args) {
192+
redactBsConfig(bsConfig);
193+
redactArgs(args);
194+
}
195+
175196
function send(args) {
176197
if (isUsageReportingEnabled() === "true") return;
177198

178199
let bsConfig = JSON.parse(JSON.stringify(args.bstack_config));
179200
let runSettings = "";
180201
let sanitizedbsConfig = "";
181202
let cli_details = cli_version_and_path(bsConfig);
182-
let data = utils.isUndefined(args.data) ? {} : args.data;
183203

204+
redactRecordCaps(bsConfig, args);
205+
206+
let data = utils.isUndefined(args.data) ? {} : args.data;
184207
if (bsConfig && bsConfig.run_settings) {
185208
runSettings = bsConfig.run_settings;
186209
data.cypress_version = bsConfig.run_settings.cypress_version;

bin/helpers/utils.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ exports.setRecordKeyFlag = (bsConfig, args) => {
346346
exports.setProjectId = (bsConfig, args) => {
347347
if(!this.isUndefined(args["projectId"])) {
348348
return args["projectId"];
349+
} else if(!this.isUndefined(process.env.CYPRESS_PROJECT_ID)) {
350+
return process.env.CYPRESS_PROJECT_ID;
349351
} else if(!this.isUndefined(bsConfig.run_settings["projectId"])) {
350352
return bsConfig.run_settings["projectId"];
351353
} else {

test/unit/bin/helpers/utils.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,11 +3041,26 @@ describe('utils', () => {
30413041
let args = {
30423042
projectId: "def"
30433043
}
3044+
process.env.CYPRESS_PROJECT_ID = "jkl"
30443045
getCypressJSONStub.returns({ projectId: "ghi" })
30453046
expect(utils.setProjectId(bsConfig, args)).to.eq("def")
3047+
delete process.env.CYPRESS_PROJECT_ID;
30463048
});
30473049

3048-
it("prioritizes projectId passed in the bsConfig if args not passed", () => {
3050+
it("prioritizes env var if args not passed", () => {
3051+
let bsConfig = {
3052+
run_settings: {
3053+
projectId: "abc"
3054+
}
3055+
}
3056+
let args = {};
3057+
process.env.CYPRESS_PROJECT_ID = "jkl"
3058+
getCypressJSONStub.returns({ projectId: "ghi" })
3059+
expect(utils.setProjectId(bsConfig, args)).to.eq("jkl")
3060+
delete process.env.CYPRESS_PROJECT_ID;
3061+
});
3062+
3063+
it("prioritizes projectId passed in the bsConfig if args and env var not passed", () => {
30493064
let bsConfig = {
30503065
run_settings: {
30513066
projectId: "abc"
@@ -3056,7 +3071,7 @@ describe('utils', () => {
30563071
expect(utils.setProjectId(bsConfig, args)).to.eq("abc")
30573072
});
30583073

3059-
it("prioritizes projectId passed in cypress json when no args and bsConfig is passed", () => {
3074+
it("prioritizes projectId passed in cypress json when no args, env var and bsConfig is passed", () => {
30603075
let bsConfig = {
30613076
run_settings: {}
30623077
}

0 commit comments

Comments
 (0)