Skip to content

Commit

Permalink
correct onvif filters (#622)
Browse files Browse the repository at this point in the history
* correct filters

Signed-off-by: Johnson Shih <[email protected]>

* Update patch version

Signed-off-by: Johnson Shih <[email protected]>

* correct how scope is matched

Signed-off-by: Johnson Shih <[email protected]>

* add more test cases

Signed-off-by: Johnson Shih <[email protected]>

* case-insensitive comparison for ip address

Signed-off-by: Johnson Shih <[email protected]>

* utility functions for ut

Signed-off-by: Johnson Shih <[email protected]>

* Update patch version

Signed-off-by: Johnson Shih <[email protected]>

* rename test function name

Signed-off-by: Johnson Shih <[email protected]>

---------

Signed-off-by: Johnson Shih <[email protected]>
  • Loading branch information
johnsonshih authored Jun 22, 2023
1 parent 59a2699 commit 3c8c62f
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 49 deletions.
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "agent"
version = "0.10.13"
version = "0.10.14"
authors = ["Kate Goldenring <[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion controller/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "controller"
version = "0.10.13"
version = "0.10.14"
authors = ["<[email protected]>", "<[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
4 changes: 2 additions & 2 deletions deployment/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.10.13
version: 0.10.14

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 0.10.13
appVersion: 0.10.14
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "debug-echo-discovery-handler"
version = "0.10.13"
version = "0.10.14"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "onvif-discovery-handler"
version = "0.10.13"
version = "0.10.14"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opcua-discovery-handler"
version = "0.10.13"
version = "0.10.14"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udev-discovery-handler"
version = "0.10.13"
version = "0.10.14"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/debug-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-debug-echo"
version = "0.10.13"
version = "0.10.14"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
2 changes: 1 addition & 1 deletion discovery-handlers/onvif/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "akri-onvif"
version = "0.10.13"
version = "0.10.14"
authors = ["Kate Goldenring <[email protected]>"]
edition = "2018"
rust-version = "1.68.1"
Expand Down
63 changes: 63 additions & 0 deletions discovery-handlers/onvif/src/discovery_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,12 @@ async fn apply_filters(
}
};
// Evaluate camera ip address against ip filter if provided
// use case-insensitive comparison in case of IPv6 is used
let ip_address_as_vec = vec![ip_address.clone()];
if util::execute_filter(
discovery_handler_config.ip_addresses.as_ref(),
&ip_address_as_vec,
|scope, pattern| scope.to_lowercase() == pattern.to_lowercase(),
) {
return None;
}
Expand All @@ -177,6 +179,7 @@ async fn apply_filters(
if util::execute_filter(
discovery_handler_config.mac_addresses.as_ref(),
&mac_address_as_vec,
|scope, pattern| scope.to_lowercase() == pattern.to_lowercase(),
) {
return None;
}
Expand Down Expand Up @@ -583,4 +586,64 @@ mod tests {
.await
.is_none());
}

#[tokio::test]
async fn test_apply_filters_include_mac_exist_different_letter_cases() {
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: None,
mac_addresses: Some(FilterList {
action: FilterType::Include,
items: vec![mock_mac.to_uppercase()],
}),
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_exclude_mac_exist_different_letter_cases() {
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: None,
mac_addresses: Some(FilterList {
action: FilterType::Exclude,
items: vec![mock_mac.to_uppercase()],
}),
scopes: None,
discovery_timeout_seconds: 1,
};
assert!(apply_filters(&onvif_config, mock_uri, &mock)
.await
.is_none());
}
}
Loading

0 comments on commit 3c8c62f

Please sign in to comment.