summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/run_tests.rs19
-rw-r--r--tests/node_compat/config.jsonc6
-rw-r--r--tests/node_compat/runner/TODO.md6
-rw-r--r--tests/node_compat/test/parallel/test-http-url.parse-auth-with-header-in-request.js59
-rw-r--r--tests/node_compat/test/parallel/test-http-url.parse-auth.js55
-rw-r--r--tests/node_compat/test/parallel/test-http-url.parse-basic.js65
-rw-r--r--tests/node_compat/test/parallel/test-http-url.parse-path.js53
-rw-r--r--tests/node_compat/test/parallel/test-http-url.parse-post.js61
-rw-r--r--tests/node_compat/test/parallel/test-http-url.parse-search.js54
-rw-r--r--tests/specs/cert/localhost_unsafe_ssl/localhost_unsafe_ssl.ts.out2
-rw-r--r--tests/unit/fetch_test.ts8
-rw-r--r--tests/unit/http_test.ts4
-rw-r--r--tests/unit/serve_test.ts12
-rw-r--r--tests/util/server/src/https.rs53
14 files changed, 404 insertions, 53 deletions
diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs
index b8263be29..5bd0de60c 100644
--- a/tests/integration/run_tests.rs
+++ b/tests/integration/run_tests.rs
@@ -5303,19 +5303,17 @@ 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)
- .collect::<Result<Vec<_>, _>>()
- .unwrap();
+ let certs = rustls_pemfile::certs(&mut reader).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::pki_types::ServerName::try_from("localhost".to_string()).unwrap();
+ let hostname = rustls::ServerName::try_from("localhost").unwrap();
let tcp_stream = tokio::net::TcpStream::connect("localhost:4504")
.await
@@ -5357,18 +5355,17 @@ 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)
- .collect::<Result<Vec<_>, _>>()
- .unwrap();
+ let certs = rustls_pemfile::certs(&mut reader).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::pki_types::ServerName::try_from("localhost").unwrap();
+ let hostname = rustls::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 6a61c4e63..0a661c0a9 100644
--- a/tests/node_compat/config.jsonc
+++ b/tests/node_compat/config.jsonc
@@ -392,8 +392,14 @@
// "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 4f397cc21..d5dd2fc7b 100644
--- a/tests/node_compat/runner/TODO.md
+++ b/tests/node_compat/runner/TODO.md
@@ -1308,12 +1308,6 @@ 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
new file mode 100644
index 000000000..eaa63bab7
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-http-url.parse-auth-with-header-in-request.js
@@ -0,0 +1,59 @@
+// 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
new file mode 100644
index 000000000..3bf3242c9
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-http-url.parse-auth.js
@@ -0,0 +1,55 @@
+// 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
new file mode 100644
index 000000000..7018cd410
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-http-url.parse-basic.js
@@ -0,0 +1,65 @@
+// 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
new file mode 100644
index 000000000..f0c07887f
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-http-url.parse-path.js
@@ -0,0 +1,53 @@
+// 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
new file mode 100644
index 000000000..c59114603
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-http-url.parse-post.js
@@ -0,0 +1,61 @@
+// 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
new file mode 100644
index 000000000..872533161
--- /dev/null
+++ b/tests/node_compat/test/parallel/test-http-url.parse-search.js
@@ -0,0 +1,54 @@
+// 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 3067fffae..81e490c1c 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: 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
at file:///[WILDCARD]/cafile_url_imports.ts:[WILDCARD]
diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts
index b549be9a4..4176f39ac 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 sending request for url",
+ "error trying to connect",
);
},
);
@@ -80,7 +80,7 @@ Deno.test(
await fetch("http://nil/");
},
TypeError,
- "error sending request for url",
+ "error trying to connect",
);
},
);
@@ -1824,7 +1824,7 @@ Deno.test(
await fetch(`http://${addr}/`);
},
TypeError,
- "error sending request",
+ "invalid content-length parsed",
);
listener.close();
@@ -1880,7 +1880,7 @@ Deno.test(
await response.arrayBuffer();
},
Error,
- "error decoding response body",
+ "end of file before message length reached",
);
listener.close();
diff --git a/tests/unit/http_test.ts b/tests/unit/http_test.ts
index eddb1520b..6968c6f88 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("error decoding response body"));
+ assert(err.message.includes("unexpected EOF"));
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("error decoding response body"));
+ assert(err.message.includes("unexpected internal error encountered"));
const httpConn = await server;
httpConn.close();
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts
index 363667066..ff77578e6 100644
--- a/tests/unit/serve_test.ts
+++ b/tests/unit/serve_test.ts
@@ -3522,7 +3522,11 @@ Deno.test(
fail();
} catch (clientError) {
assert(clientError instanceof TypeError);
- assert(clientError.message.includes("error sending request for url"));
+ assert(
+ clientError.message.endsWith(
+ "connection closed before message completed",
+ ),
+ );
} finally {
ac.abort();
await server.finished;
@@ -3570,7 +3574,11 @@ Deno.test({
fail();
} catch (clientError) {
assert(clientError instanceof TypeError);
- assert(clientError.message.includes("error sending request for url"));
+ assert(
+ clientError.message.endsWith(
+ "connection closed before message completed",
+ ),
+ );
} finally {
ac.abort();
await server.finished;
diff --git a/tests/util/server/src/https.rs b/tests/util/server/src/https.rs
index 617fd5cae..8a2524dca 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_result: Result<Vec<CertificateDer<'static>>, io::Error> = {
+ let certs: Vec<Certificate> = {
let mut cert_reader = io::BufReader::new(cert_file);
- rustls_pemfile::certs(&mut cert_reader).collect()
+ rustls_pemfile::certs(&mut cert_reader)
+ .unwrap()
+ .into_iter()
+ .map(Certificate)
+ .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)
- .collect::<Vec<_>>()
- .remove(0)?;
+ .expect("Cannot load CA certificate")
+ .remove(0);
let mut key_reader = io::BufReader::new(key_file);
let key = {
- 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))
+ 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())
} else {
None
}
@@ -100,19 +100,18 @@ pub fn get_tls_config(
match key {
Some(key) => {
let mut root_cert_store = rustls::RootCertStore::empty();
- root_cert_store.add(ca_cert).unwrap();
+ root_cert_store.add(&rustls::Certificate(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_client_cert_verifier(client_verifier)
- .with_single_cert(certs, key)
+ .with_safe_defaults()
+ .with_client_cert_verifier(Arc::new(
+ rustls::server::AllowAnyAnonymousOrAuthenticatedClient::new(
+ root_cert_store,
+ ),
+ ))
+ .with_single_cert(certs, PrivateKey(key))
.map_err(|e| anyhow!("Error setting cert: {:?}", e))
.unwrap();