mod common;
use common::TestServer;
use glide::{AsyncCommands, ConnectionManagementCommands, CustomCommand};
const NEW_PASS: &str = "rotated-p4ss";
#[tokio::test]
async fn update_password_immediate_auth_succeeds() {
let srv = match TestServer::start() {
Some(s) => s,
None => {
eprintln!("SKIP: no valkey-server binary available");
return;
}
};
let client = srv.client().await;
assert_eq!(client.ping().await.unwrap(), "PONG");
client
.custom_command(&["CONFIG", "SET", "requirepass", NEW_PASS])
.await
.unwrap();
client
.update_connection_password(Some(NEW_PASS.to_string()), true)
.await
.expect("immediate re-auth with the correct password should succeed");
let _: () = client.set("pw-k", "v").await.unwrap();
let got: Option<glide::Bytes> = client.get("pw-k").await.unwrap();
assert_eq!(got.as_deref(), Some(&b"v"[..]));
client
.update_connection_password(None, false)
.await
.unwrap();
client
.custom_command(&["CONFIG", "SET", "requirepass", ""])
.await
.unwrap();
}
#[tokio::test]
async fn update_password_immediate_auth_wrong_password_errors() {
let srv = match TestServer::start() {
Some(s) => s,
None => {
eprintln!("SKIP: no valkey-server binary available");
return;
}
};
let client = srv.client().await;
client
.custom_command(&["CONFIG", "SET", "requirepass", NEW_PASS])
.await
.unwrap();
let res = client
.update_connection_password(Some("not-the-password".to_string()), true)
.await;
assert!(
res.is_err(),
"immediate AUTH with a wrong password must error"
);
client
.update_connection_password(Some(NEW_PASS.to_string()), true)
.await
.unwrap();
client
.custom_command(&["CONFIG", "SET", "requirepass", ""])
.await
.unwrap();
}
#[tokio::test]
async fn update_password_store_only_is_ok_without_auth() {
let srv = match TestServer::start() {
Some(s) => s,
None => {
eprintln!("SKIP: no valkey-server binary available");
return;
}
};
let client = srv.client().await;
client
.update_connection_password(Some("staged".to_string()), false)
.await
.unwrap();
client
.update_connection_password(None, false)
.await
.unwrap();
assert_eq!(client.ping().await.unwrap(), "PONG");
}
#[cfg(feature = "sync")]
#[test]
fn sync_update_password_store_only() {
use glide::GlideClientConfiguration;
use glide::sync::SyncGlideClient;
let srv = match TestServer::start() {
Some(s) => s,
None => {
eprintln!("SKIP: no valkey-server binary available");
return;
}
};
let config = GlideClientConfiguration::with_address("127.0.0.1", srv.port);
let client = SyncGlideClient::connect(config).expect("connect");
client
.update_connection_password(Some("staged".to_string()), false)
.expect("store-only password update should succeed");
client
.update_connection_password(None, false)
.expect("clearing password should succeed");
assert_eq!(client.ping().unwrap(), "PONG");
}
#[tokio::test]
async fn cluster_update_password_store_only() {
let cluster = match common::ClusterHarness::start() {
Some(cl) => cl,
None => {
eprintln!("SKIP: cluster harness unavailable");
return;
}
};
let client = match cluster.client().await {
Some(c) => c,
None => {
eprintln!("SKIP: cluster client connect failed");
return;
}
};
client
.update_connection_password(Some("staged".to_string()), false)
.await
.unwrap();
client
.update_connection_password(None, false)
.await
.unwrap();
assert_eq!(client.ping().await.unwrap(), "PONG");
}