Skip to content

Commit

Permalink
ports are u64, not strings... this err'ed into Default
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Snaps <[email protected]>
  • Loading branch information
alexsnaps committed Oct 19, 2024
1 parent c2f86c7 commit 204f190
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 73 deletions.
12 changes: 9 additions & 3 deletions src/data/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use log::debug;
use log::warn;
use proxy_wasm::hostcalls;
use proxy_wasm::types::Status;
use std::fmt::{Display, Formatter};
use std::fmt::{Debug, Display, Formatter};

fn remote_address() -> Result<Option<Vec<u8>>, Status> {
// Ref https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-forwarded-for
Expand All @@ -26,7 +26,7 @@ fn remote_address() -> Result<Option<Vec<u8>>, Status> {
}

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

Expand All @@ -37,7 +37,7 @@ pub fn get_property(path: &Path) -> Result<Option<Vec<u8>>, Status> {
}
}

#[derive(Debug, Clone)]
#[derive(Clone)]
pub struct Path {
tokens: Vec<String>,
}
Expand All @@ -56,6 +56,12 @@ impl Display for Path {
}
}

impl Debug for Path {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "path: {:?}", self.tokens)
}
}

impl From<&str> for Path {
fn from(value: &str) -> Self {
let mut token = String::new();
Expand Down
56 changes: 28 additions & 28 deletions tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn it_auths() {
Some("get_property: path: [\"destination\", \"port\"]"),
)
.expect_get_property(Some(vec!["destination", "port"]))
.returning(Some("8000".as_bytes()))
.returning(Some(&8000u64.to_le_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: path: [\"source\", \"address\"]"),
Expand All @@ -172,7 +172,7 @@ fn it_auths() {
Some("get_property: path: [\"source\", \"port\"]"),
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some("45000".as_bytes()))
.returning(Some(&45000u64.to_le_bytes()))
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -186,18 +186,18 @@ fn it_auths() {
Some("Check"),
Some(&[0, 0, 0, 0]),
Some(&[
10, 217, 1, 10, 23, 10, 21, 10, 19, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 0, 18, 22, 10, 20, 10, 18, 18, 14, 49, 50, 55, 46, 48, 46,
48, 46, 49, 58, 56, 48, 48, 48, 24, 0, 34, 141, 1, 10, 0, 18, 136, 1, 18, 3, 71,
69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97,
98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10,
7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97,
116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117,
101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10,
47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116,
111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82,
4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, 116, 104,
99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
]),
Some(5000),
)
Expand Down Expand Up @@ -355,7 +355,7 @@ fn it_denies() {
Some("get_property: path: [\"destination\", \"port\"]"),
)
.expect_get_property(Some(vec!["destination", "port"]))
.returning(Some("8000".as_bytes()))
.returning(Some(&8000u64.to_le_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: path: [\"source\", \"address\"]"),
Expand All @@ -367,7 +367,7 @@ fn it_denies() {
Some("get_property: path: [\"source\", \"port\"]"),
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some("45000".as_bytes()))
.returning(Some(&45000u64.to_le_bytes()))
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -381,18 +381,18 @@ fn it_denies() {
Some("Check"),
Some(&[0, 0, 0, 0]),
Some(&[
10, 217, 1, 10, 23, 10, 21, 10, 19, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 0, 18, 22, 10, 20, 10, 18, 18, 14, 49, 50, 55, 46, 48, 46,
48, 46, 49, 58, 56, 48, 48, 48, 24, 0, 34, 141, 1, 10, 0, 18, 136, 1, 18, 3, 71,
69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97,
98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10,
7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97,
116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117,
101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10,
47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116,
111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82,
4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, 116, 104,
99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
]),
Some(5000),
)
Expand Down
84 changes: 42 additions & 42 deletions tests/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn it_performs_authenticated_rate_limiting() {
Some("get_property: path: [\"destination\", \"port\"]"),
)
.expect_get_property(Some(vec!["destination", "port"]))
.returning(Some("8000".as_bytes()))
.returning(Some(&8000u64.to_le_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: path: [\"source\", \"address\"]"),
Expand All @@ -190,7 +190,7 @@ fn it_performs_authenticated_rate_limiting() {
Some("get_property: path: [\"source\", \"port\"]"),
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some("45000".as_bytes()))
.returning(Some(&45000u64.to_le_bytes()))
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -204,18 +204,18 @@ fn it_performs_authenticated_rate_limiting() {
Some("Check"),
Some(&[0, 0, 0, 0]),
Some(&[
10, 217, 1, 10, 23, 10, 21, 10, 19, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 0, 18, 22, 10, 20, 10, 18, 18, 14, 49, 50, 55, 46, 48, 46,
48, 46, 49, 58, 56, 48, 48, 48, 24, 0, 34, 141, 1, 10, 0, 18, 136, 1, 18, 3, 71,
69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97,
98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10,
7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97,
116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117,
101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10,
47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116,
111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82,
4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, 116, 104,
99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
]),
Some(5000),
)
Expand Down Expand Up @@ -391,7 +391,7 @@ fn unauthenticated_does_not_ratelimit() {
Some("get_property: path: [\"destination\", \"port\"]"),
)
.expect_get_property(Some(vec!["destination", "port"]))
.returning(Some("8000".as_bytes()))
.returning(Some(&8000u64.to_le_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: path: [\"source\", \"address\"]"),
Expand All @@ -403,7 +403,7 @@ fn unauthenticated_does_not_ratelimit() {
Some("get_property: path: [\"source\", \"port\"]"),
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some("45000".as_bytes()))
.returning(Some(&45000u64.to_le_bytes()))
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -417,18 +417,18 @@ fn unauthenticated_does_not_ratelimit() {
Some("Check"),
Some(&[0, 0, 0, 0]),
Some(&[
10, 217, 1, 10, 23, 10, 21, 10, 19, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 0, 18, 22, 10, 20, 10, 18, 18, 14, 49, 50, 55, 46, 48, 46,
48, 46, 49, 58, 56, 48, 48, 48, 24, 0, 34, 141, 1, 10, 0, 18, 136, 1, 18, 3, 71,
69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97,
98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10,
7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97,
116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117,
101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10,
47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116,
111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82,
4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, 116, 104,
99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
10, 220, 1, 10, 25, 10, 23, 10, 21, 18, 15, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58,
52, 53, 48, 48, 48, 24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55,
46, 48, 46, 48, 46, 49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18,
136, 1, 18, 3, 71, 69, 84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105,
116, 121, 18, 16, 97, 98, 105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101,
115, 115, 26, 14, 10, 7, 58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26,
38, 10, 5, 58, 112, 97, 116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47,
114, 101, 113, 117, 101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112,
97, 116, 104, 34, 10, 47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99,
97, 114, 115, 46, 116, 111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4,
104, 116, 116, 112, 82, 4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18,
12, 97, 117, 116, 104, 99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
]),
Some(5000),
)
Expand Down Expand Up @@ -681,7 +681,7 @@ fn authenticated_one_ratelimit_action_matches() {
Some("get_property: path: [\"destination\", \"port\"]"),
)
.expect_get_property(Some(vec!["destination", "port"]))
.returning(Some("8000".as_bytes()))
.returning(Some(&8000u64.to_le_bytes()))
.expect_log(
Some(LogLevel::Debug),
Some("get_property: path: [\"source\", \"address\"]"),
Expand All @@ -693,7 +693,7 @@ fn authenticated_one_ratelimit_action_matches() {
Some("get_property: path: [\"source\", \"port\"]"),
)
.expect_get_property(Some(vec!["source", "port"]))
.returning(Some("45000".as_bytes()))
.returning(Some(&45000u64.to_le_bytes()))
// retrieving tracing headers
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
Expand All @@ -707,18 +707,18 @@ fn authenticated_one_ratelimit_action_matches() {
Some("Check"),
Some(&[0, 0, 0, 0]),
Some(&[
10, 212, 1, 10, 18, 10, 16, 10, 14, 18, 10, 49, 46, 50, 46, 51, 46, 52, 58, 56, 48,
24, 0, 18, 22, 10, 20, 10, 18, 18, 14, 49, 50, 55, 46, 48, 46, 48, 46, 49, 58, 56,
48, 48, 48, 24, 0, 34, 141, 1, 10, 0, 18, 136, 1, 18, 3, 71, 69, 84, 26, 30, 10,
10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97, 98, 105, 95, 116,
101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10, 7, 58, 109, 101,
116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97, 116, 104, 18,
29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117, 101, 115, 116,
47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10, 47, 97, 100,
109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116, 111, 121, 115,
116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82, 4, 72, 84, 84,
80, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, 116, 104, 99, 111, 110,
102, 105, 103, 45, 65, 90, 0,
10, 215, 1, 10, 20, 10, 18, 10, 16, 18, 10, 49, 46, 50, 46, 51, 46, 52, 58, 56, 48,
24, 200, 223, 2, 18, 23, 10, 21, 10, 19, 18, 14, 49, 50, 55, 46, 48, 46, 48, 46,
49, 58, 56, 48, 48, 48, 24, 192, 62, 34, 141, 1, 10, 0, 18, 136, 1, 18, 3, 71, 69,
84, 26, 30, 10, 10, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 18, 16, 97, 98,
105, 95, 116, 101, 115, 116, 95, 104, 97, 114, 110, 101, 115, 115, 26, 14, 10, 7,
58, 109, 101, 116, 104, 111, 100, 18, 3, 71, 69, 84, 26, 38, 10, 5, 58, 112, 97,
116, 104, 18, 29, 47, 100, 101, 102, 97, 117, 108, 116, 47, 114, 101, 113, 117,
101, 115, 116, 47, 104, 101, 97, 100, 101, 114, 115, 47, 112, 97, 116, 104, 34, 10,
47, 97, 100, 109, 105, 110, 47, 116, 111, 121, 42, 17, 99, 97, 114, 115, 46, 116,
111, 121, 115, 116, 111, 114, 101, 46, 99, 111, 109, 50, 4, 104, 116, 116, 112, 82,
4, 72, 84, 84, 80, 82, 20, 10, 4, 104, 111, 115, 116, 18, 12, 97, 117, 116, 104,
99, 111, 110, 102, 105, 103, 45, 65, 90, 0,
]),
Some(5000),
)
Expand Down

0 comments on commit 204f190

Please sign in to comment.