-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '7.11' into backport/7.11/pr-87898
- Loading branch information
Showing
26 changed files
with
386 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
x-pack/plugins/actions/server/builtin_action_types/lib/get_proxy_agent.test.ts
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
x-pack/plugins/actions/server/builtin_action_types/lib/get_proxy_agent.ts
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/actions/server/builtin_action_types/lib/get_proxy_agents.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import HttpProxyAgent from 'http-proxy-agent'; | ||
import { HttpsProxyAgent } from 'https-proxy-agent'; | ||
import { Logger } from '../../../../../../src/core/server'; | ||
import { getProxyAgents } from './get_proxy_agents'; | ||
import { loggingSystemMock } from '../../../../../../src/core/server/mocks'; | ||
const logger = loggingSystemMock.create().get() as jest.Mocked<Logger>; | ||
|
||
describe('getProxyAgents', () => { | ||
test('get agents for valid proxy URL', () => { | ||
const { httpAgent, httpsAgent } = getProxyAgents( | ||
{ proxyUrl: 'https://someproxyhost', proxyRejectUnauthorizedCertificates: false }, | ||
logger | ||
); | ||
expect(httpAgent instanceof HttpProxyAgent).toBeTruthy(); | ||
expect(httpsAgent instanceof HttpsProxyAgent).toBeTruthy(); | ||
}); | ||
|
||
test('return undefined agents for invalid proxy URL', () => { | ||
const { httpAgent, httpsAgent } = getProxyAgents( | ||
{ proxyUrl: ':nope: not a valid URL', proxyRejectUnauthorizedCertificates: false }, | ||
logger | ||
); | ||
expect(httpAgent).toBe(undefined); | ||
expect(httpsAgent).toBe(undefined); | ||
}); | ||
|
||
test('return undefined agents for null proxy options', () => { | ||
const { httpAgent, httpsAgent } = getProxyAgents(null, logger); | ||
expect(httpAgent).toBe(undefined); | ||
expect(httpsAgent).toBe(undefined); | ||
}); | ||
|
||
test('return undefined agents for undefined proxy options', () => { | ||
const { httpAgent, httpsAgent } = getProxyAgents(undefined, logger); | ||
expect(httpAgent).toBe(undefined); | ||
expect(httpsAgent).toBe(undefined); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
x-pack/plugins/actions/server/builtin_action_types/lib/get_proxy_agents.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Agent } from 'http'; | ||
import HttpProxyAgent from 'http-proxy-agent'; | ||
import { HttpsProxyAgent } from 'https-proxy-agent'; | ||
import { Logger } from '../../../../../../src/core/server'; | ||
import { ProxySettings } from '../../types'; | ||
|
||
interface GetProxyAgentsResponse { | ||
httpAgent: Agent | undefined; | ||
httpsAgent: Agent | undefined; | ||
} | ||
|
||
export function getProxyAgents( | ||
proxySettings: ProxySettings | undefined | null, | ||
logger: Logger | ||
): GetProxyAgentsResponse { | ||
const undefinedResponse = { | ||
httpAgent: undefined, | ||
httpsAgent: undefined, | ||
}; | ||
|
||
if (!proxySettings) { | ||
return undefinedResponse; | ||
} | ||
|
||
logger.debug(`Creating proxy agents for proxy: ${proxySettings.proxyUrl}`); | ||
let proxyUrl: URL; | ||
try { | ||
proxyUrl = new URL(proxySettings.proxyUrl); | ||
} catch (err) { | ||
logger.warn(`invalid proxy URL "${proxySettings.proxyUrl}" ignored`); | ||
return undefinedResponse; | ||
} | ||
|
||
const httpAgent = new HttpProxyAgent(proxySettings.proxyUrl); | ||
const httpsAgent = (new HttpsProxyAgent({ | ||
host: proxyUrl.hostname, | ||
port: Number(proxyUrl.port), | ||
protocol: proxyUrl.protocol, | ||
headers: proxySettings.proxyHeaders, | ||
// do not fail on invalid certs if value is false | ||
rejectUnauthorized: proxySettings.proxyRejectUnauthorizedCertificates, | ||
}) as unknown) as Agent; | ||
// vsCode wasn't convinced HttpsProxyAgent is an http.Agent, so we convinced it | ||
|
||
return { httpAgent, httpsAgent }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.