Skip to content

Commit

Permalink
Handle None for signal_id in GetValue endpoint
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
engelmi committed Jan 2, 2025
1 parent a67f4e6 commit b81b797
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions databroker/src/grpc/kuksa_val_v2/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,10 @@ async fn get_signal(
signal_id: Option<proto::SignalId>,
broker: &AuthorizedAccess<'_, '_>,
) -> Result<i32, tonic::Status> {
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) => {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b81b797

Please sign in to comment.