add test for TLS version selection

Since rustls does not even support TLS versions below 1.2, no need to check
for that.
This commit is contained in:
Johann150 2021-02-25 17:31:24 +01:00
parent 8b4692b08b
commit 8a6eb65b48
No known key found for this signature in database
GPG key ID: 9EE6577A2A06F8F1
3 changed files with 24 additions and 0 deletions

View file

@ -254,3 +254,25 @@ fn serve_secret() {
assert_eq!(page.header.status, Status::Success);
}
#[test]
#[should_panic(expected = "AlertReceived(ProtocolVersion)")]
fn explicit_tls_version() {
use rustls::{ClientSession, ProtocolVersion};
use std::io::Read;
use std::net::TcpStream;
let _server = Server::new(&["--addr", "[::]:1976", "-3"]);
let mut config = rustls::ClientConfig::new();
// try to connect using only TLS 1.2
config.versions = vec![ProtocolVersion::TLSv1_2];
let dns_name = webpki::DNSNameRef::try_from_ascii_str("localhost").unwrap();
let mut session = ClientSession::new(&std::sync::Arc::new(config), dns_name);
let mut tcp = TcpStream::connect(addr(1976)).unwrap();
let mut tls = rustls::Stream::new(&mut session, &mut tcp);
let mut buf = [0; 10];
tls.read(&mut buf).unwrap();
}