Skip to content

Commit bea6f11

Browse files
Dsn usubscription fetch subscriptions invalid topic (eclipse-uprotocol#25)
* Implement dsn~usubscription-fetch-subscriptions-invalid-topic
1 parent 27c6130 commit bea6f11

File tree

1 file changed

+61
-7
lines changed

1 file changed

+61
-7
lines changed

up-subscription/src/handlers/fetch_subscriptions.rs

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ impl RequestHandler for FetchSubscriptionsRequestHandler {
6161
let FetchSubscriptionsRequest { request, .. } = fetch_subscriptions_request;
6262
let request_kind = match request {
6363
Some(Request::Topic(topic)) => {
64-
if !topic.is_empty() {
65-
RequestKind::Topic(topic)
66-
} else {
67-
return Err(ServiceInvocationError::InvalidArgument(
68-
"Empty topic in Request::Topic".to_string(),
69-
));
70-
}
64+
// [impl->dsn~usubscription-fetch-subscriptions-invalid-topic~1]
65+
helpers::validate_uri(&topic)?;
66+
RequestKind::Topic(topic)
7167
}
7268
Some(Request::Subscriber(subscriber)) => {
7369
if let Some(subscriber) = subscriber.uri.into_option() {
@@ -396,4 +392,62 @@ mod tests {
396392
_ => panic!("Wrong error type"),
397393
}
398394
}
395+
396+
// [utest->dsn~usubscription-fetch-subscriptions-invalid-topic~1]
397+
#[test_case(UUri::default(); "Bad topic UUri")]
398+
#[test_case(UUri {
399+
authority_name: String::from("*"),
400+
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
401+
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
402+
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
403+
..Default::default()
404+
}; "Wildcard authority in topic UUri")]
405+
#[test_case(UUri {
406+
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
407+
ue_id: 0xFFFF_0000,
408+
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
409+
resource_id: test_lib::helpers::TOPIC_LOCAL1_RESOURCE as u32,
410+
..Default::default()
411+
}; "Wildcard entity id in topic UUri")]
412+
#[test_case(UUri {
413+
authority_name: test_lib::helpers::LOCAL_AUTHORITY.into(),
414+
ue_id: test_lib::helpers::TOPIC_LOCAL1_ID,
415+
ue_version_major: test_lib::helpers::TOPIC_LOCAL1_VERSION as u32,
416+
resource_id: 0x0000_FFFF,
417+
..Default::default()
418+
}; "Wildcard resource id in topic UUri")]
419+
#[tokio::test]
420+
async fn test_invalid_topic_uri(topic: UUri) {
421+
helpers::init_once();
422+
423+
// create request and other required object(s)
424+
let fetch_subscriptions_request = FetchSubscriptionsRequest {
425+
request: Some(up_rust::core::usubscription::Request::Topic(topic)),
426+
..Default::default()
427+
};
428+
let request_payload =
429+
UPayload::try_from_protobuf(fetch_subscriptions_request.clone()).unwrap();
430+
let message_attributes = UAttributes {
431+
source: Some(test_lib::helpers::subscriber_uri1()).into(),
432+
..Default::default()
433+
};
434+
let (subscription_sender, _) = mpsc::channel::<SubscriptionEvent>(1);
435+
436+
// create handler and perform tested operation
437+
let request_handler = FetchSubscriptionsRequestHandler::new(subscription_sender);
438+
439+
let result = request_handler
440+
.handle_request(
441+
up_rust::core::usubscription::RESOURCE_ID_FETCH_SUBSCRIPTIONS,
442+
&message_attributes,
443+
Some(request_payload),
444+
)
445+
.await;
446+
447+
assert!(result.is_err());
448+
match result.unwrap_err() {
449+
ServiceInvocationError::InvalidArgument(_) => {}
450+
_ => panic!("Wrong error type"),
451+
}
452+
}
399453
}

0 commit comments

Comments
 (0)