1
1
use tokio_core:: reactor:: Core ;
2
2
3
3
use super :: * ;
4
+ use error:: { ConnectError , SqlState } ;
4
5
5
6
#[ test]
6
7
fn basic ( ) {
@@ -19,10 +20,58 @@ fn md5_user() {
19
20
l. run ( done) . unwrap ( ) ;
20
21
}
21
22
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
+
22
47
#[ test]
23
48
fn pass_user ( ) {
24
49
let mut l = Core :: new ( ) . unwrap ( ) ;
25
50
let handle = l. handle ( ) ;
26
51
let done = Connection :: connect ( "postgres://pass_user:password@localhost/postgres" , & handle) ;
27
52
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