Skip to content

Commit 35ee093

Browse files
Adding defaultAuthHash to info and stop commands
1 parent a68b09d commit 35ee093

File tree

4 files changed

+56
-28
lines changed

4 files changed

+56
-28
lines changed

bin/commands/info.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module.exports = function info(args) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
// setting defaultAuthHash to {} if not present and set via env variables or via args.
14+
utils.defaultAuthHash(bsConfig, args);
15+
1316
// accept the username from command line if provided
1417
utils.setUsername(bsConfig, args);
1518

@@ -30,7 +33,7 @@ module.exports = function info(args) {
3033
password: bsConfig.auth.access_key,
3134
},
3235
headers: {
33-
"User-Agent": utils.getUserAgent(),
36+
'User-Agent': utils.getUserAgent(),
3437
},
3538
};
3639

@@ -55,7 +58,7 @@ module.exports = function info(args) {
5558

5659
if (resp.statusCode == 299) {
5760
messageType = Constants.messageTypes.INFO;
58-
errorCode = "api_deprecated";
61+
errorCode = 'api_deprecated';
5962

6063
if (build) {
6164
message = build.message;
@@ -66,14 +69,14 @@ module.exports = function info(args) {
6669
}
6770
} else if (resp.statusCode != 200) {
6871
messageType = Constants.messageTypes.ERROR;
69-
errorCode = "api_failed_build_info";
72+
errorCode = 'api_failed_build_info';
7073

7174
if (build) {
7275
message = `${
7376
Constants.userMessages.BUILD_INFO_FAILED
7477
} with error: \n${JSON.stringify(build, null, 2)}`;
7578
logger.error(message);
76-
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
79+
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
7780
} else {
7881
message = Constants.userMessages.BUILD_INFO_FAILED;
7982
logger.error(message);
@@ -89,7 +92,7 @@ module.exports = function info(args) {
8992
}
9093
}
9194
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
92-
})
95+
});
9396
}).catch(function (err) {
9497
logger.error(err);
9598
utils.setUsageReportingFlag(null, args.disableUsageReporting);

bin/commands/stop.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module.exports = function stop(args) {
1010
let bsConfigPath = utils.getConfigPath(args.cf);
1111

1212
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
13+
// setting defaultAuthHash to {} if not present and set via env variables or via args.
14+
utils.defaultAuthHash(bsConfig, args);
15+
1316
// accept the username from command line if provided
1417
utils.setUsername(bsConfig, args);
1518

@@ -30,7 +33,7 @@ module.exports = function stop(args) {
3033
password: bsConfig.auth.access_key,
3134
},
3235
headers: {
33-
"User-Agent": utils.getUserAgent(),
36+
'User-Agent': utils.getUserAgent(),
3437
},
3538
};
3639

@@ -46,16 +49,16 @@ module.exports = function stop(args) {
4649

4750
logger.info(message);
4851
} else {
49-
let build = null
52+
let build = null;
5053
try {
51-
build = JSON.parse(body)
54+
build = JSON.parse(body);
5255
} catch (error) {
53-
build = null
56+
build = null;
5457
}
5558

5659
if (resp.statusCode == 299) {
5760
messageType = Constants.messageTypes.INFO;
58-
errorCode = "api_deprecated";
61+
errorCode = 'api_deprecated';
5962

6063
if (build) {
6164
message = build.message;
@@ -66,14 +69,14 @@ module.exports = function stop(args) {
6669
}
6770
} else if (resp.statusCode != 200) {
6871
messageType = Constants.messageTypes.ERROR;
69-
errorCode = "api_failed_build_stop";
72+
errorCode = 'api_failed_build_stop';
7073

7174
if (build) {
7275
message = `${
7376
Constants.userMessages.BUILD_STOP_FAILED
7477
} with error: \n${JSON.stringify(build, null, 2)}`;
7578
logger.error(message);
76-
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
79+
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
7780
} else {
7881
message = Constants.userMessages.BUILD_STOP_FAILED;
7982
logger.error(message);
@@ -85,7 +88,7 @@ module.exports = function stop(args) {
8588
}
8689
}
8790
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
88-
})
91+
});
8992
}).catch(function (err) {
9093
logger.error(err);
9194
utils.setUsageReportingFlag(null, args.disableUsageReporting);

test/unit/bin/commands/info.js

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("buildInfo", () => {
3333
return "end";
3434
});
3535
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
36+
defaultAuthHashStub = sandbox.stub();
3637
});
3738

