-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: throw better error when accessing unbound socket proxy
Fixes: #22268 Backport-PR-URL: #22850 PR-URL: #22486 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
1 parent
d0be932
commit 6a396ff
Showing
4 changed files
with
87 additions
and
2 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
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
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
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const http2 = require('http2'); | ||
const net = require('net'); | ||
|
||
const server = http2.createServer(); | ||
server.on('stream', common.mustCall((stream) => { | ||
stream.respond(); | ||
stream.end('ok'); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const socket = client.socket; | ||
const req = client.request(); | ||
req.resume(); | ||
req.on('close', common.mustCall(() => { | ||
client.close(); | ||
server.close(); | ||
|
||
// Tests to make sure accessing the socket proxy fails with an | ||
// informative error. | ||
setImmediate(common.mustCall(() => { | ||
common.expectsError(() => { | ||
socket.example; | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
common.expectsError(() => { | ||
socket.example = 1; | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
common.expectsError(() => { | ||
socket instanceof net.Socket; | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
common.expectsError(() => { | ||
socket.ref(); | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
common.expectsError(() => { | ||
socket.unref(); | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
common.expectsError(() => { | ||
socket.setEncoding(); | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
common.expectsError(() => { | ||
socket.setKeepAlive(); | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
common.expectsError(() => { | ||
socket.setNoDelay(); | ||
}, { | ||
code: 'ERR_HTTP2_SOCKET_UNBOUND' | ||
}); | ||
})); | ||
})); | ||
})); |