Skip to content

Commit dc08fc6

Browse files
committed
Test missing/bad password
1 parent 9227a0c commit dc08fc6

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

postgres-tokio/src/test.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use tokio_core::reactor::Core;
22

33
use super::*;
4+
use error::{ConnectError, SqlState};
45

56
#[test]
67
fn basic() {
@@ -19,10 +20,58 @@ fn md5_user() {
1920
l.run(done).unwrap();
2021
}
2122

23+
#[test]
24+
fn md5_user_no_pass() {
25+
let mut l = Core::new().unwrap();
26+
let handle = l.handle();
27+
let done = Connection::connect("postgres://md5_user@localhost/postgres", &handle);
28+
match l.run(done) {
29+
Err(ConnectError::ConnectParams(_)) => {}
30+
Err(e) => panic!("unexpected error {}", e),
31+
Ok(_) => panic!("unexpected success"),
32+
}
33+
}
34+
35+
#[test]
36+
fn md5_user_wrong_pass() {
37+
let mut l = Core::new().unwrap();
38+
let handle = l.handle();
39+
let done = Connection::connect("postgres://md5_user:foobar@localhost/postgres", &handle);
40+
match l.run(done) {
41+
Err(ConnectError::Db(ref e)) if e.code == SqlState::InvalidPassword => {}
42+
Err(e) => panic!("unexpected error {}", e),
43+
Ok(_) => panic!("unexpected success"),
44+
}
45+
}
46+
2247
#[test]
2348
fn pass_user() {
2449
let mut l = Core::new().unwrap();
2550
let handle = l.handle();
2651
let done = Connection::connect("postgres://pass_user:password@localhost/postgres", &handle);
2752
l.run(done).unwrap();
28-
}
53+
}
54+
55+
#[test]
56+
fn pass_user_no_pass() {
57+
let mut l = Core::new().unwrap();
58+
let handle = l.handle();
59+
let done = Connection::connect("postgres://pass_user@localhost/postgres", &handle);
60+
match l.run(done) {
61+
Err(ConnectError::ConnectParams(_)) => {}
62+
Err(e) => panic!("unexpected error {}", e),
63+
Ok(_) => panic!("unexpected success"),
64+
}
65+
}
66+
67+
#[test]
68+
fn pass_user_wrong_pass() {
69+
let mut l = Core::new().unwrap();
70+
let handle = l.handle();
71+
let done = Connection::connect("postgres://pass_user:foobar@localhost/postgres", &handle);
72+
match l.run(done) {
73+
Err(ConnectError::Db(ref e)) if e.code == SqlState::InvalidPassword => {}
74+
Err(e) => panic!("unexpected error {}", e),
75+
Ok(_) => panic!("unexpected success"),
76+
}
77+
}

0 commit comments

Comments
 (0)