Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.wasm32-wasip1]
rustflags = ["-C", "link-arg=--allow-undefined"]
2 changes: 1 addition & 1 deletion src/data/cel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl Expression {
})
.collect();

attributes.sort_by(|a, b| a.path.tokens().len().cmp(&b.path.tokens().len()));
attributes.sort_by_key(|a| a.path.tokens().len());

Ok(Self {
attributes,
Expand Down
11 changes: 10 additions & 1 deletion src/filter/kuadrant_filter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::kuadrant::{Pipeline, PipelineFactory, PipelineState, ReqRespCtx};
use crate::metrics::METRICS;
use proxy_wasm::hostcalls;
use proxy_wasm::traits::{Context, HttpContext};
use proxy_wasm::types::Action;
use std::ops::Not;
Expand Down Expand Up @@ -122,7 +123,15 @@ impl HttpContext for KuadrantFilter {
Err(e) => {
error!("#{} failed to build pipeline: {:?}", self.context_id, e);
METRICS.errors().increment();
// todo(adam-cattermole): we should deny the request
#[allow(clippy::panic)]
hostcalls::send_http_response(500, Default::default(), Some(b"Internal Server Error.\n"))
.unwrap_or_else(|err| {
error!(
"#{} CRITICAL: Failed to send error response: {:?}. WASM runtime is in an invalid state",
self.context_id, err
);
panic!("CRITICAL: Failed to send HTTP reply after pipeline build failure");
});
Action::Continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/kuadrant/pipeline/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Pipeline {
}

pub fn eval(mut self) -> PipelineState {
let tasks_to_process: Vec<_> = self.task_queue.drain(..).collect();
let tasks_to_process: Vec<_> = std::mem::take(&mut self.task_queue);

for task in tasks_to_process {
if task
Expand Down
37 changes: 35 additions & 2 deletions src/kuadrant/pipeline/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl TryFrom<PluginConfiguration> for PipelineFactory {

let blueprint = Rc::new(blueprint);
for hostname in &config_action_set.route_rule_conditions.hostnames {
let key = reverse_subdomain(hostname);
let key = reverse_subdomain(&hostname.to_ascii_lowercase());
index.map_with_default(
key,
|blueprints| blueprints.push(Rc::clone(&blueprint)),
Expand Down Expand Up @@ -189,7 +189,7 @@ impl PipelineFactory {
match ctx.get_attribute::<String>("request.host") {
Ok(AttributeState::Available(Some(host))) => {
let split_host = host.split_once(':').map_or(host.as_str(), |(h, _)| h);
Ok(split_host.to_owned())
Ok(split_host.to_ascii_lowercase())
}
Ok(AttributeState::Available(None)) => Err(BuildError::EvaluationError(
"hostname not found".to_string(),
Expand Down Expand Up @@ -585,6 +585,39 @@ mod tests {
assert_eq!(factory.request_data.len(), 1);
}

#[test]
fn build_matches_hostname_case_insensitively() {
let config = build_test_config(vec!["Example.COM".to_string()], vec![], "test-service");
let factory = PipelineFactory::try_from(config).unwrap();

let mock_host = MockWasmHost::new()
.with_property("request.host".into(), "example.com".as_bytes().to_vec());
let ctx = ReqRespCtx::new(Arc::new(mock_host));
assert!(factory.build(ctx).unwrap().is_some());
}

#[test]
fn build_matches_mixed_case_request_hostname() {
let config = build_test_config(vec!["api.example.com".to_string()], vec![], "test-service");
let factory = PipelineFactory::try_from(config).unwrap();

let mock_host = MockWasmHost::new()
.with_property("request.host".into(), "API.Example.COM".as_bytes().to_vec());
let ctx = ReqRespCtx::new(Arc::new(mock_host));
assert!(factory.build(ctx).unwrap().is_some());
}

#[test]
fn build_matches_wildcard_case_insensitively() {
let config = build_test_config(vec!["*.Example.COM".to_string()], vec![], "test-service");
let factory = PipelineFactory::try_from(config).unwrap();

let mock_host = MockWasmHost::new()
.with_property("request.host".into(), "API.example.com".as_bytes().to_vec());
let ctx = ReqRespCtx::new(Arc::new(mock_host));
assert!(factory.build(ctx).unwrap().is_some());
}

#[test]
fn factory_handles_multiple_hostnames_for_same_action_set() {
let config = build_test_config(
Expand Down
6 changes: 1 addition & 5 deletions src/kuadrant/pipeline/tasks/token_usage/event_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@ impl EventBuilder {
}
self.event.data.push_str(val);
}
"id" => {
if !val.contains('\u{0000}') {
self.event.id = val.to_string()
}
}
"id" if !val.contains('\u{0000}') => self.event.id = val.to_string(),
"retry" => {
if let Ok(val) = val.parse::<u64>() {
self.event.retry = Some(Duration::from_millis(val))
Expand Down
Loading