Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests #55

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions azure-pipelines/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ trigger:
branches:
include:
- main
pr: none

pr:
- main
- release/*

resources:
repositories:
Expand All @@ -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 ps -a -q | xargs docker rm -f && docker compose run test-direct-client
workingDirectory: tests
displayName: Test direct client
- script: docker ps -a -q | xargs docker rm -f && docker compose run test-proxy-client
workingDirectory: tests
displayName: Test proxy client

publishPackage: ${{ parameters.publishPackage }}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,25 @@ 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
test-proxy-client:
image: test-proxy-client:latest
build: test-proxy-client
volumes:
- ..:/repo
- ./test-https-proxy/mitmproxy-config:/root/.mitmproxy
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
Expand All @@ -52,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
Expand All @@ -63,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:
Expand All @@ -90,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
Expand Down
3 changes: 1 addition & 2 deletions tests/test-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down
7 changes: 3 additions & 4 deletions tests/test-client/src/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
},
}),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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',
});
Expand Down
9 changes: 7 additions & 2 deletions tests/test-client/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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: {},
Expand Down Expand Up @@ -80,6 +82,9 @@ export async function testRequest<C extends typeof https | typeof http>(client:
reject(err);
}
});
res.on('error', err => {
reject(err);
});
});
req.on('error', err => {
reject(err);
Expand Down
Loading