Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions up-subscription/src/handlers/fetch_subscribers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ impl RequestHandler for FetchSubscribersRequestHandler {
));
};

// topic input validation
// [impl->dsn~usubscription-fetch-subscribers-invalid-topic~1]
helpers::validate_uri(&topic)?;
helpers::validate_uri(&topic).map_err(|e| {
ServiceInvocationError::InvalidArgument(format!("Invalid topic uri '{topic}': {e}"))
})?;

// Interact with subscription manager backend
let (respond_to, receive_from) = oneshot::channel::<Vec<SubscriberUUri>>();
Expand Down
12 changes: 10 additions & 2 deletions up-subscription/src/handlers/fetch_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ impl RequestHandler for FetchSubscriptionsRequestHandler {
let request_kind = match request {
Some(Request::Topic(topic)) => {
// [impl->dsn~usubscription-fetch-subscriptions-invalid-topic~1]
helpers::validate_uri(&topic)?;
helpers::validate_uri(&topic).map_err(|e| {
ServiceInvocationError::InvalidArgument(format!(
"Invalid topic uri '{topic}': {e}"
))
})?;
RequestKind::Topic(topic)
}
Some(Request::Subscriber(subscriber)) => {
if let Some(subscriber) = subscriber.uri.into_option() {
// [impl->dsn~usubscription-fetch-subscriptions-invalid-subscriber~1]
helpers::validate_uri(&subscriber)?;
helpers::validate_uri(&subscriber).map_err(|e| {
ServiceInvocationError::InvalidArgument(format!(
"Invalid subscriber uri '{subscriber}': {e}"
))
})?;
RequestKind::Subscriber(subscriber)
} else {
return Err(ServiceInvocationError::InvalidArgument(
Expand Down
64 changes: 64 additions & 0 deletions up-subscription/src/handlers/register_for_notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ impl RequestHandler for RegisterNotificationsRequestHandler {
"No topic defined in request".to_string(),
));
};
// [impl->dsn~usubscription-register-notifications-invalid-topic~1]
helpers::validate_uri(topic).map_err(|e| {
ServiceInvocationError::InvalidArgument(format!("Invalid topic uri '{topic}': {e}"))
})?;

// Interact with notification manager backend
let se = NotificationEvent::AddNotifyee {
Expand All @@ -84,8 +88,11 @@ impl RequestHandler for RegisterNotificationsRequestHandler {
#[cfg(test)]
mod tests {
use super::*;
use test_case::test_case;
use tokio::sync::mpsc::{self};

use up_rust::UUri;

use crate::{helpers, tests::test_lib};

// [utest->dsn~usubscription-register-notifications-protobuf~1]
Expand Down Expand Up @@ -259,4 +266,61 @@ mod tests {
_ => panic!("Wrong error type"),
}
}

// [utest->dsn~usubscription-register-notifications-invalid-topic~1]
#[test_case(UUri::default(); "Bad topic UUri")]
#[test_case(UUri {
authority_name: String::from("*"),
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
..Default::default()
}; "Wildcard authority in topic UUri")]
#[test_case(UUri {
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
ue_id: 0xFFFF_0000,
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
..Default::default()
}; "Wildcard entity id in topic UUri")]
#[test_case(UUri {
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
resource_id: 0x0000_FFFF,
..Default::default()
}; "Wildcard resource id in topic UUri")]
#[tokio::test]
async fn test_invalid_topic_uri(topic: UUri) {
helpers::init_once();

// create request and other required object(s)
let notification_request = NotificationsRequest {
topic: Some(topic).into(),
..Default::default()
};
let request_payload = UPayload::try_from_protobuf(notification_request.clone()).unwrap();
let message_attributes = UAttributes {
source: Some(test_lib::helpers::subscriber_uri1()).into(),
..Default::default()
};
let (notification_sender, _) = mpsc::channel::<NotificationEvent>(1);

// create and spawn off handler, to make all the asnync goodness work
let request_handler = RegisterNotificationsRequestHandler::new(notification_sender);

let result = request_handler
.handle_request(
RESOURCE_ID_REGISTER_FOR_NOTIFICATIONS,
&message_attributes,
Some(request_payload),
)
.await;

assert!(result.is_err());
match result.unwrap_err() {
ServiceInvocationError::InvalidArgument(_) => {}
_ => panic!("Wrong error type"),
}
}
}