From 8bb7b0b187d2e01aa81f821c5e5022112172a8f5 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Fri, 6 Dec 2024 16:10:21 +0100 Subject: [PATCH 1/5] tmp --- tests/docker-compose.yml | 8 ++------ tests/test-client/package.json | 3 +-- tests/test-client/src/proxy.test.ts | 7 +++---- tests/test-client/src/utils.ts | 6 ++++-- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 65459d5..d74dc7b 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -8,9 +8,7 @@ services: networks: - test-servers working_dir: /repo/tests/test-client - environment: - - MOCHA_TESTS=src/direct.test.ts src/tls.test.ts src/socket.test.ts - command: /bin/sh -c 'rm -rf /root/.npm && npm run test:watch' + command: /bin/sh -c 'rm -rf /root/.npm && npm run test src/direct.test.ts src/tls.test.ts src/socket.test.ts' depends_on: test-https-server: condition: service_healthy @@ -23,15 +21,13 @@ services: networks: - test-proxies working_dir: /repo/tests/test-client - environment: - - MOCHA_TESTS=src/proxy.test.ts command: /bin/sh -c ' while [ ! -f /root/.mitmproxy/mitmproxy-ca-cert.pem ]; do sleep 1; done && cp /root/.mitmproxy/mitmproxy-ca-cert.pem /usr/local/share/ca-certificates/mitmproxy.crt && update-ca-certificates && /usr/local/bin/configure-kerberos-client.sh && rm -rf /root/.npm && - npm run test:watch' + npm run test src/proxy.test.ts' depends_on: test-http-proxy: condition: service_started diff --git a/tests/test-client/package.json b/tests/test-client/package.json index 83aa345..43997e9 100644 --- a/tests/test-client/package.json +++ b/tests/test-client/package.json @@ -4,8 +4,7 @@ "description": "", "main": "test.js", "scripts": { - "test": "mocha -r ts-node/register $MOCHA_TESTS", - "test:watch": "npm test -- -w --watch-extensions ts" + "test": "mocha -r ts-node/register --exit" }, "keywords": [], "author": "", diff --git a/tests/test-client/src/proxy.test.ts b/tests/test-client/src/proxy.test.ts index a928b19..dc0073d 100644 --- a/tests/test-client/src/proxy.test.ts +++ b/tests/test-client/src/proxy.test.ts @@ -5,7 +5,7 @@ import * as fs from 'fs'; import * as path from 'path'; import * as vpa from '../../..'; import { createPacProxyAgent } from '../../../src/agent'; -import { testRequest, ca, unusedCa, proxiedProxyAgentParamsV1, tlsProxiedProxyAgentParamsV1 } from './utils'; +import { testRequest, ca, unusedCa, proxiedProxyAgentParamsV1, tlsProxiedProxyAgentParamsV1, log } from './utils'; describe('Proxied client', function () { it('should use HTTP proxy for HTTPS connection', function () { @@ -126,7 +126,6 @@ describe('Proxied client', function () { if (proxyAuthenticate) { assert.strictEqual(proxyAuthenticate, 'Negotiate'); } - const log = { ...console, trace: console.log }; return lookupProxyAuthorization(log, log, proxyAuthenticateCache, true, proxyURL, proxyAuthenticate, state); }, }), @@ -188,7 +187,7 @@ describe('Proxied client', function () { const params = { ...proxiedProxyAgentParamsV1, loadAdditionalCertificates: async () => [ - ...await vpa.loadSystemCertificates({ log: console }), + ...await vpa.loadSystemCertificates({ log }), ], }; const { resolveProxyWithRequest: resolveProxy } = vpa.createProxyResolver(params); @@ -279,7 +278,7 @@ function sendTelemetry(mainThreadTelemetry: Console, authenticate: string[], isR } telemetrySent = true; - mainThreadTelemetry.log('proxyAuthenticationRequest', { + mainThreadTelemetry.debug('proxyAuthenticationRequest', { authenticationType: authenticate.map(a => a.split(' ')[0]).join(','), extensionHostType: isRemote ? 'remote' : 'local', }); diff --git a/tests/test-client/src/utils.ts b/tests/test-client/src/utils.ts index bd4036e..8820155 100644 --- a/tests/test-client/src/utils.ts +++ b/tests/test-client/src/utils.ts @@ -7,6 +7,8 @@ import * as assert from 'assert'; import * as vpa from '../../..'; import { loadSystemCertificates } from '../../../src'; +export const log = { ...console, debug: () => {}, trace: () => {} }; + export const ca = [ fs.readFileSync(path.join(__dirname, '../../test-https-server/ssl_cert.pem')).toString(), fs.readFileSync(path.join(__dirname, '../../test-https-server/ssl_teapot_cert.pem')).toString(), @@ -21,12 +23,12 @@ export const directProxyAgentParams: vpa.ProxyAgentParams = { isAdditionalFetchSupportEnabled: () => true, addCertificatesV1: () => false, addCertificatesV2: () => true, - log: console, + log, getLogLevel: () => vpa.LogLevel.Trace, proxyResolveTelemetry: () => undefined, useHostProxy: true, loadAdditionalCertificates: async () => [ - ...await loadSystemCertificates({ log: console }), + ...await loadSystemCertificates({ log }), ...ca, ], env: {}, From b3cbbf242b7f6f2d9984e20c554d17554813bb51 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Fri, 6 Dec 2024 16:37:38 +0100 Subject: [PATCH 2/5] test --- azure-pipelines/publish.yml | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/azure-pipelines/publish.yml b/azure-pipelines/publish.yml index 26a3e70..d3a266d 100644 --- a/azure-pipelines/publish.yml +++ b/azure-pipelines/publish.yml @@ -4,7 +4,10 @@ trigger: branches: include: - main -pr: none + +pr: +- main +- release/* resources: repositories: @@ -31,6 +34,25 @@ extends: displayName: Install dependencies - script: npm run compile displayName: Compile - - testPlatforms: {} + + testPlatforms: + - name: Linux + nodeVersions: + - 20.x + + testSteps: + - script: npm ci + displayName: Install dependencies + - script: npm run compile + displayName: Compile + - script: docker run --rm -v `pwd`/..:/repo -w /repo/tests/test-client node:20 npm i + workingDirectory: tests + displayName: Install test dependencies + - script: docker compose run test-direct-client + workingDirectory: tests + displayName: Test direct client + - script: docker compose run test-proxy-client + workingDirectory: tests + displayName: Test proxy client + publishPackage: ${{ parameters.publishPackage }} \ No newline at end of file From ce8e1a3e2d94d71c5eff3338cdd9a3724f770e23 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Mon, 9 Dec 2024 08:51:18 +0100 Subject: [PATCH 3/5] avoid pulling --- tests/docker-compose.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index d74dc7b..9dfb273 100644 --- a/tests/docker-compose.yml +++ b/tests/docker-compose.yml @@ -13,7 +13,6 @@ services: test-https-server: condition: service_healthy test-proxy-client: - image: test-proxy-client:latest build: test-proxy-client volumes: - ..:/repo @@ -48,7 +47,6 @@ services: test-https-server: condition: service_healthy test-http-auth-proxy: - image: test-http-auth-proxy:latest build: test-http-auth-proxy networks: - test-proxies @@ -59,7 +57,6 @@ services: test-https-server: condition: service_healthy test-http-kerberos-proxy: - image: test-http-kerberos-proxy:latest build: test-http-kerberos-proxy container_name: test-http-kerberos-proxy # needs to be configured to have a static name for the kerberos server hostname networks: @@ -86,7 +83,6 @@ services: test-https-server: condition: service_healthy test-https-server: - image: test-https-server:latest build: test-https-server volumes: - ./test-https-server:/etc/nginx From d6ce4a73b5e6714a1871689d1f18d844201a0d44 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Mon, 9 Dec 2024 09:42:34 +0100 Subject: [PATCH 4/5] handle error --- package-lock.json | 4 ++-- tests/test-client/src/utils.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4d7aaa5..5aae90b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@vscode/proxy-agent", - "version": "0.26.0", + "version": "0.27.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@vscode/proxy-agent", - "version": "0.26.0", + "version": "0.27.0", "license": "MIT", "dependencies": { "@tootallnate/once": "^3.0.0", diff --git a/tests/test-client/src/utils.ts b/tests/test-client/src/utils.ts index 8820155..2621099 100644 --- a/tests/test-client/src/utils.ts +++ b/tests/test-client/src/utils.ts @@ -82,6 +82,9 @@ export async function testRequest(client: reject(err); } }); + res.on('error', err => { + reject(err); + }); }); req.on('error', err => { reject(err); From 27bd8d889f115ecf1c40c6a769266c518bacea00 Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Mon, 9 Dec 2024 09:45:21 +0100 Subject: [PATCH 5/5] start clean --- azure-pipelines/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure-pipelines/publish.yml b/azure-pipelines/publish.yml index d3a266d..bed23e9 100644 --- a/azure-pipelines/publish.yml +++ b/azure-pipelines/publish.yml @@ -48,10 +48,10 @@ extends: - script: docker run --rm -v `pwd`/..:/repo -w /repo/tests/test-client node:20 npm i workingDirectory: tests displayName: Install test dependencies - - script: docker compose run test-direct-client + - script: docker ps -a -q | xargs docker rm -f && docker compose run test-direct-client workingDirectory: tests displayName: Test direct client - - script: docker compose run test-proxy-client + - script: docker ps -a -q | xargs docker rm -f && docker compose run test-proxy-client workingDirectory: tests displayName: Test proxy client