Skip to content

Commit

Permalink
test: fix self signed test
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoaldamav committed Jan 18, 2024
1 parent 8737e87 commit 550c2e0
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions network/proxy-agent/proxy-agent.strict-ssl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
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/,
);
});
});

0 comments on commit 550c2e0

Please sign in to comment.