@@ -7,7 +7,14 @@ var fs = require("fs");
77const StreamZip = require ( "node-stream-zip" ) ;
88const 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 ,
@@ -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
0 commit comments