From 3a243c827238b93c3f09a38e3b5e90e2ccfc15a1 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Mon, 19 Feb 2024 01:26:16 +1100 Subject: [PATCH] BREAKING: add `Deno.CreateHttpClientOptions.{cert,key}` (#22280) This change deprecates `Deno.CreateHttpClientOptions.{certChain,privateKey}` in favour of `Deno.CreateHttpClientOptions.{cert,key}`. Closes #22278 Co-authored-by: Matt Mastracci --- cli/tsc/dts/lib.deno.unstable.d.ts | 8 ++++---- ext/fetch/lib.rs | 10 +++++----- tests/unit/fetch_test.ts | 16 ++++++++-------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cli/tsc/dts/lib.deno.unstable.d.ts b/cli/tsc/dts/lib.deno.unstable.d.ts index d50b3e9fc6..b3ee0c4ee0 100644 --- a/cli/tsc/dts/lib.deno.unstable.d.ts +++ b/cli/tsc/dts/lib.deno.unstable.d.ts @@ -896,10 +896,10 @@ declare namespace Deno { caCerts?: string[]; /** A HTTP proxy to use for new connections. */ proxy?: Proxy; - /** PEM formatted client certificate chain. */ - certChain?: string; - /** PEM formatted (RSA or PKCS8) private key of client certificate. */ - privateKey?: string; + /** Server private key in PEM format. */ + cert?: string; + /** Cert chain in PEM format. */ + key?: string; /** Sets the maximum numer of idle connections per host allowed in the pool. */ poolMaxIdlePerHost?: number; /** Set an optional timeout for idle sockets being kept-alive. diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index b5ef3e62c3..02ce34810d 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -794,8 +794,8 @@ impl HttpClientResource { pub struct CreateHttpClientArgs { ca_certs: Vec, proxy: Option, - cert_chain: Option, - private_key: Option, + cert: Option, + key: Option, pool_max_idle_per_host: Option, pool_idle_timeout: Option, #[serde(default = "default_true")] @@ -826,12 +826,12 @@ where } let client_cert_chain_and_key = { - if args.cert_chain.is_some() || args.private_key.is_some() { + if args.cert.is_some() || args.key.is_some() { let cert_chain = args - .cert_chain + .cert .ok_or_else(|| type_error("No certificate chain provided"))?; let private_key = args - .private_key + .key .ok_or_else(|| type_error("No private key provided"))?; Some((cert_chain, private_key)) diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index dc596718f1..c33503bdfc 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -1333,8 +1333,8 @@ Deno.test( async function fetchClientCertWrongPrivateKey(): Promise { await assertRejects(async () => { const client = Deno.createHttpClient({ - certChain: "bad data", - privateKey: await Deno.readTextFile( + cert: "bad data", + key: await Deno.readTextFile( "tests/testdata/tls/localhost.key", ), }); @@ -1350,10 +1350,10 @@ Deno.test( async function fetchClientCertBadPrivateKey(): Promise { await assertRejects(async () => { const client = Deno.createHttpClient({ - certChain: await Deno.readTextFile( + cert: await Deno.readTextFile( "tests/testdata/tls/localhost.crt", ), - privateKey: "bad data", + key: "bad data", }); await fetch("https://localhost:5552/assets/fixture.json", { client, @@ -1367,10 +1367,10 @@ Deno.test( async function fetchClientCertNotPrivateKey(): Promise { await assertRejects(async () => { const client = Deno.createHttpClient({ - certChain: await Deno.readTextFile( + cert: await Deno.readTextFile( "tests/testdata/tls/localhost.crt", ), - privateKey: "", + key: "", }); await fetch("https://localhost:5552/assets/fixture.json", { client, @@ -1387,10 +1387,10 @@ Deno.test( const data = "Hello World"; const caCert = await Deno.readTextFile("tests/testdata/tls/RootCA.crt"); const client = Deno.createHttpClient({ - certChain: await Deno.readTextFile( + cert: await Deno.readTextFile( "tests/testdata/tls/localhost.crt", ), - privateKey: await Deno.readTextFile( + key: await Deno.readTextFile( "tests/testdata/tls/localhost.key", ), caCerts: [caCert],