Skip to content

Commit

Permalink
fix(tests): Get TLS version from Node instead of hardcoding it (#4700)
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s authored and aslushnikov committed Jul 15, 2019
1 parent bafda9f commit a39d553
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
16 changes: 12 additions & 4 deletions test/ignorehttpserrors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p

describe('Response.securityDetails', function() {
it('should work', async({page, httpsServer}) => {
const response = await page.goto(httpsServer.EMPTY_PAGE);
const [serverRequest, response] = await Promise.all([
httpsServer.waitForRequest('/empty.html'),
page.goto(httpsServer.EMPTY_PAGE)
]);
const securityDetails = response.securityDetails();
expect(securityDetails.issuer()).toBe('puppeteer-tests');
expect(securityDetails.protocol()).toBe('TLS 1.2');
const protocol = serverRequest.socket.getProtocol().replace('v', ' ');
expect(securityDetails.protocol()).toBe(protocol);
expect(securityDetails.subjectName()).toBe('puppeteer-tests');
expect(securityDetails.validFrom()).toBe(1550084863);
expect(securityDetails.validTo()).toBe(33086084863);
Expand All @@ -55,11 +59,15 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
httpsServer.setRedirect('/plzredirect', '/empty.html');
const responses = [];
page.on('response', response => responses.push(response));
await page.goto(httpsServer.PREFIX + '/plzredirect');
const [serverRequest, ] = await Promise.all([
httpsServer.waitForRequest('/plzredirect'),
page.goto(httpsServer.PREFIX + '/plzredirect')
]);
expect(responses.length).toBe(2);
expect(responses[0].status()).toBe(302);
const securityDetails = responses[0].securityDetails();
expect(securityDetails.protocol()).toBe('TLS 1.2');
const protocol = serverRequest.socket.getProtocol().replace('v', ' ');
expect(securityDetails.protocol()).toBe(protocol);
});
});

Expand Down
8 changes: 6 additions & 2 deletions test/launcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,15 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p
const browser = await puppeteer.connect({browserWSEndpoint, ignoreHTTPSErrors: true});
const page = await browser.newPage();
let error = null;
const response = await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);
const [serverRequest, response] = await Promise.all([
httpsServer.waitForRequest('/empty.html'),
page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e)
]);
expect(error).toBe(null);
expect(response.ok()).toBe(true);
expect(response.securityDetails()).toBeTruthy();
expect(response.securityDetails().protocol()).toBe('TLS 1.2');
const protocol = serverRequest.socket.getProtocol().replace('v', ' ');
expect(response.securityDetails().protocol()).toBe(protocol);
await page.close();
await browser.close();
});
Expand Down
1 change: 0 additions & 1 deletion utils/testserver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class TestServer {
const server = new TestServer(dirPath, port, {
key: fs.readFileSync(path.join(__dirname, 'key.pem')),
cert: fs.readFileSync(path.join(__dirname, 'cert.pem')),
secureProtocol: 'TLSv1_2_method',
passphrase: 'aaaa',
});
await new Promise(x => server._server.once('listening', x));
Expand Down

0 comments on commit a39d553

Please sign in to comment.