Skip to content

2.5.2 #164

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 13 commits into from
Jun 28, 2022
Merged

2.5.2 #164

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
39 changes: 26 additions & 13 deletions commands/build_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,36 @@ function get_build_info(args) {
env = args["env"];
} else {
console.log(
"Environment can be stage, beta or prod, setting Env to prod"
"Environment can be stage,stage_new, beta or prod, setting Env to prod"
);
}
}

request(
constants[env].BUILD_BASE_URL + args.buildId,
{
auth: {
username: username,
password: access_key,
},
let options = {
url: constants[env].BUILD_BASE_URL + args.buildId,
auth: {
username: username,
password: access_key,
},
(err, res, body) => {
if (err) {
reject(err);
};
if ("reject_unauthorized" in args) {
if (
args["reject_unauthorized"] != "false" &&
args["reject_unauthorized"] != "true"
) {
console.log("reject_unauthorized has to boolean");
return;
} else {
if (args["reject_unauthorized"] == "false") {
options["rejectUnauthorized"] = false;
console.log("Setting rejectUnauthorized to false for web requests");
}
}
}

request.get(options, (err, res, body) => {
if (err) {
reject(err);
} else {
if (res.statusCode == "401") {
resolve("Unauthorized");
} else if (JSON.parse(body).status == "success") {
Expand All @@ -60,7 +73,7 @@ function get_build_info(args) {
resolve(JSON.parse(body).message);
}
}
);
});
});
}

Expand Down
17 changes: 16 additions & 1 deletion commands/build_stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function stop_session(args) {
env = args["env"];
} else {
console.log(
"Environment can be stage, beta or prod, setting Env to prod"
"Environment can be stage,stage_new, beta or prod, setting Env to prod"
);
}
}
Expand All @@ -72,6 +72,21 @@ function stop_session(args) {
Username: username,
},
};

