From b81b797a44338177b0be667b0d76e06069cccfd7 Mon Sep 17 00:00:00 2001 From: Michael Engel Date: Mon, 30 Dec 2024 16:40:14 +0100 Subject: [PATCH] Handle None for signal_id in GetValue endpoint Currently, calling the GetValue endpoint with an empty body will cause the databroker to panic since unwrap is called on the signal_id option - which is None in that case. In order to prevent the server-side panic, a simple none check is performed before calling unwrap. Signed-off-by: Michael Engel --- databroker/src/grpc/kuksa_val_v2/val.rs | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/databroker/src/grpc/kuksa_val_v2/val.rs b/databroker/src/grpc/kuksa_val_v2/val.rs index 25f82769..286d1958 100644 --- a/databroker/src/grpc/kuksa_val_v2/val.rs +++ b/databroker/src/grpc/kuksa_val_v2/val.rs @@ -853,6 +853,10 @@ async fn get_signal( signal_id: Option, broker: &AuthorizedAccess<'_, '_>, ) -> Result { + if signal_id.is_none() { + return Err(tonic::Status::invalid_argument("No SignalId provided")); + } + if let Some(signal) = signal_id.unwrap().signal { match signal { proto::signal_id::Signal::Path(path) => { @@ -1175,6 +1179,28 @@ mod tests { } } + #[tokio::test] + async fn test_get_value_with_signal_id_none() { + let broker = DataBroker::default(); + + let request = proto::GetValueRequest { signal_id: None }; + + // Manually insert permissions + let mut get_value_request = tonic::Request::new(request); + get_value_request + .extensions_mut() + .insert(permissions::ALLOW_ALL.clone()); + + match broker.get_value(get_value_request).await { + Ok(_response) => { + panic!("Did not expect success"); + } + Err(status) => { + assert_eq!(status.code(), tonic::Code::InvalidArgument) + } + } + } + struct GetValuesConfig { send_auth: bool, request_first: bool,