Skip to content

Commit

Permalink
Fix tests using header resolver
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Cattermole <[email protected]>
  • Loading branch information
adam-cattermole committed Aug 22, 2024
1 parent 2cc7eb9 commit 22945a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ impl HeaderResolver {
for header in TracingHeader::all() {
if let Some(value) =
hostcalls::get_map_value_bytes(MapType::HttpRequestHeaders, header.as_str())
.unwrap()
.ok()
.and_then(|opt| opt)
{
headers.push((header.as_str().to_owned(), value));
}
Expand Down
25 changes: 7 additions & 18 deletions tests/rate_limited.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use proxy_wasm::types::Status::NotFound;

Check failure on line 1 in tests/rate_limited.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused import: `proxy_wasm::types::Status::NotFound`

Check warning on line 1 in tests/rate_limited.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `proxy_wasm::types::Status::NotFound`
use proxy_wasm_test_framework::tester;
use proxy_wasm_test_framework::types::{Action, BufferType, LogLevel, MapType, ReturnType};
use serial_test::serial;
Expand Down Expand Up @@ -57,12 +58,6 @@ fn it_loads() {
module
.call_proxy_on_request_headers(http_context, 0, false)
.expect_log(Some(LogLevel::Debug), Some("#2 on_http_request_headers"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("tracestate"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("baggage"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("cars.toystore.com"))
.expect_log(
Expand Down Expand Up @@ -161,14 +156,14 @@ fn it_limits() {
module
.call_proxy_on_request_headers(http_context, 0, false)
.expect_log(Some(LogLevel::Debug), Some("#2 on_http_request_headers"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("cars.toystore.com"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("tracestate"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("baggage"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("cars.toystore.com"))
.expect_get_property(Some(vec!["request", "url_path"]))
.returning(Some("/admin/toy".as_bytes()))
.expect_get_property(Some(vec!["request", "host"]))
Expand Down Expand Up @@ -299,14 +294,14 @@ fn it_passes_additional_headers() {
module
.call_proxy_on_request_headers(http_context, 0, false)
.expect_log(Some(LogLevel::Debug), Some("#2 on_http_request_headers"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("cars.toystore.com"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("tracestate"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("baggage"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("cars.toystore.com"))
.expect_get_property(Some(vec!["request", "url_path"]))
.returning(Some("/admin/toy".as_bytes()))
.expect_get_property(Some(vec!["request", "host"]))
Expand Down Expand Up @@ -431,14 +426,14 @@ fn it_rate_limits_with_empty_conditions() {
module
.call_proxy_on_request_headers(http_context, 0, false)
.expect_log(Some(LogLevel::Debug), Some("#2 on_http_request_headers"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("a.com"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("tracestate"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("baggage"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("a.com"))
.expect_log(
Some(LogLevel::Debug),
Some("#2 ratelimitpolicy selected some-name"),
Expand Down Expand Up @@ -542,12 +537,6 @@ fn it_does_not_rate_limits_when_selector_does_not_exist_and_misses_default_value
module
.call_proxy_on_request_headers(http_context, 0, false)
.expect_log(Some(LogLevel::Debug), Some("#2 on_http_request_headers"))
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("traceparent"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("tracestate"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some("baggage"))
.returning(None)
.expect_get_header_map_value(Some(MapType::HttpRequestHeaders), Some(":authority"))
.returning(Some("a.com"))
.expect_get_property(Some(vec!["unknown", "path"]))
Expand Down

0 comments on commit 22945a9

Please sign in to comment.