Skip to content

Commit 40520e1

Browse files
Merge pull request #164 from LambdaTest/dev
2.5.2
2 parents e5f19d8 + 62250b6 commit 40520e1

15 files changed

+310
-137
lines changed

commands/build_info.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,36 @@ function get_build_info(args) {
3535
env = args["env"];
3636
} else {
3737
console.log(
38-
"Environment can be stage, beta or prod, setting Env to prod"
38+
"Environment can be stage,stage_new, beta or prod, setting Env to prod"
3939
);
4040
}
4141
}
42-
43-
request(
44-
constants[env].BUILD_BASE_URL + args.buildId,
45-
{
46-
auth: {
47-
username: username,
48-
password: access_key,
49-
},
42+
let options = {
43+
url: constants[env].BUILD_BASE_URL + args.buildId,
44+
auth: {
45+
username: username,
46+
password: access_key,
5047
},
51-
(err, res, body) => {
52-
if (err) {
53-
reject(err);
48+
};
49+
if ("reject_unauthorized" in args) {
50+
if (
51+
args["reject_unauthorized"] != "false" &&
52+
args["reject_unauthorized"] != "true"
53+
) {
54+
console.log("reject_unauthorized has to boolean");
55+
return;
56+
} else {
57+
if (args["reject_unauthorized"] == "false") {
58+
options["rejectUnauthorized"] = false;
59+
console.log("Setting rejectUnauthorized to false for web requests");
5460
}
61+
}
62+
}
63+
64+
request.get(options, (err, res, body) => {
65+
if (err) {
66+
reject(err);
67+
} else {
5568
if (res.statusCode == "401") {
5669
resolve("Unauthorized");
5770
} else if (JSON.parse(body).status == "success") {
@@ -60,7 +73,7 @@ function get_build_info(args) {
6073
resolve(JSON.parse(body).message);
6174
}
6275
}
63-
);
76+
});
6477
});
6578
}
6679

commands/build_stop.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function stop_session(args) {
6060
env = args["env"];
6161
} else {
6262
console.log(
63-
"Environment can be stage, beta or prod, setting Env to prod"
63+
"Environment can be stage,stage_new, beta or prod, setting Env to prod"
6464
);
6565
}
6666
}
@@ -72,6 +72,21 @@ function stop_session(args) {
7272
Username: username,
7373
},
7474
};
75+
76+
if ("reject_unauthorized" in args) {
77+
if (
78+
args["reject_unauthorized"] != "false" &&
79+
args["reject_unauthorized"] != "true"
80+
) {
81+
console.log("reject_unauthorized has to boolean");
82+
return;
83+
} else {
84+
if (args["reject_unauthorized"] == "false") {
85+
options["rejectUnauthorized"] = false;
86+
console.log("Setting rejectUnauthorized to false for web requests");
87+
}
88+
}
89+
}
7590
request.put(options, function (err, resp, body) {
7691
if (err) {
7792
reject(err);

commands/generate_reports.js

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ var fs = require("fs");
77
const StreamZip = require("node-stream-zip");
88
const path = require("path");
99

10-
function download_artefact(username, access_key, env, test_id, file_path) {
10+
function download_artefact(
11+
username,
12+
access_key,
13+
env,
14+
test_id,
15+
file_path,
16+
rejectUnauthorized
17+
) {
1118
return new Promise(function (resolve, reject) {
1219
let response_code;
1320
if (!fs.existsSync(file_path)) {
@@ -18,23 +25,26 @@ function download_artefact(username, access_key, env, test_id, file_path) {
1825
file_path = path.join(file_path, "artefacts.zip");
1926
const stream = fs.createWriteStream(file_path);
2027
stream.end();
21-
request(
22-
constants[env].REPORT_URL + test_id,
23-
{
24-
auth: {
25-
username: username,
26-
password: access_key,
27-
},
28-
gzip: true,
29-
timeout: 120000,
28+
let options = {
29+
url: constants[env].REPORT_URL + test_id,
30+
auth: {
31+
username: username,
32+
password: access_key,
3033
},
31-
(err, res, body) => {
32-
if (err) {
33-
reject(err);
34-
}
35-
response_code = res.statusCode;
34+
gzip: true,
35+
timeout: 120000,
36+
};
37+
if (rejectUnauthorized == false) {
38+
options["rejectUnauthorized"] = false;
39+
console.log("Setting rejectUnauthorized to false for web requests");
40+
}
41+
42+
request(options, (err, res, body) => {
43+
if (err) {
44+
reject(err);
3645
}
37-
).pipe(
46+
response_code = res.statusCode;
47+
}).pipe(
3848
fs
3949
.createWriteStream(file_path, {
4050
overwrite: true,
@@ -121,7 +131,7 @@ function generate_report(args) {
121131
env = args["env"];
122132
} else {
123133
console.log(
124-
"Environment can be stage, beta or prod, setting Env to prod"
134+
"Environment can be stage,stage_new, beta or prod, setting Env to prod"
125135
);
126136
}
127137
}
@@ -132,8 +142,25 @@ function generate_report(args) {
132142
username: username,
133143
access_key: access_key,
134144
},
145+
run_settings: {
146+
reject_unauthorized: true,
147+
},
135148
};
136149

150+
if ("reject_unauthorized" in args) {
151+
if (
152+
args["reject_unauthorized"] != "false" &&
153+
args["reject_unauthorized"] != "true"
154+
) {
155+
console.log("reject_unauthorized has to boolean");
156+
return;
157+
} else {
158+
if (args["reject_unauthorized"] == "false") {
159+
build_payload["run_settings"]["reject_unauthorized"] = false;
160+
console.log("Setting rejectUnauthorized to false for web requests");
161+
}
162+
}
163+
}
137164
build_stats
138165
.get_completed_build_info(build_payload, args["session_id"], env)
139166
.then(function (build_info) {
@@ -166,7 +193,8 @@ function generate_report(args) {
166193
build_info["data"][i]["browser"],
167194
build_info["data"][i]["version"],
168195
build_info["data"][i]["test_id"]
169-
)
196+
),
197+
build_payload["run_settings"]["reject_unauthorized"]
170198
)
171199
.then(function (resp) {
172200
//Files downloaded

commands/run.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,30 @@ module.exports = function (args) {
2424
env = args["env"];
2525
} else {
2626
console.log(
27-
"Environment can be stage, beta, preprod or prod, setting Env to prod"
27+
"Environment can be stage,stage_new, beta, preprod or prod, setting Env to prod"
2828
);
29+
return;
30+
}
31+
}
32+
let rejectUnauthorized = true;
33+
if ("reject_unauthorized" in args) {
34+
if (
35+
args["reject_unauthorized"] != "false" &&
36+
args["reject_unauthorized"] != "true"
37+
) {
38+
console.log("reject_unauthorized has to boolean");
39+
return;
40+
} else {
41+
if (args["reject_unauthorized"] == "false") {
42+
rejectUnauthorized = false;
43+
console.log("Setting rejectUnauthorized to false for web requests");
44+
} else {
45+
rejectUnauthorized = true;
46+
}
2947
}
3048
}
3149
validate_cli
32-
.validate_cli(env)
50+
.validate_cli(env, rejectUnauthorized)
3351
.then(function (resp) {
3452
let cli_flag = false;
3553
for (let i = 0; i < resp["value"].length; i++) {

commands/utils/batch/batch_runner.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ const builds = require("../poller/build");
1616
var batchCounter = 0;
1717
var totalBatches = 0;
1818

19-
function run_test(payload, env = "prod") {
19+
function run_test(payload, env = "prod", rejectUnauthorized) {
2020
return new Promise(function (resolve, reject) {
2121
let options = {
2222
url: constants[env].INTEGRATION_BASE_URL + constants.RUN_URL,
2323
body: payload,
2424
};
25-
25+
if (rejectUnauthorized == false) {
26+
options["rejectUnauthorized"] = false;
27+
}
2628
let responseData = null;
2729
request.post(options, function (err, resp, body) {
2830
if (err) {
@@ -111,7 +113,12 @@ async function run(lt_config, batches, env, i = 0) {
111113
access_key: lt_config["lambdatest_auth"]["access_key"],
112114
type: "cypress",
113115
});
114-
run_test(payload, env)
116+
117+
run_test(
118+
payload,
119+
env,
120+
lt_config.run_settings.reject_unauthorized
121+
)
115122
.then(function (session_id) {
116123
delete_archive(project_file);
117124
delete_archive(file_obj["name"]);

commands/utils/constants.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
"&status=running,queued,created,initiated,pqueued,error,lambda error,failed",
1414
BUILD_ERROR_STATES: "&status=error,lambda error,failed",
1515
CYPRESS_ENV_FILE_PATH: "cypress.env.json",
16-
ENVS: ["stage", "beta", "prod", "preprod"],
16+
ENVS: ["stage", "beta", "prod", "preprod", "stage_new"],
1717
prod: {
1818
INTEGRATION_BASE_URL: "https://api.lambdatest.com/liis",
1919
BUILD_BASE_URL: "https://api.lambdatest.com/automation/api/v1/builds/",
@@ -45,6 +45,28 @@ module.exports = {
4545
REPORT_URL:
4646
"https://stage-api.lambdatest.com/automation/api/v1/cypress/artefacts/test/",
4747
},
48+
stage_new: {
49+
INTEGRATION_BASE_URL: "https://api.lambdatestinternal.com/liis",
50+
BUILD_BASE_URL:
51+
"https://api.lambdatestinternal.com/automation/api/v1/builds/",
52+
BUILD_STOP_URL:
53+
"https://api.lambdatestinternal.com/api/v1/test/stop?sessionId=",
54+
SESSION_URL:
55+
"https://api.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
56+
REPORT_URL:
57+
"https://api.lambdatestinternal.com/automation/api/v1/cypress/artefacts/test/",
58+
},
59+
stage_new1: {
60+
INTEGRATION_BASE_URL: "https://prestage-api.lambdatest.com/liis",
61+
BUILD_BASE_URL:
62+
"https://prestage-api.lambdatest.com/automation/api/v1/builds/",
63+
BUILD_STOP_URL:
64+
"https://prestage-api.lambdatest.com/api/v1/test/stop?sessionId=",
65+
SESSION_URL:
66+
"https://prestage-api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
67+
REPORT_URL:
68+
"https://prestage-api.lambdatest.com/automation/api/v1/cypress/artefacts/test/",
69+
},
4870
preprod: {
4971
INTEGRATION_BASE_URL: "https://preprod-api.lambdatest.com/liis",
5072
BUILD_BASE_URL:

commands/utils/poller/build.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,34 @@ const request = require("request");
33
//https://api.cypress-v3.dev.lambdatest.io/api/v1/test/stop/?sessionId=4a7434b9-1905-4aaf-a178-9167acb00c5d
44
function stop_cypress_session(lt_config, session_id, env) {
55
return new Promise(function (resolve, reject) {
6-
request(
7-
constants[env].BUILD_STOP_URL + session_id,
8-
{
9-
auth: {
10-
username: lt_config["lambdatest_auth"]["username"],
11-
password: lt_config["lambdatest_auth"]["access_key"],
12-
},
13-
method: "PUT",
6+
let options = {
7+
url: constants[env].BUILD_STOP_URL + session_id,
8+
headers: {
9+
Authorization: "Token " + lt_config["lambdatest_auth"]["access_key"],
10+
Username: lt_config["lambdatest_auth"]["username"],
1411
},
15-
(err, res, body) => {
16-
if (err) {
17-
console.log("Error occured while stopping session", err);
18-
reject(err);
19-
}
20-
if (res.statusCode == "401") {
21-
console.log("Error Occured: Unauthorized access to session-stop");
22-
reject("Unauthorized");
23-
} else if (res.statusCode == "200") {
24-
console.log("Session stopped successfully");
25-
resolve(JSON.parse(body));
26-
} else {
27-
console.log(body);
28-
reject("No response for session stop");
29-
}
12+
method: "PUT",
13+
};
14+
if (lt_config.run_settings.reject_unauthorized == false) {
15+
options["rejectUnauthorized"] = false;
16+
}
17+
18+
request.put(options, (err, res, body) => {
19+
if (err) {
20+
console.log("Error occured while stopping session", err);
21+
reject(err);
22+
}
23+
if (res.statusCode == "401") {
24+
console.log("Error Occured: Unauthorized access to session-stop");
25+
reject("Unauthorized");
26+
} else if (res.statusCode == "200") {
27+
console.log("Session stopped successfully");
28+
resolve(JSON.parse(body));
29+
} else {
30+
console.log(body);
31+
reject("No response for session stop");
3032
}
31-
);
33+
});
3234
});
3335
}
3436

0 commit comments

Comments
 (0)