Skip to content
Open
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
1 change: 0 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
schedule:
- cron: "40 17 * * 3"

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: read
Expand Down
39 changes: 23 additions & 16 deletions crates/edgezero-adapter-axum/tests/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,28 +1189,35 @@ async fn authority_override_changes_host_only_and_cache_bypass_adds_no_origin_he
.get(CACHE_CONTROL)
.and_then(|value| value.to_str().ok())
.unwrap_or("absent");
format!("{host}|{cache_control}")
let tag = headers.get("surrogate-key").map_or("absent", |_| "present");
format!("{host}|{cache_control}|{tag}")
}),
))
.await;
let client = HttpClient::with_client(
AxumOutboundClient::try_new(executor_handle.clone()).expect("client"),
);
let request = OutboundRequest::get(format!("{origin}/"))
.expect("request")
.host_authority_override("virtual.example:8443")
.expect("authority override")
.cache_policy(OutboundCachePolicy::Bypass);

let body = client
.send(request)
.await
.expect("response")
.into_bytes_bounded(1_024)
.await
.expect("response body");

assert_eq!(body, "virtual.example:8443|absent");
for policy in [
OutboundCachePolicy::Bypass,
OutboundCachePolicy::PlatformDefault,
OutboundCachePolicy::PlatformDefaultWithSurrogateKey(HeaderValue::from_static(
"example-all example-reader-0123",
)),
] {
let request = OutboundRequest::get(format!("{origin}/"))
.expect("request")
.host_authority_override("virtual.example.com:8443")
.expect("authority override")
.cache_policy(policy);
let body = client
.send(request)
.await
.expect("response")
.into_bytes_bounded(1_024)
.await
.expect("response body");
assert_eq!(body, "virtual.example.com:8443|absent|absent");
}
}

#[tokio::test]
Expand Down
123 changes: 117 additions & 6 deletions crates/edgezero-adapter-cloudflare/src/outbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use edgezero_core::error::{BadGatewayReason, BudgetSource};
all(feature = "cloudflare", target_arch = "wasm32"),
feature = "test-utils"
))]
use edgezero_core::outbound::OutboundRequest;
use edgezero_core::outbound::{OutboundCachePolicy, OutboundRequest};
#[cfg(feature = "test-utils")]
use edgezero_core::outbound::{OutboundSendMode, validate_for_dispatch};

