diff --git a/ext/node/polyfills/_tls_wrap.ts b/ext/node/polyfills/_tls_wrap.ts index 6697bc97ac..08275d4110 100644 --- a/ext/node/polyfills/_tls_wrap.ts +++ b/ext/node/polyfills/_tls_wrap.ts @@ -158,6 +158,7 @@ export class TLSSocket extends net.Socket { // onSocket handler of ClientRequest object. tlssock.emit("secure"); tlssock.removeListener("end", onConnectEnd); + return; } try { diff --git a/ext/node/polyfills/http.ts b/ext/node/polyfills/http.ts index ff85a61531..f92f9e5039 100644 --- a/ext/node/polyfills/http.ts +++ b/ext/node/polyfills/http.ts @@ -414,6 +414,11 @@ class ClientRequest extends OutgoingMessage { oncreate, ); if (newSocket) { + // If socket is created by createConnection option + // we apply sock-init-workaround + // This covers npm:ws and npm:mqtt + // https://github.com/denoland/deno/issues/27694 + newSocket._needsSockInitWorkaround = true; oncreate(null, newSocket); } } catch (err) { diff --git a/tests/registry/npm/bufferutil/bufferutil-4.0.9.tgz b/tests/registry/npm/bufferutil/bufferutil-4.0.9.tgz new file mode 100644 index 0000000000..d0be275984 Binary files /dev/null and b/tests/registry/npm/bufferutil/bufferutil-4.0.9.tgz differ diff --git a/tests/registry/npm/bufferutil/registry.json b/tests/registry/npm/bufferutil/registry.json new file mode 100644 index 0000000000..6b84d0435a --- /dev/null +++ b/tests/registry/npm/bufferutil/registry.json @@ -0,0 +1,73 @@ +{ + "name": "bufferutil", + "dist-tags": { + "latest": "4.0.9" + }, + "versions": { + "4.0.9": { + "name": "bufferutil", + "version": "4.0.9", + "description": "WebSocket buffer utils", + "main": "index.js", + "engines": { + "node": ">=6.14.2" + }, + "scripts": { + "install": "node-gyp-build", + "prebuild": "prebuildify --napi --strip --target=8.11.2", + "prebuild-darwin-x64+arm64": "prebuildify --arch x64+arm64 --napi --strip --target=8.11.2", + "test": "mocha" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/websockets/bufferutil.git" + }, + "author": { + "name": "Einar Otto Stangvik", + "email": "einaros@gmail.com", + "url": "http://2x.io" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/websockets/bufferutil/issues" + }, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "devDependencies": { + "mocha": "^11.0.1", + "node-gyp": "^11.0.0", + "prebuildify": "^6.0.0" + }, + "_id": "bufferutil@4.0.9", + "gitHead": "35e2eb6a14a8d58b87bc1f9ff2ddff67e2f1fa97", + "_nodeVersion": "23.5.0", + "_npmVersion": "10.9.2", + "dist": { + "integrity": "sha512-WDtdLmJvAuNNPzByAYpRo2rF1Mmradw6gvWsQKf63476DDXmomT9zUiGypLcG4ibIM67vhAj8jJRdbmEws2Aqw==", + "shasum": "6e81739ad48a95cad45a279588e13e95e24a800a", + "tarball": "http://localhost:4260/bufferutil/bufferutil-4.0.9.tgz", + "fileCount": 11, + "unpackedSize": 371859 + }, + "directories": {}, + "_hasShrinkwrap": false + } + }, + "bugs": { + "url": "https://github.com/websockets/bufferutil/issues" + }, + "author": { + "name": "Einar Otto Stangvik", + "email": "einaros@gmail.com", + "url": "http://2x.io" + }, + "license": "MIT", + "homepage": "https://github.com/websockets/bufferutil", + "repository": { + "type": "git", + "url": "git+https://github.com/websockets/bufferutil.git" + }, + "description": "WebSocket buffer utils", + "readmeFilename": "README.md" +} diff --git a/tests/registry/npm/utf-8-validate/registry.json b/tests/registry/npm/utf-8-validate/registry.json new file mode 100644 index 0000000000..43dc313781 --- /dev/null +++ b/tests/registry/npm/utf-8-validate/registry.json @@ -0,0 +1,75 @@ +{ + "name": "utf-8-validate", + "dist-tags": { + "latest": "6.0.5" + }, + "versions": { + "6.0.5": { + "name": "utf-8-validate", + "version": "6.0.5", + "description": "Check if a buffer contains valid UTF-8", + "main": "index.js", + "engines": { + "node": ">=6.14.2" + }, + "scripts": { + "install": "node-gyp-build", + "prebuild": "prebuildify --napi --strip --target=8.11.2", + "prebuild-linux-musl-x64": "prebuildify-cross --image alpine --napi --strip --target=8.11.2", + "prebuild-darwin-x64+arm64": "prebuildify --arch x64+arm64 --napi --strip --target=8.11.2", + "test": "mocha" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/websockets/utf-8-validate.git" + }, + "author": { + "name": "Einar Otto Stangvik", + "email": "einaros@gmail.com", + "url": "http://2x.io" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/websockets/utf-8-validate/issues" + }, + "dependencies": { + "node-gyp-build": "^4.3.0" + }, + "devDependencies": { + "mocha": "^10.0.0", + "node-gyp": "^10.0.1", + "prebuildify": "^6.0.0", + "prebuildify-cross": "^5.0.0" + }, + "_id": "utf-8-validate@6.0.5", + "gitHead": "4a9a05728641674620818c6a78b01fce38e6f222", + "_nodeVersion": "22.10.0", + "_npmVersion": "10.9.0", + "dist": { + "integrity": "sha512-EYZR+OpIXp9Y1eG1iueg8KRsY8TuT8VNgnanZ0uA3STqhHQTLwbl+WX76/9X5OY12yQubymBpaBSmMPkSTQcKA==", + "shasum": "8087d39902be2cc15bdb21a426697ff256d65aab", + "tarball": "http://localhost:4260/utf-8-validate/utf-8-validate-6.0.5.tgz", + "fileCount": 15, + "unpackedSize": 717511 + }, + "directories": {}, + "_hasShrinkwrap": false + } + }, + "bugs": { + "url": "https://github.com/websockets/utf-8-validate/issues" + }, + "author": { + "name": "Einar Otto Stangvik", + "email": "einaros@gmail.com", + "url": "http://2x.io" + }, + "license": "MIT", + "homepage": "https://github.com/websockets/utf-8-validate", + "repository": { + "type": "git", + "url": "git+https://github.com/websockets/utf-8-validate.git" + }, + "description": "Check if a buffer contains valid UTF-8", + "readmeFilename": "README.md" +} diff --git a/tests/registry/npm/utf-8-validate/utf-8-validate-6.0.5.tgz b/tests/registry/npm/utf-8-validate/utf-8-validate-6.0.5.tgz new file mode 100644 index 0000000000..132928121e Binary files /dev/null and b/tests/registry/npm/utf-8-validate/utf-8-validate-6.0.5.tgz differ diff --git a/tests/registry/npm/ws/registry.json b/tests/registry/npm/ws/registry.json new file mode 100644 index 0000000000..1738dc57dd --- /dev/null +++ b/tests/registry/npm/ws/registry.json @@ -0,0 +1,97 @@ +{ + "name": "ws", + "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", + "dist-tags": { + "latest": "8.18.0" + }, + "versions": { + "8.18.0": { + "name": "ws", + "version": "8.18.0", + "description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", + "bugs": { + "url": "https://github.com/websockets/ws/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/websockets/ws.git" + }, + "author": { + "name": "Einar Otto Stangvik", + "email": "einaros@gmail.com", + "url": "http://2x.io" + }, + "license": "MIT", + "main": "index.js", + "exports": { + ".": { + "browser": "./browser.js", + "import": "./wrapper.mjs", + "require": "./index.js" + }, + "./package.json": "./package.json" + }, + "browser": "browser.js", + "engines": { + "node": ">=10.0.0" + }, + "scripts": { + "test": "nyc --reporter=lcov --reporter=text mocha --throw-deprecation test/*.test.js", + "integration": "mocha --throw-deprecation test/*.integration.js", + "lint": "eslint . && prettier --check --ignore-path .gitignore \"**/*.{json,md,yaml,yml}\"" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + }, + "devDependencies": { + "benchmark": "^2.1.4", + "bufferutil": "^4.0.1", + "eslint": "^9.0.0", + "eslint-config-prettier": "^9.0.0", + "eslint-plugin-prettier": "^5.0.0", + "globals": "^15.0.0", + "mocha": "^8.4.0", + "nyc": "^15.0.0", + "prettier": "^3.0.0", + "utf-8-validate": "^6.0.0" + }, + "_id": "ws@8.18.0", + "gitHead": "976c53c4065c49ede73bfba824caf5a6e0f290cb", + "_nodeVersion": "22.4.0", + "_npmVersion": "10.8.1", + "dist": { + "integrity": "sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==", + "shasum": "0d7505a6eafe2b0e712d232b42279f53bc289bbc", + "tarball": "http://localhost:4260/ws/ws-8.18.0.tgz", + "fileCount": 19, + "unpackedSize": 146647 + }, + "directories": {}, + "_hasShrinkwrap": false + } + }, + "author": { + "name": "Einar Otto Stangvik", + "email": "einaros@gmail.com", + "url": "http://2x.io" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/websockets/ws.git" + }, + "license": "MIT", + "homepage": "https://github.com/websockets/ws", + "bugs": { + "url": "https://github.com/websockets/ws/issues" + }, + "readmeFilename": "README.md" +} diff --git a/tests/registry/npm/ws/ws-8.18.0.tgz b/tests/registry/npm/ws/ws-8.18.0.tgz new file mode 100644 index 0000000000..ee13c43bbd Binary files /dev/null and b/tests/registry/npm/ws/ws-8.18.0.tgz differ diff --git a/tests/specs/npm/ws_compat/__test__.jsonc b/tests/specs/npm/ws_compat/__test__.jsonc new file mode 100644 index 0000000000..33de572cbb --- /dev/null +++ b/tests/specs/npm/ws_compat/__test__.jsonc @@ -0,0 +1,4 @@ +{ + "args": "run -A --cert=../../../testdata/tls/RootCA.pem main.ts", + "output": "main.out" +} diff --git a/tests/specs/npm/ws_compat/main.out b/tests/specs/npm/ws_compat/main.out new file mode 100644 index 0000000000..28e5f860b3 --- /dev/null +++ b/tests/specs/npm/ws_compat/main.out @@ -0,0 +1,4 @@ +[WILDCARD] +open on server +open on client +message on server diff --git a/tests/specs/npm/ws_compat/main.ts b/tests/specs/npm/ws_compat/main.ts new file mode 100644 index 0000000000..1b44618537 --- /dev/null +++ b/tests/specs/npm/ws_compat/main.ts @@ -0,0 +1,24 @@ +import WebSocket from "npm:ws@8.18.0"; + +const key = Deno.readTextFileSync("../../../testdata/tls/localhost.key"); +const cert = Deno.readTextFileSync("../../../testdata/tls/localhost.crt"); + +Deno.serve({ key, cert, port: 0, onListen }, (req) => { + const { socket, response } = Deno.upgradeWebSocket(req); + socket.addEventListener("open", () => { + console.log("open on server"); + }); + socket.addEventListener("message", () => { + console.log("message on server"); + Deno.exit(0); + }); + return response; +}); + +function onListen({ port }) { + const socket = new WebSocket(`wss://localhost:${port}`); + socket.on("open", () => { + console.log("open on client"); + socket.send("hi"); + }); +}