From b8c70ba6cf405fa124f28008fa55d616617520d8 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 7 Jul 2024 09:28:53 -0700 Subject: [PATCH] Deflake node-tls-connect test --- test/js/node/tls/node-tls-connect.test.ts | 34 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/test/js/node/tls/node-tls-connect.test.ts b/test/js/node/tls/node-tls-connect.test.ts index 86120a41d3..68416e10e6 100644 --- a/test/js/node/tls/node-tls-connect.test.ts +++ b/test/js/node/tls/node-tls-connect.test.ts @@ -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);