diff --git a/ext/net/02_tls.js b/ext/net/02_tls.js index b77b92e263..0b775047f6 100644 --- a/ext/net/02_tls.js +++ b/ext/net/02_tls.js @@ -15,7 +15,6 @@ import { const { Number, ObjectDefineProperty, - ReflectHas, TypeError, } = primordials; @@ -134,10 +133,10 @@ class TlsListener extends Listener { * interfaces. */ function hasTlsKeyPairOptions(options) { - return (ReflectHas(options, "cert") || ReflectHas(options, "key") || - ReflectHas(options, "certFile") || - ReflectHas(options, "keyFile") || ReflectHas(options, "privateKey") || - ReflectHas(options, "certChain")); + return (options.cert !== undefined || options.key !== undefined || + options.certFile !== undefined || + options.keyFile !== undefined || options.privateKey !== undefined || + options.certChain !== undefined); } /** diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 32d05056a3..8978c4f7e0 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -2889,6 +2889,37 @@ Deno.test( }, ); +// Regression test for https://github.com/denoland/deno/issues/23537 +Deno.test( + { permissions: { read: true, net: true } }, + async function httpServerUndefinedCert() { + const ac = new AbortController(); + const { promise, resolve } = Promise.withResolvers(); + const hostname = "127.0.0.1"; + + const server = Deno.serve({ + handler: () => new Response("Hello World"), + hostname, + port: servePort, + signal: ac.signal, + onListen: onListen(resolve), + onError: createOnErrorCb(ac), + // Undefined should be equivalent to missing + cert: undefined, + key: undefined, + }); + + await promise; + const resp = await fetch(`http://localhost:${servePort}/`); + + const respBody = await resp.text(); + assertEquals("Hello World", respBody); + + ac.abort(); + await server.finished; + }, +); + Deno.test( { permissions: { read: true, net: true } }, async function httpServerWithTls() {