Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
Address findings: change to grpc codes; fix naming
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmittag authored and SebastianSchildt committed Dec 11, 2023
1 parent 334d22d commit 1a3c946
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 48 deletions.
2 changes: 1 addition & 1 deletion kuksa_databroker/databroker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ vergen = { version = "8", features = [

[dev-dependencies]
anyhow = "1.0"
chrono = "^0.4"
cucumber = { version = "0.20", default-features = false, features = ["libtest", "macros"] }
chrono = { version = "0.4.31" }

[[test]]
name = "read_write_values"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,63 @@ Feature: Reading and writing values of a VSS Data Entry
Rule: Access with right permissions succeeds and fails with wrong/no permissions

Background:
Given a running Databroker server with authorization true with the following Data Entries registered
Given a running Databroker server with authorization enabled with the following Data Entries registered
| path | data type | change type | type |
| Vehicle.Speed | float | Static | Sensor |
| Vehicle.ADAS.ABS.IsEnabled | bool | Static | Actuator |

Scenario: Write the current value of an unset Data Entry without authenticating fails
Scenario: Writing the current value of an unset Data Entry without authenticating fails
When a client sets the current value of Vehicle.Width of type float to 13.4
Then the current value for Vehicle.Width can not be accessed because we are unauthorized
Then the operation fails with status code 16

Scenario: Read the current value of an unset Data Entry without authenticating fails
When a client gets the current value of Vehicle.Width
Then the current value for Vehicle.Width can not be accessed because we are unauthorized
Then the operation fails with status code 16

Scenario: Write the current value of a Data Entry without right permissions fails
When a client uses a token with auhtorization read
Scenario: Writing the current value of a Data Entry without right permissions fails
When a client uses a token with scope read
And a client sets the current value of Vehicle.Speed of type float to 13.4
Then setting the value for Vehicle.Speed fails with error code 403

Scenario: Write the current value of a Data Entry without right permissions fails
When a client uses a token with auhtorization actuate
Scenario: Writing the current value of a Data Entry without right permissions fails
When a client uses a token with scope actuate
And a client sets the current value of Vehicle.Speed of type float to 13.4
Then setting the value for Vehicle.Speed fails with error code 403

Scenario: Write the current value of a Data Entry without right permissions fails
When a client uses a token with auhtorization provide:Vehicle.ADAS.ABS.IsEnabled
Scenario: Writing the current value of a Data Entry without right permissions fails
When a client uses a token with scope provide:Vehicle.ADAS.ABS.IsEnabled
And a client sets the current value of Vehicle.Speed of type float to 13.4
Then setting the value for Vehicle.Speed fails with error code 403

Scenario: Write the current value of a Data Entry with right permissions succeeds
When a client uses a token with auhtorization provide:Vehicle.Speed
Scenario: Writing the current value of a Data Entry with right permissions succeeds
When a client uses a token with scope provide:Vehicle.Speed
And a client sets the current value of Vehicle.Speed of type float to 13.4
Then the set operation succeeds without an error
Then the set operation succeeds

Scenario: Write the target value of a Data Entry without right permissions fails
When a client uses a token with auhtorization read
Scenario: Writing the target value of a Data Entry without right permissions fails
When a client uses a token with scope read
And a client sets the target value of Vehicle.ADAS.ABS.IsEnabled of type bool to true
Then setting the value for Vehicle.Speed fails with error code 403

Scenario: Write the target value of a Data Entry without right permissions fails
When a client uses a token with auhtorization provide
Scenario: Writing the target value of a Data Entry without right permissions fails
When a client uses a token with scope provide
And a client sets the target value of Vehicle.ADAS.ABS.IsEnabled of type bool to true
Then setting the value for Vehicle.Speed fails with error code 403

Scenario: Write the target value of a Data Entry without right permissions fails
When a client uses a token with auhtorization actuate:Vehicle.Speed
Scenario: Writing the target value of a Data Entry without right permissions fails
When a client uses a token with scope actuate:Vehicle.Speed
And a client sets the target value of Vehicle.ADAS.ABS.IsEnabled of type bool to true
Then setting the value for Vehicle.Speed fails with error code 403

Scenario: Write the target value of a Data Entry with right permissions succeeds
When a client uses a token with auhtorization actuate:Vehicle.ADAS.ABS.IsEnabled
Scenario: Writing the target value of a Data Entry with right permissions succeeds
When a client uses a token with scope actuate:Vehicle.ADAS.ABS.IsEnabled
And a client sets the target value of Vehicle.ADAS.ABS.IsEnabled of type bool to true
Then the set operation succeeds without an error
Then the set operation succeeds

Rule: Accessing unregistered Data Entries fails

Background:
Given a running Databroker server with authorization false
Given a running Databroker server with authorization disabled

Scenario: Setting the current value of an unregistered Data Entry fails
When a client sets the current value of No.Such.Path of type float to 13.4
Expand All @@ -80,7 +80,7 @@ Feature: Reading and writing values of a VSS Data Entry
Rule: Target values can only be set on Actuators

Background:
Given a running Databroker server with authorization false with the following Data Entries registered
Given a running Databroker server with authorization disabled with the following Data Entries registered
| path | data type | change type | type |
| Vehicle.Powertrain.Range | uint32 | Continuous | Sensor |
| Vehicle.Width | uint16 | Static | Attribute |
Expand All @@ -96,7 +96,7 @@ Feature: Reading and writing values of a VSS Data Entry
Rule: Accessing registered Data Entries works

Background:
Given a running Databroker server with authorization false with the following Data Entries registered
Given a running Databroker server with authorization disabled with the following Data Entries registered
| path | data type | change type | type |
| Vehicle.Cabin.Lights.AmbientLight | uint8 | OnChange | Actuator |
| Vehicle.Cabin.Sunroof.Position | int8 | OnChange | Actuator |
Expand Down
34 changes: 14 additions & 20 deletions kuksa_databroker/databroker/tests/read_write_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
use core::panic;
use std::{collections::HashMap, future, time::SystemTime, vec};

use common::ClientError;
use cucumber::{cli, gherkin::Step, given, then, when, writer, World as _};
use databroker::broker;
use databroker_proto::kuksa::val::v1::{datapoint::Value, DataType, Datapoint};
use tonic::Code;
use tracing::debug;
use world::{DataBrokerWorld, ValueType};

Expand Down Expand Up @@ -74,9 +72,18 @@ fn get_data_entries_from_table(
data_entries
}

#[given(regex = "^a running Databroker server with authorization (true|false).*$")]
async fn start_databroker_server(w: &mut DataBrokerWorld, auth: bool, step: &Step) {
w.start_databroker(get_data_entries_from_table(step), auth)
#[given(regex = "^a running Databroker server with authorization (enabled|disabled).*$")]
async fn start_databroker_server(w: &mut DataBrokerWorld, auth: String, step: &Step) {
let authorization_enabled: bool;
if auth == "enabled" {
authorization_enabled = true;
} else if auth == "disabled" {
authorization_enabled = false;
} else {
panic!("Not a known authorization keyword use enabled/disabled!")
}

w.start_databroker(get_data_entries_from_table(step), authorization_enabled)
.await;
assert!(w.broker_client.is_some())
}
Expand All @@ -93,7 +100,7 @@ async fn a_known_data_entry_has_value(
w.assert_set_succeeded()
}

#[when(expr = "a client uses a token with auhtorization {word}")]
#[when(expr = "a client uses a token with scope {word}")]
async fn authorize_client(w: &mut DataBrokerWorld, scope: String) {
let token = w.create_token(scope);
w.broker_client
Expand Down Expand Up @@ -244,20 +251,7 @@ fn assert_request_failure(w: &mut DataBrokerWorld, expected_status_code: i32) {
w.assert_status_has_code(expected_status_code)
}

#[then(expr = "the current value for {word} can not be accessed because we are unauthorized")]
fn assert_current_value_unauthenticated(w: &mut DataBrokerWorld) {
if let Some(error) = w.current_client_error.clone() {
match error {
ClientError::Connection(e) => {
panic!("No connection error {:?} should occcur", e)
}
ClientError::Function(e) => panic!("No function error {:?} should occur", e),
ClientError::Status(status) => assert_eq!(status.code(), Code::Unauthenticated),
}
}
}

#[then(expr = "the set operation succeeds without an error")]
#[then(expr = "the set operation succeeds")]
fn assert_set_succeeds(w: &mut DataBrokerWorld) {
w.assert_set_succeeded()
}
Expand Down
4 changes: 2 additions & 2 deletions kuksa_databroker/databroker/tests/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl DataBrokerWorld {
}
}

pub fn create_token(&self, _scope: String) -> String {
pub fn create_token(&self, scope: String) -> String {
let datetime = Utc::now();
let timestamp = datetime.timestamp();
let timestamp_exp = (match datetime.checked_add_months(chrono::Months::new(24)) {
Expand All @@ -386,7 +386,7 @@ impl DataBrokerWorld {
aud: vec!["kuksa.val".to_string()],
iat: timestamp,
exp: timestamp_exp,
scope: _scope,
scope,
};

// Create an encoding key from the private key
Expand Down

0 comments on commit 1a3c946

Please sign in to comment.