Skip to content

Commit

Permalink
remote_address: fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Eguzki Astiz Lezaun <eastizle@redhat.com>
  • Loading branch information
eguzki committed Oct 16, 2024
1 parent 496ae82 commit 7cdd953
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 10 deletions.
9 changes: 0 additions & 9 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,6 @@ mod test {
selector: "request.id".to_string(),
operator: WhenConditionOperator::Equal,
value: "request_id".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1140,7 +1139,6 @@ mod test {
selector: "request.id".to_string(),
operator: WhenConditionOperator::Equal,
value: "\"request_id\"".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1158,7 +1156,6 @@ mod test {
selector: "request.id".to_string(),
operator: WhenConditionOperator::Equal,
value: "123".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1176,7 +1173,6 @@ mod test {
selector: "foobar".to_string(),
operator: WhenConditionOperator::Equal,
value: "\"123\"".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1194,7 +1190,6 @@ mod test {
selector: "destination.port".to_string(),
operator: WhenConditionOperator::Equal,
value: "8080".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1212,7 +1207,6 @@ mod test {
selector: "foobar".to_string(),
operator: WhenConditionOperator::Equal,
value: "8080".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1230,7 +1224,6 @@ mod test {
selector: "foobar".to_string(),
operator: WhenConditionOperator::Equal,
value: "1.0".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1248,7 +1241,6 @@ mod test {
selector: "connection.mtls".to_string(),
operator: WhenConditionOperator::Equal,
value: "true".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand All @@ -1266,7 +1258,6 @@ mod test {
selector: "request.time".to_string(),
operator: WhenConditionOperator::Equal,
value: "2023-05-28T00:00:00+00:00".to_string(),
path: Default::default(),
compiled: Default::default(),
};
p.compile().expect("Should compile fine!");
Expand Down
6 changes: 5 additions & 1 deletion src/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ fn remote_address() -> Result<Option<Vec<u8>>, Status> {

fn host_get_property(property: &str) -> Result<Option<Vec<u8>>, Status> {
let path = Path::from(property);
debug!("get_property: property: {} path: {}", property, path);
debug!(
"get_property: selector: {} path: {:?}",
property,
path.tokens()
);
hostcalls::get_property(path.tokens())
}

Expand Down
84 changes: 84 additions & 0 deletions tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,66 @@ fn it_auths() {
// retrieving properties for CheckRequest
.expect_get_header_map_pairs(Some(MapType::HttpRequestHeaders))
.returning(None)
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.host path: [\"request\", \"host\"]"),
)
.expect_get_property(Some(vec!["request", "host"]))
.returning(Some("cars.toystore.com".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.method path: [\"request\", \"method\"]"),
)
.expect_get_property(Some(vec!["request", "method"]))
.returning(Some("GET".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.scheme path: [\"request\", \"scheme\"]"),
)
.expect_get_property(Some(vec!["request", "scheme"]))
.returning(Some("http".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.path path: [\"request\", \"path\"]"),
)
.expect_get_property(Some(vec!["request", "path"]))
.returning(Some("/admin/toy".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.protocol path: [\"request\", \"protocol\"]"),
)
.expect_get_property(Some(vec!["request", "protocol"]))
.returning(Some("HTTP".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.time path: [\"request\", \"time\"]"),
)
.expect_get_property(Some(vec!["request", "time"]))
.returning(None)
.expect_log(
Some(LogLevel::Debug),
Some(
"get_property: selector: destination.address path: [\"destination\", \"address\"]",
),
)
.expect_get_property(Some(vec!["destination", "address"]))
.returning(Some("127.0.0.1:8000".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: destination.port path: [\"destination\", \"port\"]"),
)
.expect_get_property(Some(vec!["destination", "port"]))
.returning(Some("8000".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: source.address path: [\"source\", \"address\"]"),
)
.expect_get_property(Some(vec!["source", "address"]))
.returning(Some("127.0.0.1:45000".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: source.port path: [\"source\", \"port\"]"),
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some("45000".as_bytes()))
// retrieving tracing headers
Expand Down Expand Up @@ -266,24 +308,66 @@ fn it_denies() {
// retrieving properties for CheckRequest
.expect_get_header_map_pairs(Some(MapType::HttpRequestHeaders))
.returning(None)
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.host path: [\"request\", \"host\"]"),
)
.expect_get_property(Some(vec!["request", "host"]))
.returning(Some("cars.toystore.com".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.method path: [\"request\", \"method\"]"),
)
.expect_get_property(Some(vec!["request", "method"]))
.returning(Some("GET".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.scheme path: [\"request\", \"scheme\"]"),
)
.expect_get_property(Some(vec!["request", "scheme"]))
.returning(Some("http".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.path path: [\"request\", \"path\"]"),
)
.expect_get_property(Some(vec!["request", "path"]))
.returning(Some("/admin/toy".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.protocol path: [\"request\", \"protocol\"]"),
)
.expect_get_property(Some(vec!["request", "protocol"]))
.returning(Some("HTTP".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: request.time path: [\"request\", \"time\"]"),
)
.expect_get_property(Some(vec!["request", "time"]))
.returning(None)
.expect_log(
Some(LogLevel::Debug),
Some(
"get_property: selector: destination.address path: [\"destination\", \"address\"]",
),
)
.expect_get_property(Some(vec!["destination", "address"]))
.returning(Some("127.0.0.1:8000".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: destination.port path: [\"destination\", \"port\"]"),
)
.expect_get_property(Some(vec!["destination", "port"]))
.returning(Some("8000".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: source.address path: [\"source\", \"address\"]"),
)
.expect_get_property(Some(vec!["source", "address"]))
.returning(Some("127.0.0.1:45000".as_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: selector: source.port path: [\"source\", \"port\"]"),
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some("45000".as_bytes()))
// retrieving tracing headers
Expand Down

0 comments on commit 7cdd953

Please sign in to comment.