Skip to content

Commit def3cfc

Browse files
committed
add integration test, only resume connection if password is still empty
1 parent d6450e4 commit def3cfc

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

integration/rust/tests/integration/auth.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,34 @@ async fn test_passthrough_auth() {
9191
user.execute("SELECT 1").await.unwrap();
9292
original.execute("SELECT 1").await.unwrap();
9393
}
94+
95+
#[tokio::test]
96+
#[serial]
97+
async fn test_user_without_password_passthrough_auth() {
98+
let admin = admin_sqlx().await;
99+
100+
admin.execute("RELOAD").await.unwrap();
101+
admin.execute("SET auth_type TO 'scram'").await.unwrap();
102+
assert_setting_str("auth_type", "scram").await;
103+
104+
let user = "postgres://pgdog2:pgdog@127.0.0.1:6432/pgdog";
105+
106+
let no_password_err = PgConnection::connect(user).await.err().unwrap();
107+
108+
assert!(
109+
no_password_err
110+
.to_string()
111+
.contains("password for user \"pgdog2\" and database \"pgdog\" is wrong")
112+
);
113+
114+
admin
115+
.execute("SET passthrough_auth TO 'enabled_plain'")
116+
.await
117+
.unwrap();
118+
assert_setting_str("passthrough_auth", "enabled_plain").await;
119+
120+
let mut user = PgConnection::connect(user).await.unwrap();
121+
122+
user.execute("SELECT 1").await.unwrap();
123+
user.close().await.unwrap();
124+
}

integration/users.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "pgdog"
33
database = "pgdog"
44
password = "pgdog"
55

6+
[[users]]
7+
name = "pgdog2"
8+
database = "pgdog"
9+
610
[[users]]
711
name = "pgdog_session"
812
database = "pgdog"

pgdog/src/frontend/client/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ impl Client {
250250
stream.send(&Authentication::Ok).await?;
251251
}
252252

253-
// Allow pools to connect if passthrough password exists
254-
if passthrough_password.is_some() {
253+
if passthrough_password.is_some() && conn.cluster()?.password().is_empty() {
255254
conn.resume_cluster_pools();
256255
}
257256

0 commit comments

Comments
 (0)