-
Notifications
You must be signed in to change notification settings - Fork 8
Add path-based asset backend proxy routing #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ use trusted_server_core::platform::{ | |
| StoreName, | ||
| }; | ||
| use trusted_server_core::request_signing::JWKS_CONFIG_STORE_NAME; | ||
| use trusted_server_core::settings::Settings; | ||
| use trusted_server_core::settings::{ProxyAssetRoute, Settings}; | ||
|
|
||
| use super::route_request; | ||
|
|
||
|
|
@@ -249,3 +249,92 @@ fn configured_missing_consent_store_only_breaks_consent_routes() { | |
| "should scope consent store failures to the consent-dependent routes" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn asset_routes_bypass_publisher_consent_dependencies() { | ||
| let mut settings = create_test_settings(); | ||
| settings.proxy.asset_routes = vec![ProxyAssetRoute { | ||
| prefix: "/.images/".to_string(), | ||
| origin_url: "https://assets.example.com".to_string(), | ||
| }]; | ||
| let orchestrator = build_orchestrator(&settings).expect("should build auction orchestrator"); | ||
| let integration_registry = | ||
| IntegrationRegistry::new(&settings).expect("should create integration registry"); | ||
|
|
||
| let asset_req = Request::get("https://test.com/.images/logo.png?auto=webp"); | ||
| let asset_services = test_runtime_services(&asset_req); | ||
| let asset_resp = futures::executor::block_on(route_request( | ||
| &settings, | ||
| &orchestrator, | ||
| &integration_registry, | ||
| &asset_services, | ||
| asset_req, | ||
| )) | ||
| .expect("should return an error response for asset proxy requests"); | ||
| assert_eq!( | ||
| asset_resp.get_status(), | ||
| StatusCode::BAD_GATEWAY, | ||
| "should bypass publisher consent dependencies and fail only on the missing upstream client" | ||
| ); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 wrench — The spec (§9 / §"Failure Semantics") explicitly forbids silent fallback to
|
||
|
|
||
| #[test] | ||
| fn built_in_routes_take_precedence_over_asset_routes() { | ||
| let mut settings = create_test_settings(); | ||
| settings.proxy.asset_routes = vec![ProxyAssetRoute { | ||
| prefix: "/.well-known/".to_string(), | ||
| origin_url: "https://assets.example.com".to_string(), | ||
| }]; | ||
| let orchestrator = build_orchestrator(&settings).expect("should build auction orchestrator"); | ||
| let integration_registry = | ||
| IntegrationRegistry::new(&settings).expect("should create integration registry"); | ||
|
|
||
| let req = Request::get("https://test.com/.well-known/trusted-server.json"); | ||
| let services = test_runtime_services(&req); | ||
| let resp = futures::executor::block_on(route_request( | ||
| &settings, | ||
| &orchestrator, | ||
| &integration_registry, | ||
| &services, | ||
| req, | ||
| )) | ||
| .expect("should route discovery request"); | ||
| assert_eq!( | ||
| resp.get_status(), | ||
| StatusCode::OK, | ||
| "should keep explicit built-in routes ahead of asset routes" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn integration_routes_take_precedence_over_asset_routes() { | ||
| let mut settings = create_test_settings(); | ||
| settings.proxy.asset_routes = vec![ProxyAssetRoute { | ||
| prefix: "/prebid.js".to_string(), | ||
| origin_url: "https://assets.example.com".to_string(), | ||
| }]; | ||
| let orchestrator = build_orchestrator(&settings).expect("should build auction orchestrator"); | ||
| let integration_registry = | ||
| IntegrationRegistry::new(&settings).expect("should create integration registry"); | ||
|
|
||
| let req = Request::get("https://test.com/prebid.js"); | ||
| let services = test_runtime_services(&req); | ||
| let mut resp = futures::executor::block_on(route_request( | ||
| &settings, | ||
| &orchestrator, | ||
| &integration_registry, | ||
| &services, | ||
| req, | ||
| )) | ||
| .expect("should route integration request"); | ||
| assert_eq!( | ||
| resp.get_status(), | ||
| StatusCode::OK, | ||
| "should keep explicit integration routes ahead of asset routes" | ||
| ); | ||
| assert_eq!( | ||
| resp.take_body_str(), | ||
| "// Script overridden by Trusted Server\n", | ||
| "should serve the integration response instead of proxying to the asset origin" | ||
| ); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 thinking — The spec's "Recommended Tests" section calls out several invariants that aren't covered yet. All are a few lines given existing helpers (
These keep the spec and tests in lockstep so behavior shifts surface as failing tests. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
♻️ refactor —
match &method { &Method::GET | &Method::HEAD => ..., _ => None }is awkward; the&patborrow dance only exists to avoid movingmethodbefore the outer match consumes it. Cleaner: