Skip to content

Commit a115c45

Browse files
committed
Fix PreferSsl
It'd be nice to have more robust testing for the SSL logic, but it seems to be working. Closes rust-postgres#15
1 parent 4522045 commit a115c45

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,12 @@ fn initialize_stream(host: &str, port: Port, ssl: SslMode)
406406

407407
let resp = socket.read_u8();
408408

409-
if resp == 'N' as u8 && ssl_required {
410-
return Err(NoSslSupport);
409+
if resp == 'N' as u8 {
410+
if ssl_required {
411+
return Err(NoSslSupport);
412+
} else {
413+
return Ok(Normal(socket));
414+
}
411415
}
412416

413417
match SslStream::try_new(ctx, socket) {

test.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use lib::{PostgresNoticeHandler,
2525
PostgresStatement,
2626
ResultDescription,
2727
RequireSsl,
28+
PreferSsl,
2829
NoSsl};
2930
use lib::error::hack::{SyntaxError,
3031
InvalidPassword,
@@ -571,13 +572,21 @@ fn test_cancel_query() {
571572
}
572573

573574
#[test]
574-
fn test_ssl_conn() {
575+
fn test_require_ssl_conn() {
575576
let ctx = SslContext::new(Sslv3);
576577
let conn = PostgresConnection::connect("postgres://postgres@localhost",
577578
RequireSsl(&ctx));
578579
conn.update("SELECT 1::VARCHAR", []);
579580
}
580581

582+
#[test]
583+
fn test_prefer_ssl_conn() {
584+
let ctx = SslContext::new(Sslv3);
585+
let conn = PostgresConnection::connect("postgres://postgres@localhost",
586+
PreferSsl(&ctx));
587+
conn.update("SELECT 1::VARCHAR", []);
588+
}
589+
581590
#[test]
582591
fn test_plaintext_pass() {
583592
PostgresConnection::connect("postgres://pass_user:password@localhost/postgres", NoSsl);

0 commit comments

Comments
 (0)