mirror of https://github.com/actions/toolkit
strip leading dot + '*' match all + testcases
parent
da7e8df206
commit
586ad49adf
|
@ -145,6 +145,30 @@ describe('proxy', () => {
|
||||||
expect(bypass).toBeFalsy()
|
expect(bypass).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('checkBypass returns true if host with subdomain in no_proxy', () => {
|
||||||
|
process.env['no_proxy'] = 'myserver.com'
|
||||||
|
const bypass = pm.checkBypass(new URL('https://sub.myserver.com'))
|
||||||
|
expect(bypass).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('checkBypass returns true if host with leading dot in no_proxy', () => {
|
||||||
|
process.env['no_proxy'] = '.myserver.com'
|
||||||
|
const bypass = pm.checkBypass(new URL('https://myserver.com'))
|
||||||
|
expect(bypass).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('checkBypass returns false if no_proxy is subdomain', () => {
|
||||||
|
process.env['no_proxy'] = 'myserver.com'
|
||||||
|
const bypass = pm.checkBypass(new URL('https://myserver.com.evil.org'))
|
||||||
|
expect(bypass).toBeFalsy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('checkBypass returns true if no_proxy is "*"', () => {
|
||||||
|
process.env['no_proxy'] = '*'
|
||||||
|
const bypass = pm.checkBypass(new URL('https://anything.whatsoever.com'))
|
||||||
|
expect(bypass).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
it('HttpClient does basic http get request through proxy', async () => {
|
it('HttpClient does basic http get request through proxy', async () => {
|
||||||
process.env['http_proxy'] = _proxyUrl
|
process.env['http_proxy'] = _proxyUrl
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
|
|
|
@ -30,6 +30,11 @@ export function checkBypass(reqUrl: URL): boolean {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// '*' match all hosts (https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/#standardizing-no_proxy)
|
||||||
|
if (noProxy === '*') {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Determine the request port
|
// Determine the request port
|
||||||
let reqPort: number | undefined
|
let reqPort: number | undefined
|
||||||
if (reqUrl.port) {
|
if (reqUrl.port) {
|
||||||
|
@ -50,8 +55,13 @@ export function checkBypass(reqUrl: URL): boolean {
|
||||||
for (const upperNoProxyItem of noProxy
|
for (const upperNoProxyItem of noProxy
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(x => x.trim().toUpperCase())
|
.map(x => x.trim().toUpperCase())
|
||||||
|
.map(x => (x.startsWith('.') ? x.substring(1) : x)) // Strip leading dot (https://about.gitlab.com/blog/2021/01/27/we-need-to-talk-no-proxy/#standardizing-no_proxy)
|
||||||
.filter(x => x)) {
|
.filter(x => x)) {
|
||||||
if (upperReqHosts.some(x => x.includes(upperNoProxyItem))) {
|
if (
|
||||||
|
upperReqHosts.some(
|
||||||
|
x => x === upperNoProxyItem || x.endsWith(`.${upperNoProxyItem}`)
|
||||||
|
)
|
||||||
|
) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue