@@ -9,6 +9,13 @@ import * as path from 'path';
9
9
10
10
let sampleFilePath : string = path . join ( __dirname , 'testoutput.txt' ) ;
11
11
12
+ const nodeVersionsWithCertificateErrors = [ 6 , 8 ] ;
13
+ let redirectProtocol = 'https' ;
14
+ if ( nodeVersionsWithCertificateErrors . find ( ( nodeVersion ) => process . version . startsWith ( `v${ nodeVersion } .` ) ) ) {
15
+ console . log ( 'Using protocol HTTP for redirect tests to avoid certificate errors on this node version' ) ;
16
+ redirectProtocol = 'http' ;
17
+ }
18
+
12
19
describe ( 'Http Tests' , function ( ) {
13
20
let _http : httpm . HttpClient ;
14
21
let _httpbin : httpm . HttpClient ;
@@ -179,30 +186,30 @@ describe('Http Tests', function () {
179
186
} ) ;
180
187
181
188
it ( 'does basic get request with redirects' , async ( ) => {
182
- let res : httpm . HttpClientResponse = await _http . get ( "https ://httpbingo.org/redirect-to?url=" + encodeURIComponent ( "https://httpbin.org/get" ) )
189
+ let res : httpm . HttpClientResponse = await _http . get ( ` ${ redirectProtocol } ://httpbingo.org/redirect-to?url=` + encodeURIComponent ( "https://httpbin.org/get" ) )
183
190
assert ( res . message . statusCode == 200 , "status code should be 200" ) ;
184
191
let body : string = await res . readBody ( ) ;
185
192
let obj :any = JSON . parse ( body ) ;
186
193
assert ( obj . url === "https://httpbin.org/get" ) ;
187
194
} ) ;
188
195
189
196
it ( 'does basic get request with redirects (303)' , async ( ) => {
190
- let res : httpm . HttpClientResponse = await _http . get ( "https ://httpbingo.org/redirect-to?url=" + encodeURIComponent ( "https://httpbin.org/get" ) + '&status_code=303' )
197
+ let res : httpm . HttpClientResponse = await _http . get ( ` ${ redirectProtocol } ://httpbingo.org/redirect-to?url=` + encodeURIComponent ( "https://httpbin.org/get" ) + '&status_code=303' )
191
198
assert ( res . message . statusCode == 200 , "status code should be 200" ) ;
192
199
let body : string = await res . readBody ( ) ;
193
200
let obj :any = JSON . parse ( body ) ;
194
201
assert ( obj . url === "https://httpbin.org/get" ) ;
195
202
} ) ;
196
203
197
204
it ( 'returns 404 for not found get request on redirect' , async ( ) => {
198
- let res : httpm . HttpClientResponse = await _http . get ( "https ://httpbingo.org/redirect-to?url=" + encodeURIComponent ( "https://httpbin.org/status/404" ) + '&status_code=303' )
205
+ let res : httpm . HttpClientResponse = await _http . get ( ` ${ redirectProtocol } ://httpbingo.org/redirect-to?url=` + encodeURIComponent ( "https://httpbin.org/status/404" ) + '&status_code=303' )
199
206
assert ( res . message . statusCode == 404 , "status code should be 404" ) ;
200
207
let body : string = await res . readBody ( ) ;
201
208
} ) ;
202
209
203
210
it ( 'does not follow redirects if disabled' , async ( ) => {
204
211
let http : httpm . HttpClient = new httpm . HttpClient ( 'typed-test-client-tests' , null , { allowRedirects : false } ) ;
205
- let res : httpm . HttpClientResponse = await http . get ( "https ://httpbingo.org/redirect-to?url=" + encodeURIComponent ( "https://httpbin.org/get" ) )
212
+ let res : httpm . HttpClientResponse = await http . get ( ` ${ redirectProtocol } ://httpbingo.org/redirect-to?url=` + encodeURIComponent ( "https://httpbin.org/get" ) )
206
213
assert ( res . message . statusCode == 302 , "status code should be 302" ) ;
207
214
let body : string = await res . readBody ( ) ;
208
215
} ) ;
0 commit comments