2021-07-24 05:38:25 +08:00
|
|
|
import { shouldEnableProxy } from "../../../src/node/proxy_agent"
|
2021-12-18 03:06:52 +08:00
|
|
|
import { mockLogger, useEnv } from "../../utils/helpers"
|
2021-07-24 05:38:25 +08:00
|
|
|
|
|
|
|
describe("shouldEnableProxy", () => {
|
2021-07-27 02:21:30 +08:00
|
|
|
const [setHTTPProxy, resetHTTPProxy] = useEnv("HTTP_PROXY")
|
|
|
|
const [setHTTPSProxy, resetHTTPSProxy] = useEnv("HTTPS_PROXY")
|
|
|
|
const [setNoProxy, resetNoProxy] = useEnv("NO_PROXY")
|
2021-07-24 05:38:25 +08:00
|
|
|
|
2021-12-18 03:06:52 +08:00
|
|
|
beforeAll(() => {
|
|
|
|
mockLogger()
|
|
|
|
})
|
|
|
|
|
2021-07-24 05:38:25 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules() // Most important - it clears the cache
|
2021-07-27 02:21:30 +08:00
|
|
|
resetHTTPProxy()
|
|
|
|
resetNoProxy()
|
|
|
|
resetHTTPSProxy()
|
2021-07-24 05:38:25 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
it("returns true when HTTP_PROXY is set", () => {
|
2021-07-27 02:21:30 +08:00
|
|
|
setHTTPProxy("http://proxy.example.com")
|
2021-07-24 05:38:25 +08:00
|
|
|
expect(shouldEnableProxy()).toBe(true)
|
|
|
|
})
|
|
|
|
it("returns true when HTTPS_PROXY is set", () => {
|
2021-07-27 02:21:30 +08:00
|
|
|
setHTTPSProxy("https://proxy.example.com")
|
2021-07-24 05:38:25 +08:00
|
|
|
expect(shouldEnableProxy()).toBe(true)
|
|
|
|
})
|
|
|
|
it("returns false when NO_PROXY is set", () => {
|
2021-07-27 02:21:30 +08:00
|
|
|
setNoProxy("*")
|
2021-07-24 05:38:25 +08:00
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
it("should return false when neither HTTP_PROXY nor HTTPS_PROXY is set", () => {
|
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
it("should return false when NO_PROXY is set to https://example.com", () => {
|
2021-07-27 02:21:30 +08:00
|
|
|
setNoProxy("https://example.com")
|
2021-07-24 05:38:25 +08:00
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
it("should return false when NO_PROXY is set to http://example.com", () => {
|
2021-07-27 02:21:30 +08:00
|
|
|
setNoProxy("http://example.com")
|
2021-07-24 05:38:25 +08:00
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
})
|