3839
afterEach(() => {
@@ -47,8 +48,8 @@ describe("buildInfo", () => {
4748

4849
let requestStub = sandbox.stub(request, "get").yields(null, { statusCode: 299 }, null);
4950

50-
const info = proxyquire("../../../../bin/commands/info", {
51-
"../helpers/utils": {
51+
const info = proxyquire('../../../../bin/commands/info', {
52+
'../helpers/utils': {
5253
setUsername: setUsernameStub,
5354
setAccessKey: setAccessKeyStub,
5455
validateBstackJson: validateBstackJsonStub,
@@ -57,9 +58,10 @@ describe("buildInfo", () => {
5758
setUsageReportingFlag: setUsageReportingFlagStub,
5859
setCypressConfigFilename: setCypressConfigFilenameStub,
5960
getUserAgent: getUserAgentStub,
60-
getConfigPath: getConfigPathStub
61+
getConfigPath: getConfigPathStub,
62+
defaultAuthHash: defaultAuthHashStub
6163
},
62-
request: { get: requestStub },
64+
request: {get: requestStub},
6365
});
6466

6567
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
@@ -84,8 +86,8 @@ describe("buildInfo", () => {
8486
.stub(request, "get")
8587
.yields(null, { statusCode: 299 }, JSON.stringify(body));
8688

87-
const info = proxyquire("../../../../bin/commands/info", {
88-
"../helpers/utils": {
89+
const info = proxyquire('../../../../bin/commands/info', {
90+
'../helpers/utils': {
8991
setUsername: setUsernameStub,
9092
setAccessKey: setAccessKeyStub,
9193
validateBstackJson: validateBstackJsonStub,
@@ -94,9 +96,10 @@ describe("buildInfo", () => {
9496
setUsageReportingFlag: setUsageReportingFlagStub,
9597
setCypressConfigFilename: setCypressConfigFilenameStub,
9698
getUserAgent: getUserAgentStub,
97-
getConfigPath: getConfigPathStub
99+
getConfigPath: getConfigPathStub,
100+
defaultAuthHash: defaultAuthHashStub
98101
},
99-
request: { get: requestStub },
102+
request: {get: requestStub},
100103
});
101104

102105
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
@@ -128,6 +131,7 @@ describe("buildInfo", () => {
128131
return "end";
129132
});
130133
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
134+
defaultAuthHashStub = sandbox.stub();
131135
});
132136

133137
afterEach(() => {
@@ -144,8 +148,8 @@ describe("buildInfo", () => {
144148
.stub(request, "get")
145149
.yields(null, { statusCode: 400 }, null);
146150

147-
const info = proxyquire("../../../../bin/commands/info", {
148-
"../helpers/utils": {
151+
const info = proxyquire('../../../../bin/commands/info', {
152+
'../helpers/utils': {
149153
setUsername: setUsernameStub,
150154
setAccessKey: setAccessKeyStub,
151155
validateBstackJson: validateBstackJsonStub,
@@ -154,9 +158,10 @@ describe("buildInfo", () => {
154158
setUsageReportingFlag: setUsageReportingFlagStub,
155159
setCypressConfigFilename: setCypressConfigFilenameStub,
156160
getUserAgent: getUserAgentStub,
157-
getConfigPath: getConfigPathStub
161+
getConfigPath: getConfigPathStub,
162+
defaultAuthHash: defaultAuthHashStub
158163
},
159-
request: { get: requestStub },
164+
request: {get: requestStub},
160165
});
161166

162167
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
@@ -198,6 +203,7 @@ describe("buildInfo", () => {
198203
setCypressConfigFilename: setCypressConfigFilenameStub,
199204
getUserAgent: getUserAgentStub,
200205
getConfigPath: getConfigPathStub,
206+
defaultAuthHash: defaultAuthHashStub
201207
},
202208
request: {get: requestStub},
203209
});
@@ -236,6 +242,7 @@ describe("buildInfo", () => {
236242
setCypressConfigFilename: setCypressConfigFilenameStub,
237243
getUserAgent: getUserAgentStub,
238244
getConfigPath: getConfigPathStub,
245+
defaultAuthHash: defaultAuthHashStub
239246
},
240247
request: {get: requestStub},
241248
});
@@ -271,6 +278,7 @@ describe("buildInfo", () => {
271278
return "end";
272279
});
273280
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
281+
defaultAuthHashStub = sandbox.stub();
274282
});
275283

276284
afterEach(() => {
@@ -296,6 +304,7 @@ describe("buildInfo", () => {
296304
setCypressConfigFilename: setCypressConfigFilenameStub,
297305
getUserAgent: getUserAgentStub,
298306
getConfigPath: getConfigPathStub,
307+
defaultAuthHash: defaultAuthHashStub
299308
},
300309
request: {get: requestStub},
301310
});
@@ -329,6 +338,7 @@ describe("buildInfo", () => {
329338
return "end";
330339
});
331340
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
341+
defaultAuthHashStub = sandbox.stub();
332342
});
333343

334344
afterEach(() => {
@@ -337,16 +347,17 @@ describe("buildInfo", () => {
337347
});
338348

339349
it("send usage report if validateBstackJson fails", () => {
340-
const info = proxyquire("../../../../bin/commands/info", {
341-
"../helpers/utils": {
350+
const info = proxyquire('../../../../bin/commands/info', {
351+
'../helpers/utils': {
342352
setUsername: setUsernameStub,
343353
setAccessKey: setAccessKeyStub,
344354
validateBstackJson: validateBstackJsonStub,
345355
getErrorCodeFromErr: getErrorCodeFromErrStub,
346356
sendUsageReport: sendUsageReportStub,
347357
setUsageReportingFlag: setUsageReportingFlagStub,
348358
setCypressConfigFilename: setCypressConfigFilenameStub,
349-
getConfigPath: getConfigPathStub
359+
getConfigPath: getConfigPathStub,
360+
defaultAuthHash: defaultAuthHashStub
350361
},
351362
});
352363

test/unit/bin/commands/stop.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("buildStop", () => {
3333
return "end";
3434
});
3535
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
36+
defaultAuthHashStub = sandbox.stub();
3637
});
3738

3839
afterEach(() => {
@@ -60,6 +61,7 @@ describe("buildStop", () => {
6061
setCypressConfigFilename: setCypressConfigFilenameStub,
6162
getUserAgent: getUserAgentStub,
6263
getConfigPath: getConfigPathStub,
64+
defaultAuthHash: defaultAuthHashStub
6365
},
6466
request: {post: requestStub},
6567
});
@@ -97,6 +99,7 @@ describe("buildStop", () => {
9799
setCypressConfigFilename: setCypressConfigFilenameStub,
98100
getUserAgent: getUserAgentStub,
99101
getConfigPath: getConfigPathStub,
102+
defaultAuthHash: defaultAuthHashStub
100103
},
101104
request: {post: requestStub},
102105
});
@@ -129,6 +132,7 @@ describe("buildStop", () => {
129132
return "end";
130133
});
131134
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
135+
defaultAuthHashStub = sandbox.stub();
132136
});
133137

134138
afterEach(() => {
@@ -156,6 +160,7 @@ describe("buildStop", () => {
156160
setCypressConfigFilename: setCypressConfigFilenameStub,
157161
getUserAgent: getUserAgentStub,
158162
getConfigPath: getConfigPathStub,
163+
defaultAuthHash: defaultAuthHashStub
159164
},
160165
request: {post: requestStub},
161166
});
@@ -200,6 +205,7 @@ describe("buildStop", () => {
200205
setCypressConfigFilename: setCypressConfigFilenameStub,
201206
getUserAgent: getUserAgentStub,
202207
getConfigPath: getConfigPathStub,
208+
defaultAuthHash: defaultAuthHashStub
203209
},
204210
request: {post: requestStub},
205211
});
@@ -239,6 +245,7 @@ describe("buildStop", () => {
239245
setCypressConfigFilename: setCypressConfigFilenameStub,
240246
getUserAgent: getUserAgentStub,
241247
getConfigPath: getConfigPathStub,
248+
defaultAuthHash: defaultAuthHashStub
242249
},
243250
request: {post: requestStub},
244251
});
@@ -273,6 +280,7 @@ describe("buildStop", () => {
273280
return "end";
274281
});
275282
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
283+
defaultAuthHashStub = sandbox.stub();
276284
});
277285

278286
afterEach(() => {
@@ -300,6 +308,7 @@ describe("buildStop", () => {
300308
setCypressConfigFilename: setCypressConfigFilenameStub,
301309
getUserAgent: getUserAgentStub,
302310
getConfigPath: getConfigPathStub,
311+
defaultAuthHash: defaultAuthHashStub
303312
},
304313
request: {post: requestStub},
305314
});
@@ -333,6 +342,7 @@ describe("buildStop", () => {
333342
return "end";
334343
});
335344
getErrorCodeFromErrStub = sandbox.stub().returns("random-error");
345+
defaultAuthHashStub = sandbox.stub();
336346
});
337347

338348
afterEach(() => {
@@ -351,6 +361,7 @@ describe("buildStop", () => {
351361
setUsageReportingFlag: setUsageReportingFlagStub,
352362
setCypressConfigFilename: setCypressConfigFilenameStub,
353363
getConfigPath: getConfigPathStub,
364+
defaultAuthHash: defaultAuthHashStub
354365
},
355366
});
356367

0 commit comments

Comments
 (0)