Skip to content

Commit

Permalink
Add a user that must use ssl for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Dec 26, 2016
1 parent 1ba054a commit faf6645
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .travis/pg_hba.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ host all md5_user 127.0.0.1/32 md5
host all pass_user ::1/128 password
host all md5_user ::1/128 md5

hostssl all ssl_user 127.0.0.1/32 trust
hostssl all ssl_user ::1/128 trust
host all ssl_user 127.0.0.1/32 reject
host all ssl_user ::1/128 reject

# IPv4 local connections:
host all postgres 127.0.0.1/32 trust
# IPv6 local connections:
Expand Down
1 change: 1 addition & 0 deletions .travis/setup.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CREATE ROLE pass_user PASSWORD 'password' LOGIN;
CREATE ROLE md5_user PASSWORD 'password' LOGIN;
CREATE ROLE ssl_user LOGIN;
CREATE EXTENSION hstore;
CREATE EXTENSION citext;
16 changes: 15 additions & 1 deletion postgres-tokio/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ fn unix_socket() {
l.run(done).unwrap();
}

#[test]
fn ssl_user_ssl_required() {
let mut l = Core::new().unwrap();
let handle = l.handle();

let done = Connection::connect("postgres://ssl_user@localhost/postgres", TlsMode::None, &handle);

match l.run(done) {
Err(ConnectError::Db(e)) => assert!(e.code == SqlState::InvalidAuthorizationSpecification),
Err(e) => panic!("unexpected error {}", e),
Ok(_) => panic!("unexpected success"),
}
}

#[cfg(feature = "with-openssl")]
#[test]
fn openssl_required() {
Expand All @@ -210,7 +224,7 @@ fn openssl_required() {
let negotiator = OpenSsl::from(builder.build());

let mut l = Core::new().unwrap();
let done = Connection::connect("postgres://postgres@localhost",
let done = Connection::connect("postgres://ssl_user@localhost/postgres",
TlsMode::Require(Box::new(negotiator)),
&l.handle())
.then(|c| c.unwrap().prepare("SELECT 1"))
Expand Down

0 comments on commit faf6645

Please sign in to comment.