Skip to content

Commit

Permalink
Fix broken azure pipeline (#316)
Browse files Browse the repository at this point in the history
* set vmImage to ubuntu-20.04

* skip certificate validation on node 8

* add node 6

* use HTTP instead of disabling certificate validation
  • Loading branch information
DaniilShmelev authored Mar 3, 2022
1 parent a6b0daf commit 9d20f74
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pool:
vmImage: ubuntu-20.04

parameters:
- name: versionSpec
type: object
Expand Down
15 changes: 11 additions & 4 deletions test/tests/httptests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import * as path from 'path';

let sampleFilePath: string = path.join(__dirname, 'testoutput.txt');

const nodeVersionsWithCertificateErrors = [6, 8];
let redirectProtocol = 'https';
if (nodeVersionsWithCertificateErrors.find((nodeVersion) => process.version.startsWith(`v${nodeVersion}.`))) {
console.log('Using protocol HTTP for redirect tests to avoid certificate errors on this node version');
redirectProtocol = 'http';
}

describe('Http Tests', function () {
let _http: httpm.HttpClient;
let _httpbin: httpm.HttpClient;
Expand Down Expand Up @@ -179,30 +186,30 @@ describe('Http Tests', function () {
});

it('does basic get request with redirects', async() => {
let res: httpm.HttpClientResponse = await _http.get("https://httpbingo.org/redirect-to?url=" + encodeURIComponent("https://httpbin.org/get"))
let res: httpm.HttpClientResponse = await _http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/get"))
assert(res.message.statusCode == 200, "status code should be 200");
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
assert(obj.url === "https://httpbin.org/get");
});

it('does basic get request with redirects (303)', async() => {
let res: httpm.HttpClientResponse = await _http.get("https://httpbingo.org/redirect-to?url=" + encodeURIComponent("https://httpbin.org/get") + '&status_code=303')
let res: httpm.HttpClientResponse = await _http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/get") + '&status_code=303')
assert(res.message.statusCode == 200, "status code should be 200");
let body: string = await res.readBody();
let obj:any = JSON.parse(body);
assert(obj.url === "https://httpbin.org/get");
});

it('returns 404 for not found get request on redirect', async() => {
let res: httpm.HttpClientResponse = await _http.get("https://httpbingo.org/redirect-to?url=" + encodeURIComponent("https://httpbin.org/status/404") + '&status_code=303')
let res: httpm.HttpClientResponse = await _http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/status/404") + '&status_code=303')
assert(res.message.statusCode == 404, "status code should be 404");
let body: string = await res.readBody();
});

it('does not follow redirects if disabled', async() => {
let http: httpm.HttpClient = new httpm.HttpClient('typed-test-client-tests', null, { allowRedirects: false });
let res: httpm.HttpClientResponse = await http.get("https://httpbingo.org/redirect-to?url=" + encodeURIComponent("https://httpbin.org/get"))
let res: httpm.HttpClientResponse = await http.get(`${redirectProtocol}://httpbingo.org/redirect-to?url=` + encodeURIComponent("https://httpbin.org/get"))
assert(res.message.statusCode == 302, "status code should be 302");
let body: string = await res.readBody();
});
Expand Down

0 comments on commit 9d20f74

Please sign in to comment.