mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-13 08:36:54 +00:00
fix(admin): clarify invalid group name errors (#5986)
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
//! E2E tests for group management (fixes #2028).
|
||||
|
||||
use crate::common::{RustFSTestEnvironment, awscurl_delete, awscurl_get, awscurl_put, init_logging};
|
||||
use crate::common::{RustFSTestEnvironment, admin_request, awscurl_delete, awscurl_get, awscurl_put, init_logging};
|
||||
use aws_sdk_s3::config::{Credentials, Region};
|
||||
use aws_sdk_s3::{Client, Config};
|
||||
use serial_test::serial;
|
||||
@@ -32,6 +32,56 @@ fn create_user_s3_client(env: &RustFSTestEnvironment, access_key: &str, secret_k
|
||||
Client::from_conf(config)
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn update_group_members_rejects_invalid_new_group_names() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
init_logging();
|
||||
|
||||
let mut env = RustFSTestEnvironment::new().await?;
|
||||
env.start_rustfs_server(vec![]).await?;
|
||||
|
||||
let invalid_groups = [
|
||||
("test group", "group name contains whitespace"),
|
||||
("test=group", "group name contains reserved characters =,"),
|
||||
("test,group", "group name contains reserved characters =,"),
|
||||
];
|
||||
|
||||
for (group, expected_message) in invalid_groups {
|
||||
let body = serde_json::json!({
|
||||
"group": group,
|
||||
"members": [],
|
||||
"isRemove": false,
|
||||
"groupStatus": "enabled"
|
||||
})
|
||||
.to_string();
|
||||
let (status, response_body) = admin_request(
|
||||
&env.url,
|
||||
http::Method::PUT,
|
||||
"/rustfs/admin/v3/update-group-members",
|
||||
Some(body),
|
||||
&env.access_key,
|
||||
&env.secret_key,
|
||||
)
|
||||
.await?;
|
||||
|
||||
assert_eq!(
|
||||
status,
|
||||
reqwest::StatusCode::BAD_REQUEST,
|
||||
"invalid group {group:?} must return HTTP 400, body: {response_body}"
|
||||
);
|
||||
assert!(
|
||||
response_body.contains("<Code>InvalidArgument</Code>"),
|
||||
"invalid group {group:?} must return InvalidArgument, body: {response_body}"
|
||||
);
|
||||
assert!(
|
||||
response_body.contains(&format!("<Message>{expected_message}</Message>")),
|
||||
"invalid group {group:?} returned an unexpected message: {response_body}"
|
||||
);
|
||||
}
|
||||
|
||||
env.stop_server();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Test that deleting a group with members fails, and deleting an empty group succeeds.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[serial]
|
||||
|
||||
Reference in New Issue
Block a user