Test missing/bad password

This commit is contained in:
Steven Fackler 2016-12-20 16:19:41 -08:00
parent 9227a0c316
commit dc08fc6423

View File

@ -1,6 +1,7 @@
use tokio_core::reactor::Core;
use super::*;
use error::{ConnectError, SqlState};
#[test]
fn basic() {
@ -19,10 +20,58 @@ fn md5_user() {
l.run(done).unwrap();
}
#[test]
fn md5_user_no_pass() {
let mut l = Core::new().unwrap();
let handle = l.handle();
let done = Connection::connect("postgres://md5_user@localhost/postgres", &handle);
match l.run(done) {
Err(ConnectError::ConnectParams(_)) => {}
Err(e) => panic!("unexpected error {}", e),
Ok(_) => panic!("unexpected success"),
}
}
#[test]
fn md5_user_wrong_pass() {
let mut l = Core::new().unwrap();
let handle = l.handle();
let done = Connection::connect("postgres://md5_user:foobar@localhost/postgres", &handle);
match l.run(done) {
Err(ConnectError::Db(ref e)) if e.code == SqlState::InvalidPassword => {}
Err(e) => panic!("unexpected error {}", e),
Ok(_) => panic!("unexpected success"),
}
}
#[test]
fn pass_user() {
let mut l = Core::new().unwrap();
let handle = l.handle();
let done = Connection::connect("postgres://pass_user:password@localhost/postgres", &handle);
l.run(done).unwrap();
}
}
#[test]
fn pass_user_no_pass() {
let mut l = Core::new().unwrap();
let handle = l.handle();
let done = Connection::connect("postgres://pass_user@localhost/postgres", &handle);
match l.run(done) {
Err(ConnectError::ConnectParams(_)) => {}
Err(e) => panic!("unexpected error {}", e),
Ok(_) => panic!("unexpected success"),
}
}
#[test]
fn pass_user_wrong_pass() {
let mut l = Core::new().unwrap();
let handle = l.handle();
let done = Connection::connect("postgres://pass_user:foobar@localhost/postgres", &handle);
match l.run(done) {
Err(ConnectError::Db(ref e)) if e.code == SqlState::InvalidPassword => {}
Err(e) => panic!("unexpected error {}", e),
Ok(_) => panic!("unexpected success"),
}
}