Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect Onvif filter #604

Merged
merged 2 commits into from
Jun 1, 2023
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
58 changes: 58 additions & 0 deletions discovery-handlers/onvif/src/discovery_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,34 @@ mod tests {
.is_none());
}

#[tokio::test]
async fn test_apply_filters_include_ip_similar() {
let mock_uri = "device_uri";

let mut mock = MockOnvifQuery::new();
configure_scenario(
&mut mock,
Some(IpAndMac {
mock_uri,
mock_ip: "mock.ip",
mock_mac: "mock:mac",
}),
);

let onvif_config = OnvifDiscoveryDetails {
ip_addresses: Some(FilterList {
action: FilterType::Include,
items: vec!["mock.i".to_string()],
}),
mac_addresses: None,
scopes: None,
discovery_timeout_seconds: 1,
};
assert!(apply_filters(&onvif_config, mock_uri, &mock)
.await
.is_none());
}

#[tokio::test]
async fn test_apply_filters_exclude_ip_nonexist() {
let mock_uri = "device_uri";
Expand Down Expand Up @@ -409,6 +437,36 @@ mod tests {
.is_none());
}

#[tokio::test]
async fn test_apply_filters_exclude_ip_similar() {
let mock_uri = "device_uri";
let mock_ip = "mock.ip";
let mock_mac = "mock:mac";

let mut mock = MockOnvifQuery::new();
configure_scenario(
&mut mock,
Some(IpAndMac {
mock_uri,
mock_ip,
mock_mac,
}),
);

let onvif_config = OnvifDiscoveryDetails {
ip_addresses: Some(FilterList {
action: FilterType::Exclude,
items: vec!["mock.i".to_string()],
}),
mac_addresses: None,
scopes: None,
discovery_timeout_seconds: 1,
};
let instance = apply_filters(&onvif_config, mock_uri, &mock).await.unwrap();

assert_eq!(expected_device(mock_uri, mock_ip, mock_mac), instance);
}

#[tokio::test]
async fn test_apply_filters_include_mac_exist() {
let mock_uri = "device_uri";
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/onvif/src/discovery_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub mod util {
.filter(|pattern| {
filter_against
.iter()
.filter(|filter_against_item| filter_against_item.contains(*pattern))
.filter(|filter_against_item| filter_against_item == pattern)
.count()
> 0
})
Expand Down