Skip to content

Commit 1822234

Browse files
Add Client#list_users_without_permissions
while at it, fix a bug where it wasn't possible to give StatusCode::NOT_FOUND a pass when assessing whether to return an error..
1 parent 4ac9565 commit 1822234

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/blocking_api.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ where
240240
Ok(response)
241241
}
242242

243+
/// Lists users in the internal database that do not have access
244+
/// to any virtual hosts.
245+
pub fn list_users_without_permissions(&self) -> Result<Vec<responses::User>> {
246+
let response = self.http_get("users/without-permissions", None, None)?;
247+
let response = response.json()?;
248+
Ok(response)
249+
}
250+
243251
/// Lists all client connections across the cluster.
244252
pub fn list_connections(&self) -> Result<Vec<responses::Connection>> {
245253
let response = self.http_get("connections", None, None)?;
@@ -1169,8 +1177,14 @@ where
11691177
server_code_to_accept_or_ignore: Option<StatusCode>,
11701178
) -> Result<HttpClientResponse> {
11711179
let status = response.status();
1172-
if status == StatusCode::NOT_FOUND {
1173-
return Err(NotFound);
1180+
1181+
match client_code_to_accept_or_ignore {
1182+
Some(status_code) if status_code == StatusCode::NOT_FOUND => {}
1183+
_ => {
1184+
if status == StatusCode::NOT_FOUND {
1185+
return Err(NotFound);
1186+
}
1187+
}
11741188
}
11751189

11761190
if status.is_client_error() {

tests/user_tests.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ fn test_list_users() {
2727
assert!(vec.iter().any(|u| u.name == "guest"))
2828
}
2929

30+
#[test]
31+
fn test_list_users_without_permissions() {
32+
let endpoint = endpoint();
33+
let rc = Client::new(&endpoint, USERNAME, PASSWORD);
34+
let test_name = "test_list_users_without_permissions";
35+
36+
let username = format!("{}.1", test_name);
37+
rc.delete_user(&username, true)
38+
.expect("failed to delete a user");
39+
40+
let salt = password_hashing::salt();
41+
let password_hash = password_hashing::base64_encoded_salted_password_hash_sha256(
42+
&salt,
43+
"test_list_users_without_permissions.1",
44+
);
45+
let params = UserParams {
46+
name: &username,
47+
password_hash: &password_hash,
48+
tags: "",
49+
};
50+
rc.create_user(&params).expect("failed to create a user");
51+
52+
let result1 = rc.list_users_without_permissions();
53+
assert!(result1.is_ok());
54+
let vec = result1.unwrap();
55+
assert!(vec.iter().any(|u| u.name == username));
56+
57+
rc.delete_user(&username, true)
58+
.expect("failed to delete a user");
59+
}
60+
3061
#[test]
3162
fn test_get_user() {
3263
let endpoint = endpoint();

0 commit comments

Comments
 (0)