-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
550c2e0
commit 451e81f
Showing
1 changed file
with
35 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
import fetch from "node-fetch"; | ||
import { getProxyAgent } from "./proxy-agent"; | ||
import Proxy from "proxy"; | ||
import fetch from 'node-fetch' | ||
import { getProxyAgent } from './proxy-agent' | ||
import Proxy from 'proxy' | ||
|
||
describe("untrusted certificate", () => { | ||
let proxy: Proxy; | ||
let proxyPort: number; | ||
beforeAll((done) => { | ||
// setup HTTP proxy server | ||
proxy = Proxy(); | ||
proxy.listen(() => { | ||
proxyPort = proxy.address().port; | ||
done(); | ||
}); | ||
}); | ||
afterAll((done) => { | ||
proxy.once("close", done); | ||
proxy.close(); | ||
}); | ||
it("should not throw an error if strictSsl is set to false", async () => { | ||
const url = "https://self-signed.badssl.com"; | ||
const agent: any = getProxyAgent(url, { | ||
httpsProxy: `http://127.0.0.1:${proxyPort}`, | ||
strictSsl: false, | ||
}); | ||
await fetch(url, { agent }); | ||
}); | ||
it("should throw an error if strictSsl is not set", async () => { | ||
const url = "https://self-signed.badssl.com"; | ||
const agent: any = getProxyAgent(url, { | ||
httpsProxy: `http://127.0.0.1:${proxyPort}`, | ||
strictSsl: true, | ||
}); | ||
await expect(fetch(url, { agent })).rejects.toThrow( | ||
/self[- ]signed certificate/, | ||
); | ||
}); | ||
}); | ||
describe('untrusted certificate', () => { | ||
let proxy: Proxy | ||
let proxyPort: number | ||
beforeAll((done) => { | ||
// setup HTTP proxy server | ||
proxy = Proxy(); | ||
proxy.listen(() => { | ||
proxyPort = proxy.address().port; | ||
done(); | ||
}); | ||
}); | ||
afterAll((done) => { | ||
proxy.once('close', done); | ||
proxy.close(); | ||
}); | ||
it('should not throw an error if strictSsl is set to false', async () => { | ||
const url = 'https://self-signed.badssl.com' | ||
const agent: any = getProxyAgent(url, { | ||
httpsProxy: `http://127.0.0.1:${proxyPort}`, | ||
strictSsl: false, | ||
}) | ||
await fetch(url, { agent }) | ||
}) | ||
it('should throw an error if strictSsl is not set', async () => { | ||
const url = 'https://self-signed.badssl.com' | ||
const agent: any = getProxyAgent(url, { | ||
httpsProxy: `http://127.0.0.1:${proxyPort}`, | ||
strictSsl: true, | ||
}) | ||
await expect(fetch(url, { agent })).rejects.toThrow(/self[- ]signed certificate/) | ||
}) | ||
}) |