From 204f19009014de2c1dedc953e8ec989e92cde64c Mon Sep 17 00:00:00 2001 From: Alex Snaps Date: Sat, 19 Oct 2024 08:46:06 -0400 Subject: [PATCH] ports are u64, not strings... this err'ed into Default Signed-off-by: Alex Snaps --- src/data/property.rs | 12 +++++-- tests/auth.rs | 56 ++++++++++++++--------------- tests/multi.rs | 84 ++++++++++++++++++++++---------------------- 3 files changed, 79 insertions(+), 73 deletions(-) diff --git a/src/data/property.rs b/src/data/property.rs index 864e6690..ace6db17 100644 --- a/src/data/property.rs +++ b/src/data/property.rs @@ -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>, Status> { // Ref https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-forwarded-for @@ -26,7 +26,7 @@ fn remote_address() -> Result>, Status> { } fn host_get_property(path: &Path) -> Result>, Status> { - debug!("get_property: path: {:?}", path); + debug!("get_property: {:?}", path); hostcalls::get_property(path.tokens()) } @@ -37,7 +37,7 @@ pub fn get_property(path: &Path) -> Result>, Status> { } } -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct Path { tokens: Vec, } @@ -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(); diff --git a/tests/auth.rs b/tests/auth.rs index 93d1c318..910d1ce4 100644 --- a/tests/auth.rs +++ b/tests/auth.rs @@ -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\"]"), @@ -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) @@ -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), ) @@ -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\"]"), @@ -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) @@ -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), ) diff --git a/tests/multi.rs b/tests/multi.rs index 14785218..df419437 100644 --- a/tests/multi.rs +++ b/tests/multi.rs @@ -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\"]"), @@ -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) @@ -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), ) @@ -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\"]"), @@ -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) @@ -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), ) @@ -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\"]"), @@ -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) @@ -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), )