Skip to content

Commit 86ed421

Browse files
engelmiSebastianSchildt
authored andcommitted
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 <mengel@redhat.com>
1 parent a67f4e6 commit 86ed421

File tree

1 file changed

+26
-0
lines changed
  • databroker/src/grpc/kuksa_val_v2

1 file changed

+26
-0
lines changed

databroker/src/grpc/kuksa_val_v2/val.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,10 @@ async fn get_signal(
853853
signal_id: Option<proto::SignalId>,
854854
broker: &AuthorizedAccess<'_, '_>,
855855
) -> Result<i32, tonic::Status> {
856+
if signal_id.is_none() {
857+
return Err(tonic::Status::invalid_argument("No SignalId provided"));
858+
}
859+
856860
if let Some(signal) = signal_id.unwrap().signal {
857861
match signal {
858862
proto::signal_id::Signal::Path(path) => {
@@ -1175,6 +1179,28 @@ mod tests {
11751179
}
11761180
}
11771181

1182+
#[tokio::test]
1183+
async fn test_get_value_with_signal_id_none() {
1184+
let broker = DataBroker::default();
1185+
1186+
let request = proto::GetValueRequest { signal_id: None };
1187+
1188+
// Manually insert permissions
1189+
let mut get_value_request = tonic::Request::new(request);
1190+
get_value_request
1191+
.extensions_mut()
1192+
.insert(permissions::ALLOW_ALL.clone());
1193+
1194+
match broker.get_value(get_value_request).await {
1195+
Ok(_response) => {
1196+
panic!("Did not expect success");
1197+
}
1198+
Err(status) => {
1199+
assert_eq!(status.code(), tonic::Code::InvalidArgument)
1200+
}
1201+
}
1202+
}
1203+
11781204
struct GetValuesConfig {
11791205
send_auth: bool,
11801206
request_first: bool,

0 commit comments

Comments
 (0)