-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: increase coverage for http2.connect
Added checks for connecting using https and an unsupported protocol. PR-URL: #14832 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
- Loading branch information
1 parent
69440c9
commit 764b3c6
Showing
1 changed file
with
40 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,49 @@ | ||
// Flags: --expose-http2 | ||
'use strict'; | ||
|
||
const { mustCall, hasCrypto, skip } = require('../common'); | ||
const { mustCall, hasCrypto, skip, expectsError } = require('../common'); | ||
if (!hasCrypto) | ||
skip('missing crypto'); | ||
const { doesNotThrow } = require('assert'); | ||
const { doesNotThrow, throws } = require('assert'); | ||
const { createServer, connect } = require('http2'); | ||
{ | ||
const server = createServer(); | ||
server.listen(0, mustCall(() => { | ||
const authority = `http://localhost:${server.address().port}`; | ||
const options = {}; | ||
const listener = () => mustCall(); | ||
|
||
const server = createServer(); | ||
server.listen(0, mustCall(() => { | ||
const authority = `http://localhost:${server.address().port}`; | ||
const options = {}; | ||
const listener = () => mustCall(); | ||
const clients = new Set(); | ||
doesNotThrow(() => clients.add(connect(authority))); | ||
doesNotThrow(() => clients.add(connect(authority, options))); | ||
doesNotThrow(() => clients.add(connect(authority, options, listener()))); | ||
doesNotThrow(() => clients.add(connect(authority, listener()))); | ||
|
||
const clients = new Set(); | ||
doesNotThrow(() => clients.add(connect(authority))); | ||
doesNotThrow(() => clients.add(connect(authority, options))); | ||
doesNotThrow(() => clients.add(connect(authority, options, listener()))); | ||
doesNotThrow(() => clients.add(connect(authority, listener()))); | ||
for (const client of clients) { | ||
client.once('connect', mustCall((headers) => { | ||
client.destroy(); | ||
clients.delete(client); | ||
if (clients.size === 0) { | ||
server.close(); | ||
} | ||
})); | ||
} | ||
})); | ||
} | ||
|
||
for (const client of clients) { | ||
client.once('connect', mustCall((headers) => { | ||
client.destroy(); | ||
clients.delete(client); | ||
if (clients.size === 0) { | ||
server.close(); | ||
} | ||
})); | ||
} | ||
})); | ||
// check for https as protocol | ||
{ | ||
const authority = 'https://localhost'; | ||
doesNotThrow(() => connect(authority)); | ||
} | ||
|
||
// check for error for an invalid protocol (not http or https) | ||
{ | ||
const authority = 'ssh://localhost'; | ||
throws(() => { | ||
connect(authority); | ||
}, expectsError({ | ||
code: 'ERR_HTTP2_UNSUPPORTED_PROTOCOL', | ||
type: Error | ||
})); | ||
} |