expose group patch for parity ()

Co-authored-by: James Hodgkinson <james@terminaloutcomes.com>
This commit is contained in:
Vladimir Dronnikov 2024-03-07 02:54:20 +03:00 committed by GitHub
parent 4c1fa0d644
commit 221445d387
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 72 additions and 29 deletions
libs/client/src
server
core/src/https
testkit/tests

View file

@ -857,7 +857,7 @@ impl KanidmClient {
.map_err(|e| ClientError::JsonDecode(e, opid))
}
async fn perform_patch_request<R: Serialize, T: DeserializeOwned>(
pub async fn perform_patch_request<R: Serialize, T: DeserializeOwned>(
&self,
dest: &str,
request: R,

View file

@ -164,6 +164,7 @@ impl Modify for SecurityAddon {
super::v1::group_get,
super::v1::group_post,
super::v1::group_id_get,
super::v1::group_id_patch,
super::v1::group_id_delete,
super::v1::group_id_attr_delete,
super::v1::group_id_attr_get,

View file

@ -2166,6 +2166,35 @@ pub async fn group_id_get(
json_rest_event_get_id(state, id, filter, None, kopid, client_auth_info).await
}
#[utoipa::path(
patch,
path = "/v1/group/{id}",
responses(
DefaultApiResponse,
),
request_body=ProtoEntry,
security(("token_jwt" = [])),
tag = "v1/group",
operation_id = "group_id_patch",
)]
pub async fn group_id_patch(
State(state): State<ServerState>,
Extension(kopid): Extension<KOpId>,
VerifiedClientInformation(client_auth_info): VerifiedClientInformation,
Path(id): Path<String>,
Json(obj): Json<ProtoEntry>,
) -> Result<Json<()>, WebError> {
// Update a value / attrs
let filter = filter_all!(f_eq(Attribute::Class, EntryClass::Group.into()));
let filter = Filter::join_parts_and(filter, filter_all!(f_id(id.as_str())));
state
.qe_w_ref
.handle_internalpatch(client_auth_info, filter, obj, kopid.eventid)
.await
.map(Json::from)
.map_err(WebError::from)
}
#[utoipa::path(
delete,
path = "/v1/group/{id}",
@ -3152,7 +3181,7 @@ pub(crate) fn route_setup(state: ServerState) -> Router<ServerState> {
.route("/v1/group/:id/_unix/_token", get(group_id_unix_token_get))
.route("/v1/group/:id/_unix", post(group_id_unix_post))
.route("/v1/group", get(group_get).post(group_post))
.route("/v1/group/:id", get(group_id_get).delete(group_id_delete))
.route("/v1/group/:id", get(group_id_get).patch(group_id_patch).delete(group_id_delete))
.route(
"/v1/group/:id/_attr/:attr",
delete(group_id_attr_delete)

View file

@ -0,0 +1,25 @@
use kanidm_client::KanidmClient;
use kanidm_proto::constants::ATTR_DESCRIPTION;
use kanidmd_testkit::{create_user, ADMIN_TEST_PASSWORD};
use serde_json::Value;
#[kanidmd_testkit::test]
async fn test_v1_group_id_patch(rsclient: KanidmClient) {
let res = rsclient
.auth_simple_password("admin", ADMIN_TEST_PASSWORD)
.await;
assert!(res.is_ok());
create_user(&rsclient, "foo", "foogroup").await;
let post_body = serde_json::json!({"attrs": { ATTR_DESCRIPTION : ["Fancy group change"]}});
let response: Value = match rsclient
.perform_patch_request("/v1/group/foogroup", post_body)
.await
{
Ok(val) => val,
Err(err) => panic!("Failed to patch group: {:?}", err),
};
eprintln!("response: {:#?}", response);
}

View file

@ -1,37 +1,25 @@
use kanidm_client::KanidmClient;
use kanidm_proto::constants::{APPLICATION_JSON, ATTR_EMAIL};
use reqwest::header::CONTENT_TYPE;
use kanidm_proto::constants::ATTR_MAIL;
use kanidmd_testkit::{create_user, ADMIN_TEST_PASSWORD};
use serde_json::Value;
/// This literally tests that the thing exists and responds in a way we expect, probably worth testing it better...
#[kanidmd_testkit::test]
async fn test_v1_person_patch(rsclient: KanidmClient) {
// We need to do manual reqwests here.
let client = reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(true)
.build()
.unwrap();
async fn test_v1_person_id_patch(rsclient: KanidmClient) {
let res = rsclient
.auth_simple_password("admin", ADMIN_TEST_PASSWORD)
.await;
assert!(res.is_ok());
let post_body = serde_json::json!({"attrs": { ATTR_EMAIL : "crab@example.com"}}).to_string();
create_user(&rsclient, "foo", "foogroup").await;
let response = match client
.patch(rsclient.make_url("/v1/person/foo"))
.header(CONTENT_TYPE, APPLICATION_JSON)
.body(post_body)
.send()
let post_body = serde_json::json!({"attrs": { ATTR_MAIL : ["crab@example.com"]}});
let response: Value = match rsclient
.perform_patch_request("/v1/person/foo", post_body)
.await
{
Ok(value) => value,
Err(error) => {
panic!(
"Failed to query {:?} : {:#?}",
rsclient.make_url("/v1/person/foo"),
error
);
}
Ok(val) => val,
Err(err) => panic!("Failed to patch person: {:?}", err),
};
eprintln!("response: {:#?}", response);
assert_eq!(response.status(), 422);
let body = response.text().await.unwrap();
eprintln!("{}", body);
}