Compare commits

...

25 Commits

Author SHA1 Message Date
Ferenc Hammerl fe3ff532cc port runner proxy 2023-03-07 10:01:49 +00: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
Lovepreet Singh 0db3029fcf Merge pull request #1353 from actions/pdotl/zstd-version-fix
Hotfix Zstd breaking due to version change in runners
2023-02-21 00:50:51 +05:30
Lovepreet Singh e6e29846f2 Add debug statement for exact zstd version value and remove dependence on version for now 2023-02-20 19:13:38 +00:00
Lovepreet Singh 7c15bf6f40 Fix failing windows test 2023-02-20 18:50:26 +00:00
Lovepreet Singh bc713ab90d Add release info 2023-02-20 18:38:47 +00:00
Lovepreet Singh a9d266bb7c Fix lint issues 2023-02-20 15:26:04 +00:00
Lovepreet Singh cf3dd065b8 Add default value and rename args 2023-02-20 14:59:12 +00:00
Lovepreet Singh 6ec51745ad Update debug statement to include latest command 2023-02-20 14:23:53 +00:00
Lovepreet Singh 0f91c9c203 Bump version using npm 2023-02-20 13:53:17 +00:00
Lovepreet Singh e18b2d8a33 0.0.1 2023-02-20 13:43:31 +00:00
Lovepreet Singh 4fd425926c Fix version number 2023-02-20 13:43:24 +00:00
Lovepreet Singh 83dffb7746 Fix lint issues 2023-02-20 13:33:16 +00:00
Lovepreet Singh 1d1d5456e3 Removed code that checks for version less than 1.3.2 as it was not working. Defaulting to zstd without long as that is what is always happening currently. 2023-02-20 13:27:45 +00:00
Lovepreet Singh 9e06993ffc Hotfix zstd version change only 2023-02-20 13:08:22 +00:00
Lovepreet Singh 3630ea6eed Fix bug with version shortcircuiting because of version being null 2023-02-20 12:51:49 +00:00
Lovepreet Singh c2d3089f83 bump version 2023-02-20 10:32:34 +00:00
Lovepreet Singh 652109d32c Test passing quiet as argument 2023-02-20 10:30:41 +00:00
Lovepreet Singh f2aa430c9d Add debug statements 2023-02-20 10:05:34 +00:00
6 changed files with 159 additions and 17 deletions
+4 -1
View File
@@ -114,4 +114,7 @@
- Fix issue with symlink restoration on windows.
### 3.1.3
- Fix to prevent from setting MYSYS environement variable globally [#1329](https://github.com/actions/toolkit/pull/1329).
- Fix to prevent from setting MYSYS environement variable globally [#1329](https://github.com/actions/toolkit/pull/1329).
### 3.1.4
- Fix zstd not being used due to `zstd --version` output change in zstd 1.5.4 release. See [#1353](https://github.com/actions/toolkit/pull/1353).
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@actions/cache",
"version": "3.1.3",
"version": "3.1.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@actions/cache",
"version": "3.1.3",
"version": "3.1.4",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@actions/cache",
"version": "3.1.3",
"version": "3.1.4",
"preview": true,
"description": "Actions cache lib",
"keywords": [
+11 -11
View File
@@ -71,11 +71,15 @@ export async function unlinkFile(filePath: fs.PathLike): Promise<void> {
return util.promisify(fs.unlink)(filePath)
}
async function getVersion(app: string): Promise<string> {
core.debug(`Checking ${app} --version`)
async function getVersion(
app: string,
additionalArgs: string[] = []
): Promise<string> {
let versionOutput = ''
additionalArgs.push('--version')
core.debug(`Checking ${app} ${additionalArgs.join(' ')}`)
try {
await exec.exec(`${app} --version`, [], {
await exec.exec(`${app}`, additionalArgs, {
ignoreReturnCode: true,
silent: true,
listeners: {
@@ -94,18 +98,14 @@ async function getVersion(app: string): Promise<string> {
// Use zstandard if possible to maximize cache performance
export async function getCompressionMethod(): Promise<CompressionMethod> {
const versionOutput = await getVersion('zstd')
const versionOutput = await getVersion('zstd', ['--quiet'])
const version = semver.clean(versionOutput)
core.debug(`zstd version: ${version}`)
if (!versionOutput.toLowerCase().includes('zstd command line interface')) {
// zstd is not installed
if (versionOutput === '') {
return CompressionMethod.Gzip
} else if (!version || semver.lt(version, 'v1.3.2')) {
// zstd is installed but using a version earlier than v1.3.2
// v1.3.2 is required to use the `--long` options in zstd
return CompressionMethod.ZstdWithoutLong
} else {
return CompressionMethod.Zstd
return CompressionMethod.ZstdWithoutLong
}
}
+127 -2
View File
@@ -28,7 +28,7 @@ describe('proxy', () => {
_clearVars()
})
afterEach(() => {})
afterEach(() => { })
afterAll(async () => {
_clearVars()
@@ -196,7 +196,7 @@ describe('proxy', () => {
expect(_proxyConnects).toEqual(['httpbin.org:80'])
})
it('HttoClient does basic http get request when bypass proxy', async () => {
it('HttpClient does basic http get request when bypass proxy', async () => {
process.env['http_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
@@ -258,8 +258,133 @@ describe('proxy', () => {
expect(agent.proxyOptions.port).toBe('8080')
expect(agent.proxyOptions.proxyAuth).toBe('user:password')
})
// unit tests from actions/runner
it('should prefer lowercase over uppercase ENVs', async () => {
process.env['http_proxy'] = 'http://127.0.0.1:7777'
process.env['HTTP_PROXY'] = 'http://127.0.0.1:8888'
process.env['https_proxy'] = 'https://127.0.0.1:8888'
process.env['HTTPS_PROXY'] = 'https://127.0.0.1:7777'
const httpClient = new httpm.HttpClient()
const httpAgent: any = httpClient.getAgent('http://some-url')
expect(httpAgent.proxyOptions.host).toBe('127.0.0.1')
expect(httpAgent.proxyOptions.port).toBe('7777')
const httpsAgent: any = httpClient.getAgent('https://some-url')
expect(httpsAgent.proxyOptions.host).toBe('127.0.0.1')
expect(httpsAgent.proxyOptions.port).toBe('8888')
})
it('should not set proxy on invalid input', async () => {
process.env['http_proxy'] = '127.0.0.1:7777'
process.env['https_proxy'] = '127.0.0.1:8888'
const httpClient = new httpm.HttpClient()
// Different from actions/runner, we throw an error here while the runner proceeds without a proxy
expect(() => httpClient.getAgent('http://some-url')).toThrow()
expect(() => httpClient.getAgent('https://some-url')).toThrow()
})
it('should bypass no_proxy hosts', async () => {
process.env['http_proxy'] = '127.0.0.1:7777'
process.env['https_proxy'] = '127.0.0.1:8888'
process.env['no_proxy'] = 'github.com, .google.com, example.com:444, 192.168.0.123:123, 192.168.1.123'
expect(pm.checkBypass(new URL('https://actions.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://ggithub.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://github.comm'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://google.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('https://example.com'))).toBeFalsy();
expect(pm.checkBypass(new URL('http://example.com:333'))).toBeFalsy();
expect(pm.checkBypass(new URL('http://192.168.0.123:123'))).toBeTruthy(); // DIFF
expect(pm.checkBypass(new URL('http://192.168.1.123/home'))).toBeTruthy(); // DIFF
expect(pm.checkBypass(new URL('https://github.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://GITHUB.COM'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://github.com/owner/repo'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://actions.github.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://mails.google.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://MAILS.GOOGLE.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://mails.v2.google.com'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://mails.v2.v3.google.com/inbox'))).toBeTruthy()
expect(pm.checkBypass(new URL('https://example.com:444'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://example.com:444'))).toBeTruthy()
expect(pm.checkBypass(new URL('http://example.COM:444'))).toBeTruthy()
})
})
it('should not use http_proxy for https requests if https_proxy is not set', async () => {
process.env['http_proxy'] = 'http://127.0.0.1:7777/'
expect(pm.getProxyUrl(new URL('http://example.com'))).toBeDefined()
expect(pm.getProxyUrl(new URL('https://example.com'))).toBeUndefined()
})
it('HttpClient does basic https get request when bypass proxy', async () => {
process.env['https_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'https://httpbin.org/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toHaveLength(0)
})
it('HttpClient bypasses proxy for loopback addresses (localhost, ::1, 127.*)', async () => {
// setup a server listening on localhost:8091
var server = http.createServer(function (request, response) {
response.writeHead(200);
request.pipe(response);
});
await server.listen(8091)
try {
process.env['http_proxy'] = _proxyUrl
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'http://localhost:8091'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
expect(body).toEqual('');
// proxy at _proxyUrl was ignored
expect(_proxyConnects).toEqual([])
}
finally {
await server.close()
}
})
it('HttpClient does basic https get request when bypass proxy', async () => {
process.env['https_proxy'] = _proxyUrl
process.env['no_proxy'] = 'httpbin.org'
const httpClient = new httpm.HttpClient()
const res: httpm.HttpClientResponse = await httpClient.get(
'https://httpbin.org/get'
)
expect(res.message.statusCode).toBe(200)
const body: string = await res.readBody()
const obj = JSON.parse(body)
expect(obj.url).toBe('https://httpbin.org/get')
expect(_proxyConnects).toHaveLength(0)
})
it('should not use https_proxy for http requests if http_proxy is not set', async () => {
process.env['https_proxy'] = 'https://127.0.0.1:7777/'
expect(pm.getProxyUrl(new URL('http://example.com'))).toBeUndefined()
expect(pm.getProxyUrl(new URL('https://example.com'))).toBeDefined()
})
// it('should detect loopback ip addresses', async () => {
// process.env['http_proxy'] = 'http://nonlocal.faraway.com:7777/'
// expect(pm.getProxyUrl(new URL('http://localhost'))).toBeUndefined()
// })
function _clearVars(): void {
delete process.env.http_proxy
delete process.env.HTTP_PROXY
+14
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,12 @@ export function checkBypass(reqUrl: URL): boolean {
return false
}
function isLoopbackAddress(host: string): boolean {
const hostUpper = host.toUpperCase()
return (
hostUpper === 'LOCALHOST' ||
hostUpper.startsWith('127.') ||
hostUpper.startsWith('::1')
)
}