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

chore: re-implement skipped windows test #95

Merged
merged 3 commits into from
Apr 4, 2024
Merged
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"@npmcli/template-oss": "4.21.3",
"minipass-fetch": "^3.0.3",
"nock": "^13.2.7",
"semver": "^7.5.4",
"simple-socks": "^3.1.0",
"socksv5": "^0.0.6",
"tap": "^16.3.0"
},
"repository": {
Expand Down
10 changes: 1 addition & 9 deletions test/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

const t = require('tap')
const timers = require('timers/promises')
const semver = require('semver')
const dns = require('dns')
const { createSetup, mockConnect } = require('./fixtures/setup.js')

const isWindows = process.platform === 'win32'

const agentTest = (t, opts) => {
const { setup, hasProxy, isSocks } = createSetup(opts)
t.test('single request basic', async (t) => {
Expand Down Expand Up @@ -174,12 +171,7 @@ const agentTest = (t, opts) => {
})

if (isSocks) {
// weird bug that fails with a message about node internals starting with this specific
// node version in windows. skipping this test for now to ship these agent updates.
const skipThis = semver.gte(process.version, '18.17.1') && isWindows && !opts.serverTls
if (!skipThis) {
await t.rejects(client.get('/'))
}
await t.rejects(client.get('/'))
} else {
const res = await client.get('/')
t.equal(res.status, 500)
Expand Down
26 changes: 7 additions & 19 deletions test/fixtures/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const http = require('http')
const https = require('https')
const timers = require('timers/promises')
const fetch = require('minipass-fetch')
const socks = require('socksv5')

const parseAuthHeader = (header) => {
const reqAuth = header.slice('Basic '.length)
Expand Down Expand Up @@ -270,29 +271,16 @@ class HttpsProxy extends HttpProxy {
}

class SocksProxy extends Server {
#failConnect

constructor (t, { protocol = 'socks:', simpleSocks, failConnect, ...options } = {}) {
constructor (t, { protocol = 'socks:', failConnect, ...options } = {}) {
super(t, {
...options,
protocol,
connectionEvent: 'handshake',
createServer: ({ auth }) => simpleSocks.createServer({
authenticate: (username, password, _, callback) => {
const args = auth ? [auth(username, password) ? null : new Error('Invalid auth')] : []
return setImmediate(callback, ...args)
},
}),
createServer: ({ auth }) => socks.createServer({
auths: [auth
? socks.auth.UserPassword((user, password, cb) => cb(auth(user, password)))
: socks.auth.None()],
}, (_, accept, deny) => failConnect ? deny() : accept())._srv,
})

this.#failConnect = failConnect
this.server.on('proxyConnect', this.#proxyConnect)
}

#proxyConnect = (_, socket) => {
if (this.#failConnect) {
socket.destroy(new Error('failConnect!'))
}
}
}

Expand Down
1 change: 0 additions & 1 deletion test/fixtures/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const createSetup = ({ serverTls, proxyTls, ...baseOpts }) => {
...baseOpts.proxy,
...opts.proxy,
agent: new Agent(omit(agentOpts, 'timeouts')),
simpleSocks: await import('simple-socks').then(r => r.default),
})
await proxy.start()
t.comment(`Proxy: ${proxy.address} ${proxy.hostAddress}`)
Expand Down
Loading