if ("reject_unauthorized" in args) {
if (
args["reject_unauthorized"] != "false" &&
args["reject_unauthorized"] != "true"
) {
console.log("reject_unauthorized has to boolean");
return;
} else {
if (args["reject_unauthorized"] == "false") {
options["rejectUnauthorized"] = false;
console.log("Setting rejectUnauthorized to false for web requests");
}
}
}
request.put(options, function (err, resp, body) {
if (err) {
reject(err);
Expand Down
64 changes: 46 additions & 18 deletions commands/generate_reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ var fs = require("fs");
const StreamZip = require("node-stream-zip");
const path = require("path");

function download_artefact(username, access_key, env, test_id, file_path) {
function download_artefact(
username,
access_key,
env,
test_id,
file_path,
rejectUnauthorized
) {
return new Promise(function (resolve, reject) {
let response_code;
if (!fs.existsSync(file_path)) {
Expand All @@ -18,23 +25,26 @@ function download_artefact(username, access_key, env, test_id, file_path) {
file_path = path.join(file_path, "artefacts.zip");
const stream = fs.createWriteStream(file_path);
stream.end();
request(
constants[env].REPORT_URL + test_id,
{
auth: {
username: username,
password: access_key,
},
gzip: true,
timeout: 120000,
let options = {
url: constants[env].REPORT_URL + test_id,
auth: {
username: username,
password: access_key,
},
(err, res, body) => {
if (err) {
reject(err);
}
response_code = res.statusCode;
gzip: true,
timeout: 120000,
};
if (rejectUnauthorized == false) {
options["rejectUnauthorized"] = false;
console.log("Setting rejectUnauthorized to false for web requests");
}

request(options, (err, res, body) => {
if (err) {
reject(err);
}
).pipe(
response_code = res.statusCode;
}).pipe(
fs
.createWriteStream(file_path, {
overwrite: true,
Expand Down Expand Up @@ -121,7 +131,7 @@ function generate_report(args) {
env = args["env"];
} else {
console.log(
"Environment can be stage, beta or prod, setting Env to prod"
"Environment can be stage,stage_new, beta or prod, setting Env to prod"
);
}
}
Expand All @@ -132,8 +142,25 @@ function generate_report(args) {
username: username,
access_key: access_key,
},
run_settings: {
reject_unauthorized: true,
},
};

if ("reject_unauthorized" in args) {
if (
args["reject_unauthorized"] != "false" &&
args["reject_unauthorized"] != "true"
) {
console.log("reject_unauthorized has to boolean");
return;
} else {
if (args["reject_unauthorized"] == "false") {
build_payload["run_settings"]["reject_unauthorized"] = false;
console.log("Setting rejectUnauthorized to false for web requests");
}
}
}
build_stats
.get_completed_build_info(build_payload, args["session_id"], env)
.then(function (build_info) {
Expand Down Expand Up @@ -166,7 +193,8 @@ function generate_report(args) {
build_info["data"][i]["browser"],
build_info["data"][i]["version"],
build_info["data"][i]["test_id"]
)
),
build_payload["run_settings"]["reject_unauthorized"]
)
.then(function (resp) {
//Files downloaded
Expand Down
22 changes: 20 additions & 2 deletions commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,30 @@ module.exports = function (args) {
env = args["env"];
} else {
console.log(
"Environment can be stage, beta, preprod or prod, setting Env to prod"
"Environment can be stage,stage_new, beta, preprod or prod, setting Env to prod"
);
return;
}
}
let rejectUnauthorized = true;
if ("reject_unauthorized" in args) {
if (
args["reject_unauthorized"] != "false" &&
args["reject_unauthorized"] != "true"
) {
console.log("reject_unauthorized has to boolean");
return;
} else {
if (args["reject_unauthorized"] == "false") {
rejectUnauthorized = false;
console.log("Setting rejectUnauthorized to false for web requests");
} else {
rejectUnauthorized = true;
}
}
}
validate_cli
.validate_cli(env)
.validate_cli(env, rejectUnauthorized)
.then(function (resp) {
let cli_flag = false;
for (let i = 0; i < resp["value"].length; i++) {
Expand Down
13 changes: 10 additions & 3 deletions commands/utils/batch/batch_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ const builds = require("../poller/build");
var batchCounter = 0;
var totalBatches = 0;

function run_test(payload, env = "prod") {
function run_test(payload, env = "prod", rejectUnauthorized) {
return new Promise(function (resolve, reject) {
let options = {
url: constants[env].INTEGRATION_BASE_URL + constants.RUN_URL,
body: payload,
};

if (rejectUnauthorized == false) {
options["rejectUnauthorized"] = false;
}
let responseData = null;
request.post(options, function (err, resp, body) {
if (err) {
Expand Down Expand Up @@ -111,7 +113,12 @@ async function run(lt_config, batches, env, i = 0) {
access_key: lt_config["lambdatest_auth"]["access_key"],
type: "cypress",
});
run_test(payload, env)

run_test(
payload,
env,
lt_config.run_settings.reject_unauthorized
)
.then(function (session_id) {
delete_archive(project_file);
delete_archive(file_obj["name"]);
Expand Down
24 changes: 23 additions & 1 deletion commands/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
"&status=running,queued,created,initiated,pqueued,error,lambda error,failed",
BUILD_ERROR_STATES: "&status=error,lambda error,failed",
CYPRESS_ENV_FILE_PATH: "cypress.env.json",
ENVS: ["stage", "beta", "prod", "preprod"],
ENVS: ["stage", "beta", "prod", "preprod", "stage_new"],
prod: {
INTEGRATION_BASE_URL: "https://api.lambdatest.com/liis",
BUILD_BASE_URL: "https://api.lambdatest.com/automation/api/v1/builds/",
Expand Down Expand Up @@ -45,6 +45,28 @@ module.exports = {
REPORT_URL:
"https://stage-api.lambdatest.com/automation/api/v1/cypress/artefacts/test/",
},
stage_new: {
INTEGRATION_BASE_URL: "https://api.lambdatestinternal.com/liis",
BUILD_BASE_URL:
"https://api.lambdatestinternal.com/automation/api/v1/builds/",
BUILD_STOP_URL:
"https://api.lambdatestinternal.com/api/v1/test/stop?sessionId=",
SESSION_URL:
"https://api.lambdatestinternal.com/automation/api/v1/sessions?limit=200&session_id=",
REPORT_URL:
"https://api.lambdatestinternal.com/automation/api/v1/cypress/artefacts/test/",
},
stage_new1: {
INTEGRATION_BASE_URL: "https://prestage-api.lambdatest.com/liis",
BUILD_BASE_URL:
"https://prestage-api.lambdatest.com/automation/api/v1/builds/",
BUILD_STOP_URL:
"https://prestage-api.lambdatest.com/api/v1/test/stop?sessionId=",
SESSION_URL:
"https://prestage-api.lambdatest.com/automation/api/v1/sessions?limit=200&session_id=",
REPORT_URL:
"https://prestage-api.lambdatest.com/automation/api/v1/cypress/artefacts/test/",
},
preprod: {
INTEGRATION_BASE_URL: "https://preprod-api.lambdatest.com/liis",
BUILD_BASE_URL:
Expand Down
50 changes: 26 additions & 24 deletions commands/utils/poller/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@ const request = require("request");
//https://api.cypress-v3.dev.lambdatest.io/api/v1/test/stop/?sessionId=4a7434b9-1905-4aaf-a178-9167acb00c5d
function stop_cypress_session(lt_config, session_id, env) {
return new Promise(function (resolve, reject) {
request(
constants[env].BUILD_STOP_URL + session_id,
{
auth: {
username: lt_config["lambdatest_auth"]["username"],
password: lt_config["lambdatest_auth"]["access_key"],
},
method: "PUT",
let options = {
url: constants[env].BUILD_STOP_URL + session_id,
headers: {
Authorization: "Token " + lt_config["lambdatest_auth"]["access_key"],
Username: lt_config["lambdatest_auth"]["username"],
},
(err, res, body) => {
if (err) {
console.log("Error occured while stopping session", err);
reject(err);
}
if (res.statusCode == "401") {
console.log("Error Occured: Unauthorized access to session-stop");
reject("Unauthorized");
} else if (res.statusCode == "200") {
console.log("Session stopped successfully");
resolve(JSON.parse(body));
} else {
console.log(body);
reject("No response for session stop");
}
method: "PUT",
};
if (lt_config.run_settings.reject_unauthorized == false) {
options["rejectUnauthorized"] = false;
}

request.put(options, (err, res, body) => {
if (err) {
console.log("Error occured while stopping session", err);
reject(err);
}
if (res.statusCode == "401") {
console.log("Error Occured: Unauthorized access to session-stop");
reject("Unauthorized");
} else if (res.statusCode == "200") {
console.log("Session stopped successfully");
resolve(JSON.parse(body));
} else {
console.log(body);
reject("No response for session stop");
}
);
});
});
}

Expand Down
Loading