mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-23 17:41:50 -04:00
5
.changeset/heavy-dolls-give.md
Normal file
5
.changeset/heavy-dolls-give.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/npm-registry-agent": patch
|
||||
---
|
||||
|
||||
Proxy URLs with special characters in credentials should work.
|
||||
@@ -33,7 +33,7 @@ export default function getAgent (uri: string, opts: AgentOptions) {
|
||||
const key = [
|
||||
`https:${isHttps.toString()}`,
|
||||
pxuri
|
||||
? `proxy:${pxuri.protocol}//${pxuri.host}:${pxuri.port}`
|
||||
? `proxy:${pxuri.protocol}//${pxuri.username}:${pxuri.password}@${pxuri.host}:${pxuri.port}`
|
||||
: '>no-proxy<',
|
||||
`local-address:${opts.localAddress ?? '>no-local-address<'}`,
|
||||
`strict-ssl:${isHttps ? Boolean(opts.strictSsl).toString() : '>no-strict-ssl<'}`,
|
||||
@@ -154,7 +154,7 @@ function getProxy (
|
||||
isHttps: boolean
|
||||
) {
|
||||
const popts = {
|
||||
auth: (proxyUrl.username ? (proxyUrl.password ? `${proxyUrl.username}:${proxyUrl.password}` : proxyUrl.username) : undefined),
|
||||
auth: getAuth(proxyUrl),
|
||||
ca: opts.ca,
|
||||
cert: opts.cert,
|
||||
host: proxyUrl.hostname,
|
||||
@@ -179,3 +179,14 @@ function getProxy (
|
||||
return new SocksProxyAgent(popts)
|
||||
}
|
||||
}
|
||||
|
||||
function getAuth (user: { username?: string, password?: string }) {
|
||||
if (!user.username) {
|
||||
return undefined
|
||||
}
|
||||
let auth = user.username
|
||||
if (user.password) {
|
||||
auth += `:${user.password}`
|
||||
}
|
||||
return decodeURIComponent(auth)
|
||||
}
|
||||
|
||||
@@ -86,3 +86,25 @@ test('a socks proxy', () => {
|
||||
type: 5,
|
||||
})
|
||||
})
|
||||
|
||||
test('proxy credentials are decoded', () => {
|
||||
const opts = {
|
||||
httpsProxy: 'https://use%21r:pas%2As@my.proxy:1234/foo',
|
||||
...OPTS,
|
||||
}
|
||||
expect(getAgent('https://foo.com/bar', opts)).toEqual({
|
||||
__type: 'https-proxy',
|
||||
auth: 'use!r:pas*s',
|
||||
ca: 'ca',
|
||||
cert: 'cert',
|
||||
host: 'my.proxy',
|
||||
key: 'key',
|
||||
localAddress: 'localAddress',
|
||||
maxSockets: 5,
|
||||
path: '/foo',
|
||||
port: '1234',
|
||||
protocol: 'https:',
|
||||
rejectUnauthorized: true,
|
||||
timeout: 6,
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user