1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

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 <matthew@mastracci.com>
This commit is contained in:
Asher Gomez 2024-02-19 01:26:16 +11:00 committed by GitHub
parent 08071f9561
commit 3a243c8272
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 17 deletions

View file

@ -896,10 +896,10 @@ declare namespace Deno {
caCerts?: string[]; caCerts?: string[];
/** A HTTP proxy to use for new connections. */ /** A HTTP proxy to use for new connections. */
proxy?: Proxy; proxy?: Proxy;
/** PEM formatted client certificate chain. */ /** Server private key in PEM format. */
certChain?: string; cert?: string;
/** PEM formatted (RSA or PKCS8) private key of client certificate. */ /** Cert chain in PEM format. */
privateKey?: string; key?: string;
/** Sets the maximum numer of idle connections per host allowed in the pool. */ /** Sets the maximum numer of idle connections per host allowed in the pool. */
poolMaxIdlePerHost?: number; poolMaxIdlePerHost?: number;
/** Set an optional timeout for idle sockets being kept-alive. /** Set an optional timeout for idle sockets being kept-alive.

View file

@ -794,8 +794,8 @@ impl HttpClientResource {
pub struct CreateHttpClientArgs { pub struct CreateHttpClientArgs {
ca_certs: Vec<String>, ca_certs: Vec<String>,
proxy: Option<Proxy>, proxy: Option<Proxy>,
cert_chain: Option<String>, cert: Option<String>,
private_key: Option<String>, key: Option<String>,
pool_max_idle_per_host: Option<usize>, pool_max_idle_per_host: Option<usize>,
pool_idle_timeout: Option<serde_json::Value>, pool_idle_timeout: Option<serde_json::Value>,
#[serde(default = "default_true")] #[serde(default = "default_true")]
@ -826,12 +826,12 @@ where
} }
let client_cert_chain_and_key = { 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 let cert_chain = args
.cert_chain .cert
.ok_or_else(|| type_error("No certificate chain provided"))?; .ok_or_else(|| type_error("No certificate chain provided"))?;
let private_key = args let private_key = args
.private_key .key
.ok_or_else(|| type_error("No private key provided"))?; .ok_or_else(|| type_error("No private key provided"))?;
Some((cert_chain, private_key)) Some((cert_chain, private_key))

View file

@ -1333,8 +1333,8 @@ Deno.test(
async function fetchClientCertWrongPrivateKey(): Promise<void> { async function fetchClientCertWrongPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
const client = Deno.createHttpClient({ const client = Deno.createHttpClient({
certChain: "bad data", cert: "bad data",
privateKey: await Deno.readTextFile( key: await Deno.readTextFile(
"tests/testdata/tls/localhost.key", "tests/testdata/tls/localhost.key",
), ),
}); });
@ -1350,10 +1350,10 @@ Deno.test(
async function fetchClientCertBadPrivateKey(): Promise<void> { async function fetchClientCertBadPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
const client = Deno.createHttpClient({ const client = Deno.createHttpClient({
certChain: await Deno.readTextFile( cert: await Deno.readTextFile(
"tests/testdata/tls/localhost.crt", "tests/testdata/tls/localhost.crt",
), ),
privateKey: "bad data", key: "bad data",
}); });
await fetch("https://localhost:5552/assets/fixture.json", { await fetch("https://localhost:5552/assets/fixture.json", {
client, client,
@ -1367,10 +1367,10 @@ Deno.test(
async function fetchClientCertNotPrivateKey(): Promise<void> { async function fetchClientCertNotPrivateKey(): Promise<void> {
await assertRejects(async () => { await assertRejects(async () => {
const client = Deno.createHttpClient({ const client = Deno.createHttpClient({
certChain: await Deno.readTextFile( cert: await Deno.readTextFile(
"tests/testdata/tls/localhost.crt", "tests/testdata/tls/localhost.crt",
), ),
privateKey: "", key: "",
}); });
await fetch("https://localhost:5552/assets/fixture.json", { await fetch("https://localhost:5552/assets/fixture.json", {
client, client,
@ -1387,10 +1387,10 @@ Deno.test(
const data = "Hello World"; const data = "Hello World";
const caCert = await Deno.readTextFile("tests/testdata/tls/RootCA.crt"); const caCert = await Deno.readTextFile("tests/testdata/tls/RootCA.crt");
const client = Deno.createHttpClient({ const client = Deno.createHttpClient({
certChain: await Deno.readTextFile( cert: await Deno.readTextFile(
"tests/testdata/tls/localhost.crt", "tests/testdata/tls/localhost.crt",
), ),
privateKey: await Deno.readTextFile( key: await Deno.readTextFile(
"tests/testdata/tls/localhost.key", "tests/testdata/tls/localhost.key",
), ),
caCerts: [caCert], caCerts: [caCert],