Compare commits

..

11 Commits

Author SHA1 Message Date
Ferenc Hammerl 7b24f92e45 Update proxy.test.ts 2023-03-02 14:51:56 +01:00
Ferenc Hammerl 4fefed4466 Fix linting 2023-03-02 13:48:37 +00:00
Ferenc Hammerl b511bc151f Better ipv6 definitions 2023-03-02 11:36:03 +00:00
Ferenc Hammerl 5d8e1ee68b Update proxy.ts 2023-03-02 11:38:57 +01:00
Ferenc Hammerl e4ae385d1a Fix linting 2023-03-01 16:29:38 +00:00
Ferenc Hammerl b708d5ba60 Fix formatting 2023-03-01 15:30:55 +00:00
Ferenc Hammerl 4557cd07bb Restore accidentally deleted test 2023-03-01 15:25:23 +00:00
Ferenc Hammerl c285ab1ccd Expect empty array instead of undefined 2023-03-01 15:09:48 +00:00
Ferenc Hammerl 833d5cadab Bypass proxy on loopback IPs 2023-03-01 13:52:48 +00:00
Ferenc Hammerl 1f4b3fac06 Revert "Bypass proxy on loopback IPs"
This reverts commit 8d92c9c903.
2023-03-01 13:48:44 +00:00
Ferenc Hammerl 8d92c9c903 Bypass proxy on loopback IPs 2023-03-01 13:45:12 +00:00
3 changed files with 41 additions and 17 deletions
+1 -17
View File
@@ -242,7 +242,7 @@ export async function downloadCacheStorageSDK(
// If the file exceeds the buffer maximum length (~1 GB on 32-bit systems and ~2 GB
// on 64-bit systems), split the download into multiple segments
// ~2 GB = 2147483647, beyond this, we start getting out of range error. So, capping it accordingly.
const maxSegmentSize = Math.min(102760447, buffer.constants.MAX_LENGTH)
const maxSegmentSize = Math.min(2147483647, buffer.constants.MAX_LENGTH)
const downloadProgress = new DownloadProgress(contentLength)
const fd = fs.openSync(archivePath, 'w')
@@ -275,23 +275,7 @@ export async function downloadCacheStorageSDK(
'Aborting cache download as the download time exceeded the timeout.'
)
} else if (Buffer.isBuffer(result)) {
core.info(
`Segment offset before writing result to the file ${downloadProgress.segmentOffset}`
)
core.info(
`Download progress object before writing result ${JSON.stringify(
downloadProgress
)}`
)
fs.writeFileSync(fd, result)
core.info(
`Segment offset after writing result to the file ${downloadProgress.segmentOffset}`
)
core.info(
`Download progress object after writing result ${JSON.stringify(
downloadProgress
)}`
)
}
}
} finally {
@@ -237,6 +237,31 @@ describe('proxy', () => {
expect(_proxyConnects).toHaveLength(0)
})
it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => {
// setup a server listening on localhost:8091
const server = http.createServer((request, response) => {
response.writeHead(200)
request.pipe(response)
})
server.listen(8091)
try {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient()
let res = await httpClient.get('http://localhost:8091')
expect(res.message.statusCode).toBe(200)
res = await httpClient.get('http://127.0.0.1:8091')
expect(res.message.statusCode).toBe(200)
// no support for ipv6 for now
expect(httpClient.get('http://[::1]:8091')).rejects.toThrow()
// proxy at _proxyUrl was ignored
expect(_proxyConnects).toEqual([])
} finally {
server.close()
}
})
it('proxyAuth not set in tunnel agent when authentication is not provided', async () => {
process.env['https_proxy'] = 'http://127.0.0.1:8080'
const httpClient = new httpm.HttpClient()
+15
View File
@@ -25,6 +25,11 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
const reqHost = reqUrl.hostname
if (isLoopbackAddress(reqHost)) {
return true
}
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''
if (!noProxy) {
return false
@@ -66,3 +71,13 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
function isLoopbackAddress(host: string): boolean {
const hostLower = host.toLowerCase()
return (
hostLower === 'localhost' ||
hostLower.startsWith('127.') ||
hostLower.startsWith('[::1]') ||
hostLower.startsWith('[0:0:0:0:0:0:0:1]')
)
}