summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Marczak <sz.marczak@gmail.com>2018-09-02 12:07:20 +0200
committerMatteo Collina <hello@matteocollina.com>2018-09-05 12:58:40 +0200
commitd6a43438d6ed3f262cc87fe2ebd0c46a87c1ff57 (patch)
tree40287494a163f4b0c765c05f2b02244a681af179
parent441391b9ebb1dda7721c1b0ce6b700b45c598b2b (diff)
downloadandroid-node-v8-d6a43438d6ed3f262cc87fe2ebd0c46a87c1ff57.tar.gz
android-node-v8-d6a43438d6ed3f262cc87fe2ebd0c46a87c1ff57.tar.bz2
android-node-v8-d6a43438d6ed3f262cc87fe2ebd0c46a87c1ff57.zip
http2: don't expose the original socket through the socket proxy
Refs: https://github.com/nodejs/node/pull/22486 PR-URL: https://github.com/nodejs/node/pull/22650 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--lib/internal/http2/core.js14
-rw-r--r--test/parallel/test-http2-socket-proxy.js11
-rw-r--r--test/parallel/test-http2-unbound-socket-proxy.js25
3 files changed, 23 insertions, 27 deletions
diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js
index ad4f98593d..f2a298b6e5 100644
--- a/lib/internal/http2/core.js
+++ b/lib/internal/http2/core.js
@@ -646,7 +646,9 @@ const proxySocketHandler = {
get(session, prop) {
switch (prop) {
case 'setTimeout':
- return session.setTimeout.bind(session);
+ case 'ref':
+ case 'unref':
+ return session[prop].bind(session);
case 'destroy':
case 'emit':
case 'end':
@@ -654,6 +656,9 @@ const proxySocketHandler = {
case 'read':
case 'resume':
case 'write':
+ case 'setEncoding':
+ case 'setKeepAlive':
+ case 'setNoDelay':
throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
default:
const socket = session[kSocket];
@@ -672,7 +677,9 @@ const proxySocketHandler = {
set(session, prop, value) {
switch (prop) {
case 'setTimeout':
- session.setTimeout = value;
+ case 'ref':
+ case 'unref':
+ session[prop] = value;
return true;
case 'destroy':
case 'emit':
@@ -681,6 +688,9 @@ const proxySocketHandler = {
case 'read':
case 'resume':
case 'write':
+ case 'setEncoding':
+ case 'setKeepAlive':
+ case 'setNoDelay':
throw new ERR_HTTP2_NO_SOCKET_MANIPULATION();
default:
const socket = session[kSocket];
diff --git a/test/parallel/test-http2-socket-proxy.js b/test/parallel/test-http2-socket-proxy.js
index f7d97a3bb1..64daeb62ba 100644
--- a/test/parallel/test-http2-socket-proxy.js
+++ b/test/parallel/test-http2-socket-proxy.js
@@ -42,6 +42,9 @@ server.on('stream', common.mustCall(function(stream, headers) {
common.expectsError(() => socket.read, errMsg);
common.expectsError(() => socket.resume, errMsg);
common.expectsError(() => socket.write, errMsg);
+ common.expectsError(() => socket.setEncoding, errMsg);
+ common.expectsError(() => socket.setKeepAlive, errMsg);
+ common.expectsError(() => socket.setNoDelay, errMsg);
common.expectsError(() => (socket.destroy = undefined), errMsg);
common.expectsError(() => (socket.emit = undefined), errMsg);
@@ -50,11 +53,19 @@ server.on('stream', common.mustCall(function(stream, headers) {
common.expectsError(() => (socket.read = undefined), errMsg);
common.expectsError(() => (socket.resume = undefined), errMsg);
common.expectsError(() => (socket.write = undefined), errMsg);
+ common.expectsError(() => (socket.setEncoding = undefined), errMsg);
+ common.expectsError(() => (socket.setKeepAlive = undefined), errMsg);
+ common.expectsError(() => (socket.setNoDelay = undefined), errMsg);
// Resetting the socket listeners to their own value should not throw.
socket.on = socket.on; // eslint-disable-line no-self-assign
socket.once = socket.once; // eslint-disable-line no-self-assign
+ socket.unref();
+ assert.strictEqual(socket._handle.hasRef(), false);
+ socket.ref();
+ assert.strictEqual(socket._handle.hasRef(), true);
+
stream.respond();
socket.writable = 0;
diff --git a/test/parallel/test-http2-unbound-socket-proxy.js b/test/parallel/test-http2-unbound-socket-proxy.js
index 44f113bac9..18881574f2 100644
--- a/test/parallel/test-http2-unbound-socket-proxy.js
+++ b/test/parallel/test-http2-unbound-socket-proxy.js
@@ -39,31 +39,6 @@ server.listen(0, common.mustCall(() => {
}, {
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'
- });
}));
}));
}));