diff options
author | Bartek Iwańczuk <biwanczuk@gmail.com> | 2024-06-13 21:41:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-13 22:41:26 +0200 |
commit | fb31eaa9ca59f6daaee0210d5cd206185c7041b9 (patch) | |
tree | 0c4ebc81ed7b44b683f31281accc47d451d09718 /tests | |
parent | 518e4d3b3a93838e0f2dbcc4d3b79f8f395db563 (diff) |
chore: upgrade to reqwest 0.12.4 and rustls 0.22 (#24056)
This commit updates Deno to use `reqwest` at 0.12.4
and `rustls` at 0.22. Other related crates were updated
as well to match versions accepted by `reqwest` and `rustls`.
Note: we are not using the latest available `rustls` yet,
but this upgrade was non-trivial already, so a bump to
0.23 for `rustls` will be done in a separate commit.
Closes #23370
---------
Signed-off-by: Ryan Dahl <ry@tinyclouds.org>
Signed-off-by: Bartek Iwańczuk <biwanczuk@gmail.com>
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
Co-authored-by: Divy Srivastava <dj.srivastava23@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/run_tests.rs | 19 | ||||
-rw-r--r-- | tests/node_compat/config.jsonc | 6 | ||||
-rw-r--r-- | tests/node_compat/runner/TODO.md | 6 | ||||
-rw-r--r-- | tests/node_compat/test/parallel/test-http-url.parse-auth-with-header-in-request.js | 59 | ||||
-rw-r--r-- | tests/node_compat/test/parallel/test-http-url.parse-auth.js | 55 | ||||
-rw-r--r-- | tests/node_compat/test/parallel/test-http-url.parse-basic.js | 65 | ||||
-rw-r--r-- | tests/node_compat/test/parallel/test-http-url.parse-path.js | 53 | ||||
-rw-r--r-- | tests/node_compat/test/parallel/test-http-url.parse-post.js | 61 | ||||
-rw-r--r-- | tests/node_compat/test/parallel/test-http-url.parse-search.js | 54 | ||||
-rw-r--r-- | tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out | 2 | ||||
-rw-r--r-- | tests/unit/fetch_test.ts | 8 | ||||
-rw-r--r-- | tests/unit/http_test.ts | 4 | ||||
-rw-r--r-- | tests/unit/serve_test.ts | 12 | ||||
-rw-r--r-- | tests/util/server/src/https.rs | 53 |
14 files changed, 53 insertions, 404 deletions
diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 0dadc0079..0d1804a28 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -5295,17 +5295,19 @@ async fn listen_tls_alpn() { let mut reader = &mut BufReader::new(Cursor::new(include_bytes!( "../testdata/tls/RootCA.crt" ))); - let certs = rustls_pemfile::certs(&mut reader).unwrap(); + let certs = rustls_pemfile::certs(&mut reader) + .collect::<Result<Vec<_>, _>>() + .unwrap(); let mut root_store = rustls::RootCertStore::empty(); - root_store.add_parsable_certificates(&certs); + root_store.add_parsable_certificates(certs); let mut cfg = rustls::ClientConfig::builder() - .with_safe_defaults() .with_root_certificates(root_store) .with_no_client_auth(); cfg.alpn_protocols.push(b"foobar".to_vec()); let cfg = Arc::new(cfg); - let hostname = rustls::ServerName::try_from("localhost").unwrap(); + let hostname = + rustls::pki_types::ServerName::try_from("localhost".to_string()).unwrap(); let tcp_stream = tokio::net::TcpStream::connect("localhost:4504") .await @@ -5347,17 +5349,18 @@ async fn listen_tls_alpn_fail() { let mut reader = &mut BufReader::new(Cursor::new(include_bytes!( "../testdata/tls/RootCA.crt" ))); - let certs = rustls_pemfile::certs(&mut reader).unwrap(); + let certs = rustls_pemfile::certs(&mut reader) + .collect::<Result<Vec<_>, _>>() + .unwrap(); let mut root_store = rustls::RootCertStore::empty(); - root_store.add_parsable_certificates(&certs); + root_store.add_parsable_certificates(certs); let mut cfg = rustls::ClientConfig::builder() - .with_safe_defaults() .with_root_certificates(root_store) .with_no_client_auth(); cfg.alpn_protocols.push(b"boofar".to_vec()); let cfg = Arc::new(cfg); - let hostname = rustls::ServerName::try_from("localhost").unwrap(); + let hostname = rustls::pki_types::ServerName::try_from("localhost").unwrap(); let tcp_stream = tokio::net::TcpStream::connect("localhost:4505") .await diff --git a/tests/node_compat/config.jsonc b/tests/node_compat/config.jsonc index 612c5558a..bc5580c1d 100644 --- a/tests/node_compat/config.jsonc +++ b/tests/node_compat/config.jsonc @@ -383,14 +383,8 @@ // "test-http-outgoing-message-inheritance.js", "test-http-outgoing-renderHeaders.js", "test-http-outgoing-settimeout.js", - "test-http-url.parse-auth-with-header-in-request.js", - "test-http-url.parse-auth.js", - "test-http-url.parse-basic.js", "test-http-url.parse-https.request.js", "test-http-url.parse-only-support-http-https-protocol.js", - "test-http-url.parse-path.js", - "test-http-url.parse-post.js", - "test-http-url.parse-search.js", "test-net-access-byteswritten.js", "test-net-better-error-messages-listen-path.js", "test-net-better-error-messages-path.js", diff --git a/tests/node_compat/runner/TODO.md b/tests/node_compat/runner/TODO.md index ebd6f192f..0d5bcc626 100644 --- a/tests/node_compat/runner/TODO.md +++ b/tests/node_compat/runner/TODO.md @@ -1316,6 +1316,12 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/co - [parallel/test-http-upgrade-reconsume-stream.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-upgrade-reconsume-stream.js) - [parallel/test-http-upgrade-server.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-upgrade-server.js) - [parallel/test-http-upgrade-server2.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-upgrade-server2.js) +- [parallel/test-http-url.parse-auth-with-header-in-request.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-url.parse-auth-with-header-in-request.js) +- [parallel/test-http-url.parse-auth.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-url.parse-auth.js) +- [parallel/test-http-url.parse-basic.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-url.parse-basic.js) +- [parallel/test-http-url.parse-path.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-url.parse-path.js) +- [parallel/test-http-url.parse-post.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-url.parse-post.js) +- [parallel/test-http-url.parse-search.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-url.parse-search.js) - [parallel/test-http-wget.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-wget.js) - [parallel/test-http-writable-true-after-close.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-writable-true-after-close.js) - [parallel/test-http-write-callbacks.js](https://github.com/nodejs/node/tree/v18.12.1/test/parallel/test-http-write-callbacks.js) diff --git a/tests/node_compat/test/parallel/test-http-url.parse-auth-with-header-in-request.js b/tests/node_compat/test/parallel/test-http-url.parse-auth-with-header-in-request.js deleted file mode 100644 index eaa63bab7..000000000 --- a/tests/node_compat/test/parallel/test-http-url.parse-auth-with-header-in-request.js +++ /dev/null @@ -1,59 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const assert = require('assert'); -const http = require('http'); -const url = require('url'); - -function check(request) { - // The correct authorization header is be passed - assert.strictEqual(request.headers.authorization, 'NoAuthForYOU'); -} - -const server = http.createServer(function(request, response) { - // Run the check function - check(request); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(0, function() { - const testURL = - url.parse(`http://asdf:qwer@localhost:${this.address().port}`); - // The test here is if you set a specific authorization header in the - // request we should not override that with basic auth - testURL.headers = { - Authorization: 'NoAuthForYOU' - }; - - // make the request - http.request(testURL).end(); -}); diff --git a/tests/node_compat/test/parallel/test-http-url.parse-auth.js b/tests/node_compat/test/parallel/test-http-url.parse-auth.js deleted file mode 100644 index 3bf3242c9..000000000 --- a/tests/node_compat/test/parallel/test-http-url.parse-auth.js +++ /dev/null @@ -1,55 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const assert = require('assert'); -const http = require('http'); -const url = require('url'); - -function check(request) { - // The correct authorization header is be passed - assert.strictEqual(request.headers.authorization, 'Basic dXNlcjpwYXNzOg=='); -} - -const server = http.createServer(function(request, response) { - // Run the check function - check(request); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(0, function() { - const port = this.address().port; - // username = "user", password = "pass:" - const testURL = url.parse(`http://user:pass%3A@localhost:${port}`); - - // make the request - http.request(testURL).end(); -}); diff --git a/tests/node_compat/test/parallel/test-http-url.parse-basic.js b/tests/node_compat/test/parallel/test-http-url.parse-basic.js deleted file mode 100644 index 7018cd410..000000000 --- a/tests/node_compat/test/parallel/test-http-url.parse-basic.js +++ /dev/null @@ -1,65 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const assert = require('assert'); -const http = require('http'); -const url = require('url'); - -let testURL; - -// Make sure the basics work -function check(request) { - // Default method should still be 'GET' - assert.strictEqual(request.method, 'GET'); - // There are no URL params, so you should not see any - assert.strictEqual(request.url, '/'); - // The host header should use the url.parse.hostname - assert.strictEqual(request.headers.host, - `${testURL.hostname}:${testURL.port}`); -} - -const server = http.createServer(function(request, response) { - // Run the check function - check(request); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(0, function() { - testURL = url.parse(`http://localhost:${this.address().port}`); - - // make the request - const clientRequest = http.request(testURL); - // Since there is a little magic with the agent - // make sure that an http request uses the http.Agent - assert.ok(clientRequest.agent instanceof http.Agent); - clientRequest.end(); -}); diff --git a/tests/node_compat/test/parallel/test-http-url.parse-path.js b/tests/node_compat/test/parallel/test-http-url.parse-path.js deleted file mode 100644 index f0c07887f..000000000 --- a/tests/node_compat/test/parallel/test-http-url.parse-path.js +++ /dev/null @@ -1,53 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const assert = require('assert'); -const http = require('http'); -const url = require('url'); - -function check(request) { - // A path should come over - assert.strictEqual(request.url, '/asdf'); -} - -const server = http.createServer(function(request, response) { - // Run the check function - check(request); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(0, function() { - const testURL = url.parse(`http://localhost:${this.address().port}/asdf`); - - // make the request - http.request(testURL).end(); -}); diff --git a/tests/node_compat/test/parallel/test-http-url.parse-post.js b/tests/node_compat/test/parallel/test-http-url.parse-post.js deleted file mode 100644 index c59114603..000000000 --- a/tests/node_compat/test/parallel/test-http-url.parse-post.js +++ /dev/null @@ -1,61 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const assert = require('assert'); -const http = require('http'); -const url = require('url'); - -let testURL; - -function check(request) { - // url.parse should not mess with the method - assert.strictEqual(request.method, 'POST'); - // Everything else should be right - assert.strictEqual(request.url, '/asdf?qwer=zxcv'); - // The host header should use the url.parse.hostname - assert.strictEqual(request.headers.host, - `${testURL.hostname}:${testURL.port}`); -} - -const server = http.createServer(function(request, response) { - // Run the check function - check(request); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(0, function() { - testURL = url.parse(`http://localhost:${this.address().port}/asdf?qwer=zxcv`); - testURL.method = 'POST'; - - // make the request - http.request(testURL).end(); -}); diff --git a/tests/node_compat/test/parallel/test-http-url.parse-search.js b/tests/node_compat/test/parallel/test-http-url.parse-search.js deleted file mode 100644 index 872533161..000000000 --- a/tests/node_compat/test/parallel/test-http-url.parse-search.js +++ /dev/null @@ -1,54 +0,0 @@ -// deno-fmt-ignore-file -// deno-lint-ignore-file - -// Copyright Joyent and Node contributors. All rights reserved. MIT license. -// Taken from Node 18.12.1 -// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually. - -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - -'use strict'; -require('../common'); -const assert = require('assert'); -const http = require('http'); -const url = require('url'); - -function check(request) { - // A path should come over with params - assert.strictEqual(request.url, '/asdf?qwer=zxcv'); -} - -const server = http.createServer(function(request, response) { - // Run the check function - check(request); - response.writeHead(200, {}); - response.end('ok'); - server.close(); -}); - -server.listen(0, function() { - const port = this.address().port; - const testURL = url.parse(`http://localhost:${port}/asdf?qwer=zxcv`); - - // make the request - http.request(testURL).end(); -}); diff --git a/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out b/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out index 81e490c1c..3067fffae 100644 --- a/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out +++ b/tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out @@ -1,3 +1,3 @@ DANGER: TLS certificate validation is disabled for: deno.land -error: Import 'https://localhost:5545/subdir/mod2.ts' failed: error sending request for url (https://localhost:5545/subdir/mod2.ts): error trying to connect: invalid peer certificate: UnknownIssuer +error: Import 'https://localhost:5545/subdir/mod2.ts' failed: error sending request for url (https://localhost:5545/subdir/mod2.ts) at file:///[WILDCARD]/cafile_url_imports.ts:[WILDCARD] diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index 4176f39ac..b549be9a4 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -67,7 +67,7 @@ Deno.test( await fetch(`http://localhost:${port}`); }, TypeError, - "error trying to connect", + "error sending request for url", ); }, ); @@ -80,7 +80,7 @@ Deno.test( await fetch("http://nil/"); }, TypeError, - "error trying to connect", + "error sending request for url", ); }, ); @@ -1824,7 +1824,7 @@ Deno.test( await fetch(`http://${addr}/`); }, TypeError, - "invalid content-length parsed", + "error sending request", ); listener.close(); @@ -1880,7 +1880,7 @@ Deno.test( await response.arrayBuffer(); }, Error, - "end of file before message length reached", + "error decoding response body", ); listener.close(); diff --git a/tests/unit/http_test.ts b/tests/unit/http_test.ts index 6968c6f88..eddb1520b 100644 --- a/tests/unit/http_test.ts +++ b/tests/unit/http_test.ts @@ -2574,7 +2574,7 @@ for (const compression of [true, false]) { assertEquals(result.value, new Uint8Array([65])); const err = await assertRejects(() => reader.read()); assert(err instanceof TypeError); - assert(err.message.includes("unexpected EOF")); + assert(err.message.includes("error decoding response body")); const httpConn = await server; httpConn.close(); @@ -2610,7 +2610,7 @@ for (const compression of [true, false]) { assertEquals(result.value, new Uint8Array([65])); const err = await assertRejects(() => reader.read()); assert(err instanceof TypeError); - assert(err.message.includes("unexpected internal error encountered")); + assert(err.message.includes("error decoding response body")); const httpConn = await server; httpConn.close(); diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index ff77578e6..363667066 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -3522,11 +3522,7 @@ Deno.test( fail(); } catch (clientError) { assert(clientError instanceof TypeError); - assert( - clientError.message.endsWith( - "connection closed before message completed", - ), - ); + assert(clientError.message.includes("error sending request for url")); } finally { ac.abort(); await server.finished; @@ -3574,11 +3570,7 @@ Deno.test({ fail(); } catch (clientError) { assert(clientError instanceof TypeError); - assert( - clientError.message.endsWith( - "connection closed before message completed", - ), - ); + assert(clientError.message.includes("error sending request for url")); } finally { ac.abort(); await server.finished; diff --git a/tests/util/server/src/https.rs b/tests/util/server/src/https.rs index 8a2524dca..617fd5cae 100644 --- a/tests/util/server/src/https.rs +++ b/tests/util/server/src/https.rs @@ -2,9 +2,9 @@ use anyhow::anyhow; use futures::Stream; use futures::StreamExt; -use rustls::Certificate; -use rustls::PrivateKey; use rustls_tokio_stream::rustls; +use rustls_tokio_stream::rustls::pki_types::CertificateDer; +use rustls_tokio_stream::rustls::pki_types::PrivateKeyDer; use rustls_tokio_stream::TlsStream; use std::io; use std::num::NonZeroUsize; @@ -68,30 +68,30 @@ pub fn get_tls_config( let key_file = std::fs::File::open(key_path)?; let ca_file = std::fs::File::open(ca_path)?; - let certs: Vec<Certificate> = { + let certs_result: Result<Vec<CertificateDer<'static>>, io::Error> = { let mut cert_reader = io::BufReader::new(cert_file); - rustls_pemfile::certs(&mut cert_reader) - .unwrap() - .into_iter() - .map(Certificate) - .collect() + rustls_pemfile::certs(&mut cert_reader).collect() }; + let certs = certs_result?; let mut ca_cert_reader = io::BufReader::new(ca_file); let ca_cert = rustls_pemfile::certs(&mut ca_cert_reader) - .expect("Cannot load CA certificate") - .remove(0); + .collect::<Vec<_>>() + .remove(0)?; let mut key_reader = io::BufReader::new(key_file); let key = { - let pkcs8_key = rustls_pemfile::pkcs8_private_keys(&mut key_reader) - .expect("Cannot load key file"); - let rsa_key = rustls_pemfile::rsa_private_keys(&mut key_reader) - .expect("Cannot load key file"); - if !pkcs8_key.is_empty() { - Some(pkcs8_key[0].clone()) - } else if !rsa_key.is_empty() { - Some(rsa_key[0].clone()) + let pkcs8_keys = rustls_pemfile::pkcs8_private_keys(&mut key_reader) + .collect::<Result<Vec<_>, _>>()?; + let rsa_keys = rustls_pemfile::rsa_private_keys(&mut key_reader) + .collect::<Result<Vec<_>, _>>()?; + + if !pkcs8_keys.is_empty() { + let key = pkcs8_keys[0].clone_key(); + Some(PrivateKeyDer::from(key)) + } else if !rsa_keys.is_empty() { + let key = rsa_keys[0].clone_key(); + Some(PrivateKeyDer::from(key)) } else { None } @@ -100,18 +100,19 @@ pub fn get_tls_config( match key { Some(key) => { let mut root_cert_store = rustls::RootCertStore::empty(); - root_cert_store.add(&rustls::Certificate(ca_cert)).unwrap(); + root_cert_store.add(ca_cert).unwrap(); // Allow (but do not require) client authentication. + let client_verifier = rustls::server::WebPkiClientVerifier::builder( + Arc::new(root_cert_store), + ) + .allow_unauthenticated() + .build() + .unwrap(); let mut config = rustls::ServerConfig::builder() - .with_safe_defaults() - .with_client_cert_verifier(Arc::new( - rustls::server::AllowAnyAnonymousOrAuthenticatedClient::new( - root_cert_store, - ), - )) - .with_single_cert(certs, PrivateKey(key)) + .with_client_cert_verifier(client_verifier) + .with_single_cert(certs, key) .map_err(|e| anyhow!("Error setting cert: {:?}", e)) .unwrap(); |