-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: configure certificates for secure proxy (#8704)
Fixes #7683 Signed-off-by: Jeff MAURY <[email protected]>
- Loading branch information
Showing
8 changed files
with
58 additions
and
27 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import type { HttpsProxyAgentOptions } from 'hpagent'; | |
import { HttpsProxyAgent } from 'hpagent'; | ||
import { beforeEach, expect, test, vi } from 'vitest'; | ||
|
||
import type { Certificates } from './certificates.js'; | ||
import type { Proxy } from './proxy.js'; | ||
import * as ProxyResolver from './proxy-resolver.js'; | ||
|
||
|
@@ -83,48 +84,52 @@ const Http = 'http'; | |
const HttpProxyUrl = `${Http}://proxy.url`; | ||
const HttpsProxyUrl = 'https://proxy.url'; | ||
|
||
const certificates: Certificates = { | ||
getAllCertificates: vi.fn(), | ||
} as unknown as Certificates; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test('getOptions return options w/o agent if proxy not enabled', () => { | ||
const proxy = createProxy(false); | ||
const options = ProxyResolver.getOptions(proxy, false); | ||
const options = ProxyResolver.getOptions(proxy, false, certificates); | ||
expect(options.agent).toBeUndefined(); | ||
}); | ||
|
||
test('getOptions return options w/ agent for https proxy', () => { | ||
const proxy = createProxy(true, HttpsProxyUrl, HttpProxyUrl); | ||
const options = ProxyResolver.getOptions(proxy, true); | ||
const options = ProxyResolver.getOptions(proxy, true, certificates); | ||
expect(options.agent).not.toBeUndefined(); | ||
expect((options.agent as any).https).toBeTruthy(); | ||
}); | ||
|
||
test('getOptions return options w/ https.Agent for https proxy', () => { | ||
const proxy = createProxy(true, undefined, HttpProxyUrl); | ||
const options = ProxyResolver.getOptions(proxy, false); | ||
const options = ProxyResolver.getOptions(proxy, false, certificates); | ||
expect(options.agent).not.toBeUndefined(); | ||
expect((options.agent as any).https).toBeFalsy(); | ||
}); | ||
|
||
test('patched http get calls original with the original parameters when proxy is not enabled', () => { | ||
const proxy = createProxy(false, HttpsProxyUrl, HttpProxyUrl); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy, certificates); | ||
patched.http.get(`${Http}://site.url`); | ||
expect(get).toBeCalledWith(`${Http}://site.url`); | ||
}); | ||
|
||
test('patched http get calls original method with the original parameters when proxy is enabled and socketPath is requested', () => { | ||
const proxy = createProxy(true, HttpsProxyUrl, HttpProxyUrl); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy, certificates); | ||
const socketOptions = { socketPath: '/var/socket/path' }; | ||
patched.http.get(socketOptions); | ||
expect(get).toBeCalledWith(socketOptions, undefined); | ||
}); | ||
|
||
test('patched http get when called with url and callback calls original with options and callback', () => { | ||
const proxy = createProxy(true, HttpsProxyUrl, HttpProxyUrl); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy, certificates); | ||
const colon = ':'; | ||
const url = `https://[fe80${colon}${colon}1802${colon}20ff${colon}fe8d${colon}d4ce]`; | ||
const callback = vi.fn(); | ||
|
@@ -145,7 +150,7 @@ test('patched http get when called with url and callback calls original with opt | |
|
||
test('patched http get translates username@password in url to auth option', () => { | ||
const proxy = createProxy(true, HttpsProxyUrl, HttpProxyUrl); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy, certificates); | ||
const url = 'https://usr:[email protected]'; | ||
const callback = vi.fn(); | ||
patched.http.get(url, callback); | ||
|
@@ -166,7 +171,7 @@ test('patched http get translates username@password in url to auth option', () = | |
|
||
test('patched http get works when url passed as protocol and hostname in options', () => { | ||
const proxy = createProxy(true, HttpsProxyUrl, HttpProxyUrl); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy); | ||
const patched = ProxyResolver.createHttpPatchedModules(proxy, certificates); | ||
const callback = vi.fn(); | ||
const options = { | ||
hostname: 'rest.url', | ||
|
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