aboutsummaryrefslogtreecommitdiff
path: root/openssl/src
diff options
context:
space:
mode:
authorMarko Lalic <[email protected]>2015-03-18 20:55:07 +0100
committerMarko Lalic <[email protected]>2015-03-23 08:41:15 +0100
commitf50577909ebea982313657594d6a58578a305e11 (patch)
tree8f85163aa252370b00a0b6dff4b72778c52e266b /openssl/src
parentopenssl: Add tests for client-side NPN (diff)
downloadrust-openssl-f50577909ebea982313657594d6a58578a305e11.tar.xz
rust-openssl-f50577909ebea982313657594d6a58578a305e11.zip
openssl: Add tests for server-side NPN
Diffstat (limited to 'openssl/src')
-rw-r--r--openssl/src/ssl/tests.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/openssl/src/ssl/tests.rs b/openssl/src/ssl/tests.rs
index 33ae619f..468b1053 100644
--- a/openssl/src/ssl/tests.rs
+++ b/openssl/src/ssl/tests.rs
@@ -292,3 +292,44 @@ fn test_connect_with_npn_successful_single_match() {
// is used.
assert_eq!(b"spdy/3.1", stream.get_selected_npn_protocol().unwrap());
}
+
+/// Tests that when the `SslStream` is created as a server stream, the protocols
+/// are correctly advertised to the client.
+#[test]
+#[cfg(feature = "npn")]
+fn test_npn_server_advertise_multiple() {
+ let localhost = "127.0.0.1:15420";
+ let listener = TcpListener::bind(localhost).unwrap();
+ // We create a different context instance for the server...
+ let listener_ctx = {
+ let mut ctx = SslContext::new(Sslv23).unwrap();
+ ctx.set_verify(SslVerifyPeer, None);
+ ctx.set_npn_protocols(&[b"http/1.1", b"spdy/3.1"]);
+ ctx.set_certificate_file(
+ &Path::new("test/cert.pem"), X509FileType::PEM);
+ ctx.set_private_key_file(
+ &Path::new("test/key.pem"), X509FileType::PEM);
+ ctx
+ };
+ // Have the listener wait on the connection in a different thread.
+ thread::spawn(move || {
+ let (stream, _) = listener.accept().unwrap();
+ let _ = SslStream::new_server(&listener_ctx, stream).unwrap();
+ });
+
+ let mut ctx = SslContext::new(Sslv23).unwrap();
+ ctx.set_verify(SslVerifyPeer, None);
+ ctx.set_npn_protocols(&[b"spdy/3.1"]);
+ match ctx.set_CA_file(&Path::new("test/cert.pem")) {
+ None => {}
+ Some(err) => panic!("Unexpected error {:?}", err)
+ }
+ // Now connect to the socket and make sure the protocol negotiation works...
+ let stream = TcpStream::connect(localhost).unwrap();
+ let stream = match SslStream::new(&ctx, stream) {
+ Ok(stream) => stream,
+ Err(err) => panic!("Expected success, got {:?}", err)
+ };
+ // SPDY is selected since that's the only thing the client supports.
+ assert_eq!(b"spdy/3.1", stream.get_selected_npn_protocol().unwrap());
+}