diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index 065ac37a..3569ca05 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -4,7 +4,7 @@ name: Rust on: push: branches: - - '*' + - 'main' pull_request: branches: - '*' @@ -30,27 +30,6 @@ jobs: with: command: check args: --release --target wasm32-unknown-unknown - test: - name: Test Suite - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - target: wasm32-unknown-unknown - - uses: arduino/setup-protoc@v1 - with: - version: '3.x' - - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --target wasm32-unknown-unknown - - uses: actions-rs/cargo@v1 - with: - command: test fmt: name: Rustfmt runs-on: ubuntu-latest diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..81cfa566 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,33 @@ +--- +name: Tests + +on: + push: + branches: + - 'main' + pull_request: + branches: + - '*' + +jobs: + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + target: wasm32-unknown-unknown + - uses: arduino/setup-protoc@v1 + with: + version: '3.x' + - uses: actions-rs/cargo@v1 + with: + command: build + args: --release --target wasm32-unknown-unknown + - uses: actions-rs/cargo@v1 + with: + command: test diff --git a/Cargo.lock b/Cargo.lock index 1ff0afd9..a5ab73cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1088,7 +1088,7 @@ dependencies = [ [[package]] name = "proxy-wasm-test-framework" version = "0.1.0" -source = "git+https://github.com/Kuadrant/wasm-test-framework.git?branch=kuadrant#29d5ac35bb0c11c642e5fae3ca3f33d409505112" +source = "git+https://github.com/Kuadrant/wasm-test-framework.git?branch=kuadrant#63433eae9ef47f6297a30dc6bfe9f8fe6493a8e7" dependencies = [ "anyhow", "lazy_static", diff --git a/src/filter/http_context.rs b/src/filter/http_context.rs index ebb27f1a..62259b67 100644 --- a/src/filter/http_context.rs +++ b/src/filter/http_context.rs @@ -237,11 +237,11 @@ impl HttpContext for Filter { info!("on_http_request_headers #{}", self.context_id); for header in TracingHeader::all() { - match self.get_http_request_header_bytes(header.as_str()) { - Some(value) => self.tracing_headers.push((header, value)), - None => (), + if let Some(value) = self.get_http_request_header_bytes(header.as_str()) { + self.tracing_headers.push((header, value)) } } + match self .config .index diff --git a/tests/rate_limited.rs b/tests/rate_limited.rs index 7376598b..53c7675e 100644 --- a/tests/rate_limited.rs +++ b/tests/rate_limited.rs @@ -57,6 +57,12 @@ fn it_loads() { module .call_proxy_on_request_headers(http_context, 0, false) .expect_log(Some(LogLevel::Info), Some("on_http_request_headers #2")) + .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( @@ -155,6 +161,12 @@ fn it_limits() { module .call_proxy_on_request_headers(http_context, 0, false) .expect_log(Some(LogLevel::Info), Some("on_http_request_headers #2")) + .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"])) @@ -283,6 +295,12 @@ fn it_passes_additional_headers() { module .call_proxy_on_request_headers(http_context, 0, false) .expect_log(Some(LogLevel::Info), Some("on_http_request_headers #2")) + .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"])) @@ -405,6 +423,12 @@ fn it_rate_limits_with_empty_conditions() { module .call_proxy_on_request_headers(http_context, 0, false) .expect_log(Some(LogLevel::Info), Some("on_http_request_headers #2")) + .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_grpc_call( @@ -506,6 +530,12 @@ 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::Info), Some("on_http_request_headers #2")) + .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"]))