From 8c053e00e289f214105fc3919b206ac160e81a2d Mon Sep 17 00:00:00 2001 From: Bob Evans Date: Thu, 3 Aug 2023 14:54:23 -0400 Subject: [PATCH] chore: Fix smoke tests node 20 (#1745) Co-authored-by: Maurice Rickard --- THIRD_PARTY_NOTICES.md | 36 +-- lib/collector/http-agents.js | 53 +--- package-lock.json | 322 ++++++++++++++++---- package.json | 4 +- test/lib/agent_helper.js | 11 + test/smoke/proxy-api-connection-port.tap.js | 10 +- test/smoke/proxy-api-connection-ssl.tap.js | 10 +- test/unit/collector/http-agents.test.js | 52 ++-- third_party_manifest.json | 40 +-- 9 files changed, 365 insertions(+), 173 deletions(-) diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 721bed5b15..a2a2334ae1 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -34,7 +34,6 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic * [@newrelic/eslint-config](#newreliceslint-config) * [@newrelic/newrelic-oss-cli](#newrelicnewrelic-oss-cli) -* [@newrelic/proxy](#newrelicproxy) * [@newrelic/test-utilities](#newrelictest-utilities) * [@octokit/rest](#octokitrest) * [@slack/bolt](#slackbolt) @@ -66,6 +65,7 @@ code, the source code can be found at [https://github.com/newrelic/node-newrelic * [memcached](#memcached) * [nock](#nock) * [prettier](#prettier) +* [proxy](#proxy) * [proxyquire](#proxyquire) * [q](#q) * [rimraf](#rimraf) @@ -1273,7 +1273,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ### https-proxy-agent -This product includes source derived from [https-proxy-agent](https://github.com/TooTallNate/node-https-proxy-agent) ([v5.0.1](https://github.com/TooTallNate/node-https-proxy-agent/tree/v5.0.1)), distributed under the [MIT License](https://github.com/TooTallNate/node-https-proxy-agent/blob/v5.0.1/README.md): +This product includes source derived from [https-proxy-agent](https://github.com/TooTallNate/proxy-agents) ([v7.0.1](https://github.com/TooTallNate/proxy-agents/tree/v7.0.1)), distributed under the [MIT License](https://github.com/TooTallNate/proxy-agents/blob/v7.0.1/README.md): ``` MIT License @@ -1866,22 +1866,6 @@ This product includes source derived from [@newrelic/newrelic-oss-cli](https://g limitations under the License. ``` -### @newrelic/proxy - -This product includes source derived from [@newrelic/proxy](https://github.com/newrelic/proxy) ([v2.0.0](https://github.com/newrelic/proxy/tree/v2.0.0)), distributed under the [MIT License](https://github.com/newrelic/proxy/blob/v2.0.0/README.md): - -``` -MIT License - -Copyright (c) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -``` - ### @newrelic/test-utilities This product includes source derived from [@newrelic/test-utilities](https://github.com/newrelic/node-test-utilities) ([v7.3.2](https://github.com/newrelic/node-test-utilities/tree/v7.3.2)), distributed under the [Apache-2.0 License](https://github.com/newrelic/node-test-utilities/blob/v7.3.2/LICENSE): @@ -9271,6 +9255,22 @@ By: Ika ``` +### proxy + +This product includes source derived from [proxy](https://github.com/TooTallNate/proxy-agents) ([v2.1.1](https://github.com/TooTallNate/proxy-agents/tree/v2.1.1)), distributed under the [MIT License](https://github.com/TooTallNate/proxy-agents/blob/v2.1.1/README.md): + +``` +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +``` + ### proxyquire This product includes source derived from [proxyquire](https://github.com/thlorenz/proxyquire) ([v1.8.0](https://github.com/thlorenz/proxyquire/tree/v1.8.0)), distributed under the [MIT License](https://github.com/thlorenz/proxyquire/blob/v1.8.0/LICENSE): diff --git a/lib/collector/http-agents.js b/lib/collector/http-agents.js index 3b385625c3..42e31c3fe1 100644 --- a/lib/collector/http-agents.js +++ b/lib/collector/http-agents.js @@ -5,8 +5,7 @@ 'use strict' -const parse = require('url').parse -const ProxyAgent = require('https-proxy-agent') +const { HttpsProxyAgent } = require('https-proxy-agent') const logger = require('../logger').child({ component: 'http-agent' }) const https = require('https') @@ -52,66 +51,34 @@ exports.proxyAgent = function proxyAgent(config) { if (null !== agentProxyWithKeepAlive) { return agentProxyWithKeepAlive } - const opts = proxyOptions(config) - const proxyUrl = opts.proxy_url + const proxyUrl = proxyOptions(config) const proxyOpts = { - host: proxyUrl.host, - port: proxyUrl.port, - protocol: proxyUrl.protocol, secureEndpoint: config.ssl, auth: proxyUrl.auth, - ca: opts.certificates, + ca: config?.certificates?.length ? config.certificates : [], keepAlive: true } - logger.info( - { - host: proxyOpts.host, - port: proxyOpts.port, - auth: !!proxyOpts.auth, - protocol: proxyUrl.protocol - }, - 'using proxy' - ) - - agentProxyWithKeepAlive = new ProxyAgent(proxyOpts) + logger.info(`using proxy: ${proxyUrl}`) + agentProxyWithKeepAlive = new HttpsProxyAgent(proxyUrl, proxyOpts) return agentProxyWithKeepAlive } function proxyOptions(config) { let proxyUrl if (config.proxy) { - const parsedUrl = parse(config.proxy) - - proxyUrl = { - protocol: parsedUrl.protocol || 'https:', - host: parsedUrl.hostname, - port: parsedUrl.port || 80, - auth: parsedUrl.auth - } + proxyUrl = config.proxy } else { + proxyUrl = 'https://' let proxyAuth = config.proxy_user if (config.proxy_pass !== '') { proxyAuth += ':' + config.proxy_pass + proxyUrl += `${proxyAuth}@` } - // Unless a proxy config is provided, default to HTTP. - proxyUrl = { - protocol: 'https:', - host: config.proxy_host || 'localhost', - port: config.proxy_port || 80, - auth: proxyAuth - } - } - - const opts = { - proxy_url: proxyUrl - } - - if (config.certificates && config.certificates.length > 0) { - opts.certificates = config.certificates + proxyUrl += `${config.proxy_host || 'localhost'}:${config.proxy_port || 80}` } - return opts + return proxyUrl } diff --git a/package-lock.json b/package-lock.json index 383ac71214..63cf48d800 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@newrelic/superagent": "^6.0.0", "@tyriar/fibonacci-heap": "^2.0.7", "concat-stream": "^2.0.0", - "https-proxy-agent": "^5.0.0", + "https-proxy-agent": "^7.0.1", "json-bigint": "^1.0.0", "json-stringify-safe": "^5.0.0", "readable-stream": "^3.6.1", @@ -31,7 +31,6 @@ "devDependencies": { "@newrelic/eslint-config": "^0.3.0", "@newrelic/newrelic-oss-cli": "^0.1.2", - "@newrelic/proxy": "^2.0.0", "@newrelic/test-utilities": "^7.3.2", "@octokit/rest": "^18.0.15", "@slack/bolt": "^3.7.0", @@ -63,6 +62,7 @@ "memcached": ">=0.2.8", "nock": "11.8.0", "prettier": "^2.3.2", + "proxy": "^2.1.1", "proxyquire": "^1.8.0", "q": "*", "rimraf": "^2.6.3", @@ -74,7 +74,7 @@ "when": "*" }, "engines": { - "node": ">=14", + "node": ">=16", "npm": ">=6.0.0" }, "optionalDependencies": { @@ -2036,6 +2036,54 @@ "npm": ">=6" } }, + "node_modules/@newrelic/native-metrics/node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "optional": true, + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/@newrelic/native-metrics/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "optional": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@newrelic/native-metrics/node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "optional": true, + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/@newrelic/native-metrics/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "optional": true + }, "node_modules/@newrelic/newrelic-oss-cli": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/@newrelic/newrelic-oss-cli/-/newrelic-oss-cli-0.1.2.tgz", @@ -2078,20 +2126,6 @@ "node": ">=8.0.0" } }, - "node_modules/@newrelic/proxy": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@newrelic/proxy/-/proxy-2.0.0.tgz", - "integrity": "sha512-xJOlsnn1UazcVF1EZ104/tU4Gn+m7yeDFA+2SRS2O+dZs2LKtkSil05ADA9Z0+GIimHuO0/z+agsL1mrY9wHZw==", - "dev": true, - "dependencies": { - "args": "^5.0.1", - "basic-auth-parser": "0.0.2", - "debug": "^3.2.6" - }, - "bin": { - "proxy": "bin/proxy.js" - } - }, "node_modules/@newrelic/security-agent": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@newrelic/security-agent/-/security-agent-0.2.0.tgz", @@ -5239,14 +5273,14 @@ } }, "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", + "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", "dependencies": { - "debug": "4" + "debug": "^4.3.4" }, "engines": { - "node": ">= 6.0.0" + "node": ">= 14" } }, "node_modules/agent-base/node_modules/debug": { @@ -5578,12 +5612,6 @@ } ] }, - "node_modules/basic-auth-parser": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/basic-auth-parser/-/basic-auth-parser-0.0.2.tgz", - "integrity": "sha512-Y7OBvWn+JnW45JWHLY6ybYub2k9cXCMrtCyO1Hds2s6eqClqWhPnOQpgXUPjAiMHj+A8TEPIQQ1dYENnJoBOHQ==", - "dev": true - }, "node_modules/before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", @@ -8847,15 +8875,15 @@ } }, "node_modules/https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.1.tgz", + "integrity": "sha512-Eun8zV0kcYS1g19r78osiQLEFIRspRUDd9tIfBCTBPBeMieF/EsJNL8VI3xOIdYRDEkjQnqOYPsZ2DsWsVsFwQ==", "dependencies": { - "agent-base": "6", + "agent-base": "^7.0.2", "debug": "4" }, "engines": { - "node": ">= 6" + "node": ">= 14" } }, "node_modules/https-proxy-agent/node_modules/debug": { @@ -11080,6 +11108,54 @@ "newrelic": ">=8.7.0" } }, + "node_modules/newrelic/node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "peer": true, + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/newrelic/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "peer": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/newrelic/node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "peer": true, + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/newrelic/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "peer": true + }, "node_modules/newrelic/node_modules/semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -12251,6 +12327,20 @@ "resolved": "https://registry.npmjs.org/long/-/long-5.2.3.tgz", "integrity": "sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==" }, + "node_modules/proxy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/proxy/-/proxy-2.1.1.tgz", + "integrity": "sha512-nLgd7zdUAOpB3ZO/xCkU8gy74UER7P0aihU8DkUsDS5ZoFwVCX7u8dy+cv5tVK8UaB/yminU1GiLWE26TKPYpg==", + "dev": true, + "dependencies": { + "args": "^5.0.3", + "basic-auth-parser": "0.0.2-1", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", @@ -12264,6 +12354,35 @@ "node": ">= 0.10" } }, + "node_modules/proxy/node_modules/basic-auth-parser": { + "version": "0.0.2-1", + "resolved": "https://registry.npmjs.org/basic-auth-parser/-/basic-auth-parser-0.0.2-1.tgz", + "integrity": "sha512-GFj8iVxo9onSU6BnnQvVwqvxh60UcSHJEDnIk3z4B6iOjsKSmqe+ibW0Rsz7YO7IE1HG3D3tqCNIidP46SZVdQ==", + "dev": true + }, + "node_modules/proxy/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/proxy/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, "node_modules/proxyquire": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/proxyquire/-/proxyquire-1.8.0.tgz", @@ -18166,6 +18285,42 @@ "https-proxy-agent": "^5.0.1", "nan": "^2.17.0", "semver": "^7.5.2" + }, + "dependencies": { + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "optional": true, + "requires": { + "debug": "4" + } + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "optional": true, + "requires": { + "ms": "2.1.2" + } + }, + "https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "optional": true, + "requires": { + "agent-base": "6", + "debug": "4" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "optional": true + } } }, "@newrelic/newrelic-oss-cli": { @@ -18201,17 +18356,6 @@ "spdx-license-list": "^6.1.0" } }, - "@newrelic/proxy": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@newrelic/proxy/-/proxy-2.0.0.tgz", - "integrity": "sha512-xJOlsnn1UazcVF1EZ104/tU4Gn+m7yeDFA+2SRS2O+dZs2LKtkSil05ADA9Z0+GIimHuO0/z+agsL1mrY9wHZw==", - "dev": true, - "requires": { - "args": "^5.0.1", - "basic-auth-parser": "0.0.2", - "debug": "^3.2.6" - } - }, "@newrelic/security-agent": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/@newrelic/security-agent/-/security-agent-0.2.0.tgz", @@ -20759,11 +20903,11 @@ "requires": {} }, "agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", + "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", "requires": { - "debug": "4" + "debug": "^4.3.4" }, "dependencies": { "debug": { @@ -21010,12 +21154,6 @@ "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", "dev": true }, - "basic-auth-parser": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/basic-auth-parser/-/basic-auth-parser-0.0.2.tgz", - "integrity": "sha512-Y7OBvWn+JnW45JWHLY6ybYub2k9cXCMrtCyO1Hds2s6eqClqWhPnOQpgXUPjAiMHj+A8TEPIQQ1dYENnJoBOHQ==", - "dev": true - }, "before-after-hook": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.3.tgz", @@ -23462,11 +23600,11 @@ } }, "https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.1.tgz", + "integrity": "sha512-Eun8zV0kcYS1g19r78osiQLEFIRspRUDd9tIfBCTBPBeMieF/EsJNL8VI3xOIdYRDEkjQnqOYPsZ2DsWsVsFwQ==", "requires": { - "agent-base": "6", + "agent-base": "^7.0.2", "debug": "4" }, "dependencies": { @@ -25123,6 +25261,40 @@ "peer": true, "requires": {} }, + "agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "peer": true, + "requires": { + "debug": "4" + } + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "peer": true, + "requires": { + "ms": "2.1.2" + } + }, + "https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "peer": true, + "requires": { + "agent-base": "6", + "debug": "4" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "peer": true + }, "semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -26020,6 +26192,40 @@ } } }, + "proxy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/proxy/-/proxy-2.1.1.tgz", + "integrity": "sha512-nLgd7zdUAOpB3ZO/xCkU8gy74UER7P0aihU8DkUsDS5ZoFwVCX7u8dy+cv5tVK8UaB/yminU1GiLWE26TKPYpg==", + "dev": true, + "requires": { + "args": "^5.0.3", + "basic-auth-parser": "0.0.2-1", + "debug": "^4.3.4" + }, + "dependencies": { + "basic-auth-parser": { + "version": "0.0.2-1", + "resolved": "https://registry.npmjs.org/basic-auth-parser/-/basic-auth-parser-0.0.2-1.tgz", + "integrity": "sha512-GFj8iVxo9onSU6BnnQvVwqvxh60UcSHJEDnIk3z4B6iOjsKSmqe+ibW0Rsz7YO7IE1HG3D3tqCNIidP46SZVdQ==", + "dev": true + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "proxy-addr": { "version": "2.0.7", "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", diff --git a/package.json b/package.json index 1b6cb68e62..1485dabdad 100644 --- a/package.json +++ b/package.json @@ -189,7 +189,7 @@ "@newrelic/superagent": "^6.0.0", "@tyriar/fibonacci-heap": "^2.0.7", "concat-stream": "^2.0.0", - "https-proxy-agent": "^5.0.0", + "https-proxy-agent": "^7.0.1", "json-bigint": "^1.0.0", "json-stringify-safe": "^5.0.0", "readable-stream": "^3.6.1", @@ -203,7 +203,6 @@ "devDependencies": { "@newrelic/eslint-config": "^0.3.0", "@newrelic/newrelic-oss-cli": "^0.1.2", - "@newrelic/proxy": "^2.0.0", "@newrelic/test-utilities": "^7.3.2", "@octokit/rest": "^18.0.15", "@slack/bolt": "^3.7.0", @@ -235,6 +234,7 @@ "memcached": ">=0.2.8", "nock": "11.8.0", "prettier": "^2.3.2", + "proxy": "^2.1.1", "proxyquire": "^1.8.0", "q": "*", "rimraf": "^2.6.3", diff --git a/test/lib/agent_helper.js b/test/lib/agent_helper.js index 88ec6ae182..48e52215cb 100644 --- a/test/lib/agent_helper.js +++ b/test/lib/agent_helper.js @@ -695,5 +695,16 @@ const helper = (module.exports = { */ isSupportedVersion(version) { return semver.gt(process.version, version) + }, + + /** + * The https-proxy-server we support finally supports keep alive + * See: https://github.com/TooTallNate/proxy-agents/pull/147 + * In order for tap to shutdown we must destroy the https agent. + * This assumes the agent already exists as a singleton so we can destroy + * the active http agent + */ + destroyProxyAgent() { + require('../../lib/collector/http-agents').proxyAgent().destroy() } }) diff --git a/test/smoke/proxy-api-connection-port.tap.js b/test/smoke/proxy-api-connection-port.tap.js index 39deca9cd8..6a28fb7b21 100644 --- a/test/smoke/proxy-api-connection-port.tap.js +++ b/test/smoke/proxy-api-connection-port.tap.js @@ -8,13 +8,13 @@ const tap = require('tap') const join = require('path').join const https = require('https') -const proxySetup = require('@newrelic/proxy') +const { createProxy: proxySetup } = require('proxy') const read = require('fs').readFileSync const configurator = require('../../lib/config') const Agent = require('../../lib/agent') const CollectorAPI = require('../../lib/collector/api') const { getTestSecret } = require('../helpers/secrets') -const { SSL_HOST } = require('../lib/agent_helper') +const { SSL_HOST, destroyProxyAgent } = require('../lib/agent_helper') let port = 0 const SSL_CONFIG = { @@ -25,6 +25,10 @@ const license = getTestSecret('TEST_LICENSE') tap.test('setting proxy_port should use the proxy agent', (t) => { const server = proxySetup(https.createServer(SSL_CONFIG)) + t.teardown(() => { + destroyProxyAgent() + server.close() + }) server.listen(0, () => { port = server.address().port @@ -62,8 +66,6 @@ tap.test('setting proxy_port should use the proxy agent', (t) => { api.shutdown((error) => { t.notOk(error, 'should have shut down without issue') t.notOk(agent.config.run_id, 'run ID should have been cleared by shutdown') - - server.close() t.end() }) }) diff --git a/test/smoke/proxy-api-connection-ssl.tap.js b/test/smoke/proxy-api-connection-ssl.tap.js index 433e24fe6d..5561c63666 100644 --- a/test/smoke/proxy-api-connection-ssl.tap.js +++ b/test/smoke/proxy-api-connection-ssl.tap.js @@ -8,13 +8,13 @@ const tap = require('tap') const join = require('path').join const https = require('https') -const proxySetup = require('@newrelic/proxy') +const { createProxy: proxySetup } = require('proxy') const read = require('fs').readFileSync const configurator = require('../../lib/config') const Agent = require('../../lib/agent') const CollectorAPI = require('../../lib/collector/api') const { getTestSecret } = require('../helpers/secrets') -const { SSL_HOST } = require('../lib/agent_helper') +const { SSL_HOST, destroyProxyAgent } = require('../lib/agent_helper') let port = 0 const SSL_CONFIG = { @@ -25,6 +25,10 @@ const license = getTestSecret('TEST_LICENSE') tap.test('support ssl to the proxy', (t) => { const server = proxySetup(https.createServer(SSL_CONFIG)) + t.teardown(() => { + destroyProxyAgent() + server.close() + }) server.listen(0, () => { port = server.address().port @@ -57,8 +61,6 @@ tap.test('support ssl to the proxy', (t) => { api.shutdown((error) => { t.notOk(error, 'should have shut down without issue') t.notOk(agent.config.run_id, 'run ID should have been cleared by shutdown') - - server.close() t.end() }) }) diff --git a/test/unit/collector/http-agents.test.js b/test/unit/collector/http-agents.test.js index a36051261d..8867ea3dd9 100644 --- a/test/unit/collector/http-agents.test.js +++ b/test/unit/collector/http-agents.test.js @@ -8,7 +8,7 @@ const tap = require('tap') const proxyquire = require('proxyquire') const PROXY_HOST = 'unique.newrelic.com' -const PROXY_PORT = 54532 +const PROXY_PORT = '54532' const PROXY_URL_WITH_PORT = `https://${PROXY_HOST}:${PROXY_PORT}` const PROXY_URL_WITHOUT_PORT = `https://${PROXY_HOST}` @@ -81,10 +81,10 @@ tap.test('proxy agent', (t) => { } agent = proxyAgent(config) t.ok(agent, 'should be created successfully') - t.equal(agent.proxy.host, PROXY_HOST, 'should have correct proxy host') + t.equal(agent.proxy.hostname, PROXY_HOST, 'should have correct proxy host') t.equal(agent.proxy.port, PROXY_PORT, 'should have correct proxy port') t.equal(agent.proxy.protocol, 'https:', 'should be set to https') - t.equal(agent.proxy.keepAlive, true, 'should be keepAlive') + t.equal(agent.keepAlive, true, 'should be keepAlive') t.end() }) @@ -94,10 +94,10 @@ tap.test('proxy agent', (t) => { } agent = proxyAgent(config) t.ok(agent, 'should be created successfully') - t.equal(agent.proxy.host, PROXY_HOST, 'should have correct proxy host') + t.equal(agent.proxy.hostname, PROXY_HOST, 'should have correct proxy host') t.equal(agent.proxy.port, PROXY_PORT, 'should have correct proxy port') t.equal(agent.proxy.protocol, 'https:', 'should be set to https') - t.equal(agent.proxy.keepAlive, true, 'should be keepAlive') + t.equal(agent.keepAlive, true, 'should be keepAlive') t.end() }) @@ -117,28 +117,28 @@ tap.test('proxy agent', (t) => { } agent = proxyAgent(config) t.ok(agent, 'should be created successfully') - t.equal(agent.proxy.host, PROXY_HOST, 'should have correct proxy host') - t.equal(agent.proxy.port, 80, 'in the absence of a defined port, port should be 80') + t.equal(agent.proxy.hostname, PROXY_HOST, 'should have correct proxy host') t.equal(agent.proxy.protocol, 'https:', 'should be set to https') - t.equal(agent.proxy.keepAlive, true, 'should be keepAlive') + t.equal(agent.keepAlive, true, 'should be keepAlive') + t.equal(agent.connectOpts.secureEndpoint, undefined) t.end() }) t.test('configured with certificates defined', (t) => { const { proxyAgent } = proxyquire('../../../lib/collector/http-agents', { - 'https-proxy-agent': Mock + 'https-proxy-agent': { HttpsProxyAgent: Mock } }) const config = { proxy: PROXY_URL_WITH_PORT, - certificates: ['cert1'] + certificates: ['cert1'], + ssl: true } - function Mock(args) { - t.same(args.ca, ['cert1'], 'should have correct certs') - t.equal(args.host, PROXY_HOST, 'should have correct proxy host') - t.equal(args.port, `${PROXY_PORT}`, 'should have correct proxy port') - t.equal(args.protocol, 'https:', 'should be set to https') - t.equal(args.keepAlive, true, 'should be keepAlive') + function Mock(host, opts) { + t.equal(host, PROXY_URL_WITH_PORT, 'should have correct proxy url') + t.same(opts.ca, ['cert1'], 'should have correct certs') + t.equal(opts.keepAlive, true, 'should be keepAlive') + t.equal(opts.secureEndpoint, true) t.end() } @@ -148,28 +148,32 @@ tap.test('proxy agent', (t) => { t.test('should default to localhost if no proxy_host or proxy_port is specified', (t) => { const config = { proxy_user: 'unit-test', - proxy_pass: 'secret' + proxy_pass: 'secret', + ssl: true } agent = proxyAgent(config) t.ok(agent, 'should be created successfully') - t.equal(agent.proxy.host, 'localhost', 'should have correct proxy host') - t.equal(agent.proxy.port, 80, 'should have correct proxy port') + t.equal(agent.proxy.hostname, 'localhost', 'should have correct proxy host') + t.equal(agent.proxy.port, '80', 'should have correct proxy port') t.equal(agent.proxy.protocol, 'https:', 'should be set to https') - t.equal(agent.proxy.auth, 'unit-test:secret', 'should have correct auth') + t.equal(agent.proxy.username, 'unit-test', 'should have correct basic auth username') + t.equal(agent.proxy.password, 'secret', 'should have correct basic auth password') + t.equal(agent.connectOpts.secureEndpoint, true) t.end() }) - t.test('should not append password to auth if it is an empty string', (t) => { + t.test('should not parse basic auth user if password is empty', (t) => { const config = { proxy_user: 'unit-test', proxy_pass: '' } agent = proxyAgent(config) t.ok(agent, 'should be created successfully') - t.equal(agent.proxy.host, 'localhost', 'should have correct proxy host') - t.equal(agent.proxy.port, 80, 'should have correct proxy port') + t.equal(agent.proxy.hostname, 'localhost', 'should have correct proxy host') + t.equal(agent.proxy.port, '80', 'should have correct proxy port') t.equal(agent.proxy.protocol, 'https:', 'should be set to https') - t.equal(agent.proxy.auth, 'unit-test', 'should have correct auth') + t.not(agent.proxy.username, 'should not have basic auth username') + t.not(agent.proxy.password, 'should not have basic auth password') t.end() }) }) diff --git a/third_party_manifest.json b/third_party_manifest.json index c4ce1b2b6c..90880bf07c 100644 --- a/third_party_manifest.json +++ b/third_party_manifest.json @@ -145,15 +145,15 @@ "publisher": "Max Ogden", "email": "max@maxogden.com" }, - "https-proxy-agent@5.0.1": { + "https-proxy-agent@7.0.1": { "name": "https-proxy-agent", - "version": "5.0.1", - "range": "^5.0.0", + "version": "7.0.1", + "range": "^7.0.1", "licenses": "MIT", - "repoUrl": "https://github.com/TooTallNate/node-https-proxy-agent", - "versionedRepoUrl": "https://github.com/TooTallNate/node-https-proxy-agent/tree/v5.0.1", + "repoUrl": "https://github.com/TooTallNate/proxy-agents", + "versionedRepoUrl": "https://github.com/TooTallNate/proxy-agents/tree/v7.0.1", "licenseFile": "node_modules/https-proxy-agent/README.md", - "licenseUrl": "https://github.com/TooTallNate/node-https-proxy-agent/blob/v5.0.1/README.md", + "licenseUrl": "https://github.com/TooTallNate/proxy-agents/blob/v7.0.1/README.md", "licenseTextSource": "spdx", "publisher": "Nathan Rajlich", "email": "nathan@tootallnate.net", @@ -249,20 +249,6 @@ "licenseTextSource": "file", "publisher": "New Relic" }, - "@newrelic/proxy@2.0.0": { - "name": "@newrelic/proxy", - "version": "2.0.0", - "range": "^2.0.0", - "licenses": "MIT", - "repoUrl": "https://github.com/newrelic/proxy", - "versionedRepoUrl": "https://github.com/newrelic/proxy/tree/v2.0.0", - "licenseFile": "node_modules/@newrelic/proxy/README.md", - "licenseUrl": "https://github.com/newrelic/proxy/blob/v2.0.0/README.md", - "licenseTextSource": "spdx", - "publisher": "Nathan Rajlich", - "email": "nathan@tootallnate.net", - "url": "http://n8.io/" - }, "@newrelic/test-utilities@7.3.2": { "name": "@newrelic/test-utilities", "version": "7.3.2", @@ -655,6 +641,20 @@ "licenseTextSource": "file", "publisher": "James Long" }, + "proxy@2.1.1": { + "name": "proxy", + "version": "2.1.1", + "range": "^2.1.1", + "licenses": "MIT", + "repoUrl": "https://github.com/TooTallNate/proxy-agents", + "versionedRepoUrl": "https://github.com/TooTallNate/proxy-agents/tree/v2.1.1", + "licenseFile": "node_modules/proxy/README.md", + "licenseUrl": "https://github.com/TooTallNate/proxy-agents/blob/v2.1.1/README.md", + "licenseTextSource": "spdx", + "publisher": "Nathan Rajlich", + "email": "nathan@tootallnate.net", + "url": "http://n8.io/" + }, "proxyquire@1.8.0": { "name": "proxyquire", "version": "1.8.0",