Expand Down Expand Up @@ -341,7 +341,8 @@ mod worker_impl {
let worker_body =
request_body(body, max_request_body_bytes, budget, time.clone()).await?;
let url = uri.to_string();
let request = build_worker_request(&method, &url, &headers, worker_body, cache_policy)?;
let request =
build_worker_request(&method, &url, &headers, worker_body, &cache_policy)?;
let (response, abort_guard) = raw_fetch(
request,
budget,
Expand Down Expand Up @@ -581,13 +582,13 @@ mod worker_impl {
url: &str,
headers: &HeaderMap,
request_body: Option<JsValue>,
cache_policy: OutboundCachePolicy,
cache_policy: &OutboundCachePolicy,
) -> Result<WorkerRequest, EdgeError> {
let mut init = RequestInit::new();
init.with_headers(build_headers(headers)?)
.with_method(worker_method(method))
.with_redirect(RequestRedirect::Manual);
if cache_policy == OutboundCachePolicy::Bypass {
if matches!(cache_policy, OutboundCachePolicy::Bypass) {
Comment thread
ChristianPavilonis marked this conversation as resolved.
Resolved
init.with_cache(CacheMode::NoStore);
}
if let Some(worker_body) = request_body {
Expand Down Expand Up @@ -1899,6 +1900,65 @@ mod worker_impl {
assert!(results.slots().iter().all(|slot| matches!(slot, OutboundCollectedSlot::Resolved(result) if result.outcome.is_ok())));
}

#[wasm_bindgen_test]
async fn tagged_default_is_rejected_before_body_poll_or_fetch() {
let _timers = NumericTimeoutGuard::install();
let (probe, _restore) = fetch_probe(false);
let client = HttpClient::with_client(CloudflareOutboundClient::new());
let polls = Rc::new(Cell::new(0_usize));
let tagged = || {
OutboundRequest::get("https://fixture.invalid/tagged")
.expect("request")
.cache_policy(OutboundCachePolicy::PlatformDefaultWithSurrogateKey(
HeaderValue::from_static("example-all"),
))
};
let streamed = || {
let observed = Rc::clone(&polls);
tagged().body(Body::from_stream(stream::poll_fn(move |_cx| {
observed.set(observed.get().saturating_add(1));
Poll::Ready(None)
})))
};
let check = |error: &EdgeError| {
assert_eq!(error.status(), StatusCode::BAD_REQUEST);
assert!(error.message().contains("surrogate keys"));
assert!(error.message().contains("cloudflare"));
};

check(&client.send(streamed()).await.expect_err("tagged send"));
check(&client.begin(streamed()).await.expect_err("tagged begin"));
let results = client
.send_all_until(
vec![
tagged(),
OutboundRequest::get("https://fixture.invalid/untagged").expect("request"),
],
Deadline::after(Duration::from_secs(1)),
)
.await
.expect("batch outcomes");
check(
resolved_slot(&results.slots()[0])
.outcome
.as_ref()
.expect_err("tagged batch slot"),
);
let untagged = resolved_slot(&results.slots()[1])
.outcome
.as_ref()
.expect("untagged batch slot");
assert_eq!(untagged.status(), StatusCode::OK);
assert_eq!(polls.get(), 0);
assert_eq!(
Reflect::get(&probe, &JsValue::from_str("calls"))
.expect("calls")
.as_f64(),
Some(1.0_f64),
"only the untagged batch slot should fetch"
);
}

#[wasm_bindgen_test]
async fn begin_dispatches_without_collection_and_drop_aborts() {
let _timers = NumericTimeoutGuard::install();
Expand Down Expand Up @@ -2231,6 +2291,33 @@ mod worker_impl {
assert_eq!(before.body().as_bytes(), after.body().as_bytes());
}

#[wasm_bindgen_test]
fn untagged_cache_policies_keep_worker_default_and_no_store_modes() {
for (policy, expected) in [
(OutboundCachePolicy::PlatformDefault, "default"),
(OutboundCachePolicy::Bypass, "no-store"),
] {
let request = build_worker_request(
&Method::GET,
"https://origin.example.com/resource",
&HeaderMap::new(),
None,
&policy,
)
.expect("Workers request");
let mode = Reflect::get(request.inner().as_ref(), &JsValue::from_str("cache"))
.expect("cache mode");
assert_eq!(mode.as_string().as_deref(), Some(expected));
assert!(
request
.headers()
.get("surrogate-key")
.expect("header")
.is_none()
);
}
}

#[wasm_bindgen_test]
fn provider_diagnostics_preserve_preparation_errors_without_changing_sources() {
let mut headers = HeaderMap::new();
Expand Down Expand Up @@ -2262,7 +2349,7 @@ mod worker_impl {
"https://example.com/?token=provider-secret-token",
&HeaderMap::new(),
Some(JsValue::from_str("body")),
OutboundCachePolicy::PlatformDefault,
&OutboundCachePolicy::PlatformDefault,
)
.expect_err("GET body rejection");
assert_eq!(
Expand Down Expand Up @@ -2358,7 +2445,7 @@ mod worker_impl {
"https://example.com/?token=provider-secret-token",
&HeaderMap::new(),
None,
OutboundCachePolicy::PlatformDefault,
&OutboundCachePolicy::PlatformDefault,
)
.expect("valid request");
let start = MonotonicInstant::now();
Expand Down Expand Up @@ -3807,6 +3894,14 @@ fn validate_supported_options(request: &OutboundRequest) -> Result<(), EdgeError
"image_optimizer is not supported by cloudflare",
));
}
if matches!(
request.cache_policy_setting(),
OutboundCachePolicy::PlatformDefaultWithSurrogateKey(_)
) {
return Err(EdgeError::bad_request(
"outbound cache surrogate keys are not supported by cloudflare",
));
}
Comment on lines +3897 to +3904

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😃 This follows the existing Image Optimizer rejection, and prepare runs it before validate_for_dispatch, so a tagged request fails with the clearer Cloudflare-specific message even when its list is also malformed. I checked this by disabling the condition: tagged_default_is_unsupported_in_batch_preflight then fails, so the test really depends on this check.

Ok(())
}

Expand Down Expand Up @@ -3845,6 +3940,22 @@ mod header_bridge_tests {

use super::*;

#[cfg(feature = "test-utils")]
#[test]
fn tagged_default_is_unsupported_in_batch_preflight() {
let request = OutboundRequest::get("https://origin.example.com/resource")
.expect("request")
.cache_policy(
edgezero_core::OutboundCachePolicy::PlatformDefaultWithSurrogateKey(
HeaderValue::from_static("example-all"),
),
);
let error = validate_batch_request_for_test(&request).expect_err("tagged request");
assert!(matches!(error, EdgeError::BadRequest { .. }));
assert!(error.message().contains("surrogate keys"));
assert!(error.message().contains("cloudflare"));
}

#[derive(Default)]
struct AppendSink(BTreeMap<String, Vec<String>>);

Expand Down
Loading
Loading