mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(ext/node): set socket.authorized to true for https request (#30641)
This PR sets true to `req.socket.authorized` when making https request from `node:https` module. This makes yarn classic's https client working (e.g. `yarn add cowsay`). --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
928f26db78
commit
6ee7d60ce1
3 changed files with 33 additions and 1 deletions
|
@ -538,6 +538,10 @@ class ClientRequest extends OutgoingMessage {
|
||||||
caCerts: caCerts,
|
caCerts: caCerts,
|
||||||
alpnProtocols: ["http/1.0", "http/1.1"],
|
alpnProtocols: ["http/1.0", "http/1.1"],
|
||||||
}, keyPair);
|
}, keyPair);
|
||||||
|
|
||||||
|
// Simulates "secure" event on TLSSocket
|
||||||
|
// This makes yarn v1's https client working
|
||||||
|
this.socket.authorized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._req = await op_node_http_request_with_conn(
|
this._req = await op_node_http_request_with_conn(
|
||||||
|
|
|
@ -74,6 +74,7 @@ util::unit_test_factory!(
|
||||||
fs_test,
|
fs_test,
|
||||||
fetch_test,
|
fetch_test,
|
||||||
http_test,
|
http_test,
|
||||||
|
https_test,
|
||||||
http_no_cert_flag_test,
|
http_no_cert_flag_test,
|
||||||
http2_test,
|
http2_test,
|
||||||
inspector_test,
|
inspector_test,
|
||||||
|
@ -119,7 +120,7 @@ fn node_unit_test(test: String) {
|
||||||
.arg("-A");
|
.arg("-A");
|
||||||
|
|
||||||
// Some tests require the root CA cert file to be loaded.
|
// Some tests require the root CA cert file to be loaded.
|
||||||
if test == "http2_test" || test == "http_test" {
|
if test == "http2_test" || test == "http_test" || test == "https_test" {
|
||||||
deno = deno.arg("--cert=./tests/testdata/tls/RootCA.pem");
|
deno = deno.arg("--cert=./tests/testdata/tls/RootCA.pem");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
27
tests/unit_node/https_test.ts
Normal file
27
tests/unit_node/https_test.ts
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||||
|
|
||||||
|
import https from "node:https";
|
||||||
|
import { assert } from "../unit/test_util.ts";
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name:
|
||||||
|
"request.socket.authorized is true when successfully requested to https server",
|
||||||
|
async fn() {
|
||||||
|
const server = Deno.serve({
|
||||||
|
port: 0,
|
||||||
|
cert: Deno.readTextFileSync("tests/testdata/tls/localhost.crt"),
|
||||||
|
key: Deno.readTextFileSync("tests/testdata/tls/localhost.key"),
|
||||||
|
onListen({ port }) {
|
||||||
|
const req = https.request(`https://localhost:${port}`, (res) => {
|
||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
assert((req.socket as any).authorized);
|
||||||
|
res.destroy();
|
||||||
|
server.shutdown();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}, () => {
|
||||||
|
return new Response("hi");
|
||||||
|
});
|
||||||
|
await server.finished;
|
||||||
|
},
|
||||||
|
});
|
Loading…
Add table
Add a link
Reference in a new issue