Deflake node-tls-connect test

This commit is contained in:
Jarred Sumner
2024-07-07 09:28:53 -07:00
parent cbcf9506d9
commit b8c70ba6cf

View File

@@ -167,6 +167,23 @@ it("should have peer certificate", async () => {
});
it("getCipher, getProtocol, getEphemeralKeyInfo, getSharedSigalgs, getSession, exportKeyingMaterial and isSessionReused should work", async () => {
const allowedCipherObjects = [
{
name: "TLS_AES_128_GCM_SHA256",
standardName: "TLS_AES_128_GCM_SHA256",
version: "TLSv1/SSLv3",
},
{
name: "TLS_AES_256_GCM_SHA384",
standardName: "TLS_AES_256_GCM_SHA384",
version: "TLSv1/SSLv3",
},
{
name: "TLS_CHACHA20_POLY1305_SHA256",
standardName: "TLS_CHACHA20_POLY1305_SHA256",
version: "TLSv1/SSLv3",
},
];
const socket = (await new Promise((resolve, reject) => {
connect({
ALPNProtocols: ["http/1.1"],
@@ -181,11 +198,18 @@ it("getCipher, getProtocol, getEphemeralKeyInfo, getSharedSigalgs, getSession, e
})) as TLSSocket;
try {
expect(socket.getCipher()).toMatchObject({
name: "TLS_AES_128_GCM_SHA256",
standardName: "TLS_AES_128_GCM_SHA256",
version: "TLSv1/SSLv3",
});
const cipher = socket.getCipher();
let hadMatch = false;
for (const allowedCipher of allowedCipherObjects) {
if (cipher.name === allowedCipher.name) {
expect(cipher).toMatchObject(allowedCipher);
hadMatch = true;
break;
}
}
if (!hadMatch) {
throw new Error(`Unexpected cipher ${cipher.name}`);
}
expect(socket.getProtocol()).toBe("TLSv1.3");
expect(typeof socket.getEphemeralKeyInfo()).toBe("object");
expect(socket.getSharedSigalgs()).toBeInstanceOf(Array);