Change some OperationError into HTTP Bad Request (400). (#3125)

This commit is contained in:
George Wu 2024-10-20 19:57:23 -07:00 committed by GitHub
parent bdc0dc6190
commit 7eb54be487
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 66 additions and 7 deletions

View file

@ -55,8 +55,11 @@ impl IntoResponse for WebError {
OperationError::NoMatchingEntries => (StatusCode::NOT_FOUND, None), OperationError::NoMatchingEntries => (StatusCode::NOT_FOUND, None),
OperationError::PasswordQuality(_) OperationError::PasswordQuality(_)
| OperationError::EmptyRequest | OperationError::EmptyRequest
| OperationError::InvalidAttribute(_)
| OperationError::InvalidAttributeName(_)
| OperationError::SchemaViolation(_) | OperationError::SchemaViolation(_)
| OperationError::CU0003WebauthnUserNotVerified => { | OperationError::CU0003WebauthnUserNotVerified
| OperationError::VL0001ValueSshPublicKeyString => {
(StatusCode::BAD_REQUEST, None) (StatusCode::BAD_REQUEST, None)
} }
_ => (StatusCode::INTERNAL_SERVER_ERROR, None), _ => (StatusCode::INTERNAL_SERVER_ERROR, None),

View file

@ -1,12 +1,12 @@
use kanidm_client::KanidmClient; use kanidm_client::{ClientError, KanidmClient};
use kanidm_proto::constants::ATTR_DESCRIPTION; use kanidm_proto::constants::ATTR_DESCRIPTION;
use kanidmd_testkit::{create_user, ADMIN_TEST_PASSWORD}; use kanidmd_testkit::{create_user, ADMIN_TEST_PASSWORD, ADMIN_TEST_USER};
use serde_json::Value; use serde_json::Value;
#[kanidmd_testkit::test] #[kanidmd_testkit::test]
async fn test_v1_group_id_patch(rsclient: KanidmClient) { async fn test_v1_group_id_patch(rsclient: KanidmClient) {
let res = rsclient let res = rsclient
.auth_simple_password("admin", ADMIN_TEST_PASSWORD) .auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD)
.await; .await;
assert!(res.is_ok()); assert!(res.is_ok());
@ -23,3 +23,31 @@ async fn test_v1_group_id_patch(rsclient: KanidmClient) {
}; };
eprintln!("response: {:#?}", response); eprintln!("response: {:#?}", response);
} }
#[kanidmd_testkit::test]
async fn test_v1_group_id_attr_post(rsclient: KanidmClient) {
let res = rsclient
.auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD)
.await;
assert!(res.is_ok());
create_user(&rsclient, "foo", "foogroup").await;
let post_body = serde_json::json!(["foo"]);
let response: ClientError = match rsclient
.perform_post_request::<serde_json::Value, String>(
"/v1/group/foogroup/_attr/member2",
post_body,
)
.await
{
Ok(val) => panic!("Expected failure to post group attribute: {:?}", val),
Err(err) => err,
};
eprintln!("response: {:#?}", response);
assert!(matches!(
response,
ClientError::Http(reqwest::StatusCode::BAD_REQUEST, _, _)
));
}

View file

@ -1,12 +1,12 @@
use kanidm_client::KanidmClient; use kanidm_client::{ClientError, KanidmClient};
use kanidm_proto::constants::ATTR_MAIL; use kanidm_proto::constants::ATTR_MAIL;
use kanidmd_testkit::{create_user, ADMIN_TEST_PASSWORD}; use kanidmd_testkit::{create_user, ADMIN_TEST_PASSWORD, ADMIN_TEST_USER};
use serde_json::Value; use serde_json::Value;
#[kanidmd_testkit::test] #[kanidmd_testkit::test]
async fn test_v1_person_id_patch(rsclient: KanidmClient) { async fn test_v1_person_id_patch(rsclient: KanidmClient) {
let res = rsclient let res = rsclient
.auth_simple_password("admin", ADMIN_TEST_PASSWORD) .auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD)
.await; .await;
assert!(res.is_ok()); assert!(res.is_ok());
@ -23,3 +23,31 @@ async fn test_v1_person_id_patch(rsclient: KanidmClient) {
}; };
eprintln!("response: {:#?}", response); eprintln!("response: {:#?}", response);
} }
#[kanidmd_testkit::test]
async fn test_v1_person_id_ssh_pubkeys_post(rsclient: KanidmClient) {
let res = rsclient
.auth_simple_password(ADMIN_TEST_USER, ADMIN_TEST_PASSWORD)
.await;
assert!(res.is_ok());
create_user(&rsclient, "foo", "foogroup").await;
let post_body = serde_json::json!([
"ssh-key-tag-goes-here",
"ed25519 im_a_real_ssh_public_key_just_trust_me comment"
]);
let response: ClientError = match rsclient
.perform_post_request::<serde_json::Value, String>("/v1/person/foo/_ssh_pubkeys", post_body)
.await
{
Ok(val) => panic!("Expected failure to post person ssh pubkeys: {:?}", val),
Err(err) => err,
};
eprintln!("response: {:#?}", response);
assert!(matches!(
response,
ClientError::Http(reqwest::StatusCode::BAD_REQUEST, _, _)
));
}