diff options
| author | Steven Fackler <[email protected]> | 2013-11-16 21:09:45 -0800 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2013-11-16 21:09:45 -0800 |
| commit | 0b287710c408a510adffbd471e227fd1f87e2780 (patch) | |
| tree | 94e803ce47ec747064801be430d6f3ba5df4c5c9 /test.rs | |
| parent | Start of x509 interface (diff) | |
| download | rust-openssl-0b287710c408a510adffbd471e227fd1f87e2780.tar.xz rust-openssl-0b287710c408a510adffbd471e227fd1f87e2780.zip | |
Certificate error codes
Diffstat (limited to 'test.rs')
| -rw-r--r-- | test.rs | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -1,4 +1,4 @@ -#[feature(struct_variant)]; +#[feature(struct_variant, macro_rules)]; use std::io::Writer; use std::io::net::tcp::TcpStream; @@ -116,6 +116,34 @@ fn test_verify_callback_load_certs() { } #[test] +fn test_verify_trusted_get_error_ok() { + fn callback(_preverify_ok: bool, x509_ctx: X509StoreContext) -> bool { + assert!(x509_ctx.get_error().is_none()); + true + } + let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap(); + let mut ctx = SslContext::new(Sslv23); + ctx.set_verify(SslVerifyPeer, Some(callback)); + match ctx.set_CA_file("test/cert.pem") { + None => {} + Some(err) => fail!("Unexpected error {:?}", err) + } + assert!(SslStream::try_new(&ctx, stream).is_ok()); +} + +#[test] +fn test_verify_trusted_get_error_err() { + fn callback(_preverify_ok: bool, x509_ctx: X509StoreContext) -> bool { + assert!(x509_ctx.get_error().is_some()); + false + } + let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap(); + let mut ctx = SslContext::new(Sslv23); + ctx.set_verify(SslVerifyPeer, Some(callback)); + assert!(SslStream::try_new(&ctx, stream).is_err()); +} + +#[test] fn test_write() { let stream = TcpStream::connect(FromStr::from_str("127.0.0.1:15418").unwrap()).unwrap(); let mut stream = SslStream::new(&SslContext::new(Sslv23), stream); |