Skip to content

Commit faf6645

Browse files
committed
Add a user that must use ssl for tests
1 parent 1ba054a commit faf6645

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

.travis/pg_hba.conf

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ host all md5_user 127.0.0.1/32 md5
44
host all pass_user ::1/128 password
55
host all md5_user ::1/128 md5
66

7+
hostssl all ssl_user 127.0.0.1/32 trust
8+
hostssl all ssl_user ::1/128 trust
9+
host all ssl_user 127.0.0.1/32 reject
10+
host all ssl_user ::1/128 reject
11+
712
# IPv4 local connections:
813
host all postgres 127.0.0.1/32 trust
914
# IPv6 local connections:

.travis/setup.sql

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
CREATE ROLE pass_user PASSWORD 'password' LOGIN;
22
CREATE ROLE md5_user PASSWORD 'password' LOGIN;
3+
CREATE ROLE ssl_user LOGIN;
34
CREATE EXTENSION hstore;
45
CREATE EXTENSION citext;

postgres-tokio/src/test.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,20 @@ fn unix_socket() {
199199
l.run(done).unwrap();
200200
}
201201

202+
#[test]
203+
fn ssl_user_ssl_required() {
204+
let mut l = Core::new().unwrap();
205+
let handle = l.handle();
206+
207+
let done = Connection::connect("postgres://ssl_user@localhost/postgres", TlsMode::None, &handle);
208+
209+
match l.run(done) {
210+
Err(ConnectError::Db(e)) => assert!(e.code == SqlState::InvalidAuthorizationSpecification),
211+
Err(e) => panic!("unexpected error {}", e),
212+
Ok(_) => panic!("unexpected success"),
213+
}
214+
}
215+
202216
#[cfg(feature = "with-openssl")]
203217
#[test]
204218
fn openssl_required() {
@@ -210,7 +224,7 @@ fn openssl_required() {
210224
let negotiator = OpenSsl::from(builder.build());
211225

212226
let mut l = Core::new().unwrap();
213-
let done = Connection::connect("postgres://postgres@localhost",
227+
let done = Connection::connect("postgres://ssl_user@localhost/postgres",
214228
TlsMode::Require(Box::new(negotiator)),
215229
&l.handle())
216230
.then(|c| c.unwrap().prepare("SELECT 1"))

0 commit comments

Comments
 (0)