Skip to content

Commit 244da72

Browse files
Fix asset route rebase fallout
1 parent e1dd6c7 commit 244da72

13 files changed

Lines changed: 108 additions & 149 deletions

File tree

crates/trusted-server-adapter-fastly/src/route_tests.rs

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use edgezero_core::http::response_builder as edge_response_builder;
77
use edgezero_core::key_value_store::NoopKvStore;
88
use error_stack::Report;
99
use fastly::http::{header, Method, StatusCode};
10-
use fastly::Request;
11-
use trusted_server_core::auction::build_orchestrator;
10+
use fastly::{Request, Response};
11+
use trusted_server_core::auction::{build_orchestrator, AuctionOrchestrator};
1212
use trusted_server_core::ec::registry::PartnerRegistry;
1313
use trusted_server_core::integrations::IntegrationRegistry;
1414
use trusted_server_core::platform::{
@@ -330,14 +330,38 @@ fn test_runtime_services_with_secret_and_http_client(
330330
.build()
331331
}
332332

333+
fn test_partner_registry(settings: &Settings) -> PartnerRegistry {
334+
PartnerRegistry::from_config(&settings.ec.partners).expect("should build partner registry")
335+
}
336+
337+
fn buffered_route_response(
338+
settings: &Settings,
339+
orchestrator: &AuctionOrchestrator,
340+
integration_registry: &IntegrationRegistry,
341+
services: &RuntimeServices,
342+
req: Request,
343+
) -> Response {
344+
let partner_registry = test_partner_registry(settings);
345+
let outcome = futures::executor::block_on(route_request(
346+
settings,
347+
orchestrator,
348+
integration_registry,
349+
&partner_registry,
350+
services,
351+
req,
352+
))
353+
.expect("should route test request");
354+
355+
outcome.response.expect("should buffer test response")
356+
}
357+
333358
#[test]
334359
fn routes_use_request_local_consent() {
335360
let settings = create_test_settings();
336361
let orchestrator = build_orchestrator(&settings).expect("should build auction orchestrator");
337362
let integration_registry =
338363
IntegrationRegistry::new(&settings).expect("should create integration registry");
339-
let partner_registry =
340-
PartnerRegistry::from_config(&settings.ec.partners).expect("should build partner registry");
364+
let partner_registry = test_partner_registry(&settings);
341365

342366
let discovery_req = Request::get("https://test.com/.well-known/trusted-server.json");
343367
let discovery_services = test_runtime_services(&discovery_req);
@@ -396,14 +420,13 @@ fn asset_routes_bypass_publisher_consent_dependencies() {
396420

397421
let asset_req = Request::get("https://test.com/.images/logo.png?auto=webp");
398422
let asset_services = test_runtime_services(&asset_req);
399-
let asset_resp = futures::executor::block_on(route_request(
423+
let asset_resp = buffered_route_response(
400424
&settings,
401425
&orchestrator,
402426
&integration_registry,
403427
&asset_services,
404428
asset_req,
405-
))
406-
.expect("should return an error response for asset proxy requests");
429+
);
407430
assert_eq!(
408431
asset_resp.get_status(),
409432
StatusCode::BAD_GATEWAY,
@@ -430,14 +453,13 @@ fn asset_origin_failure_does_not_fall_back_to_publisher_origin() {
430453
Arc::clone(&http_client) as Arc<dyn PlatformHttpClient>,
431454
);
432455

433-
let resp = futures::executor::block_on(route_request(
456+
let resp = buffered_route_response(
434457
&settings,
435458
&orchestrator,
436459
&integration_registry,
437460
&services,
438461
req,
439-
))
440-
.expect("should return an error response for failed asset origin");
462+
);
441463

442464
assert_eq!(
443465
resp.get_status(),
@@ -518,14 +540,13 @@ fn s3_asset_origin_error_stays_uncacheable_after_global_headers() {
518540
Arc::clone(&http_client) as Arc<dyn PlatformHttpClient>,
519541
);
520542

521-
let resp = futures::executor::block_on(route_request(
543+
let resp = buffered_route_response(
522544
&settings,
523545
&orchestrator,
524546
&integration_registry,
525547
&services,
526548
req,
527-
))
528-
.expect("should route S3 asset request");
549+
);
529550

530551
assert_eq!(
531552
resp.get_status(),
@@ -567,14 +588,13 @@ fn asset_routes_proxy_head_requests() {
567588
Arc::clone(&http_client) as Arc<dyn PlatformHttpClient>,
568589
);
569590

570-
let resp = futures::executor::block_on(route_request(
591+
let resp = buffered_route_response(
571592
&settings,
572593
&orchestrator,
573594
&integration_registry,
574595
&services,
575596
req,
576-
))
577-
.expect("should route HEAD asset request");
597+
);
578598

579599
assert_eq!(
580600
resp.get_status(),
@@ -617,14 +637,13 @@ fn asset_routes_ignore_query_string_for_matching() {
617637
Arc::clone(&http_client) as Arc<dyn PlatformHttpClient>,
618638
);
619639

620-
let resp = futures::executor::block_on(route_request(
640+
let resp = buffered_route_response(
621641
&settings,
622642
&orchestrator,
623643
&integration_registry,
624644
&services,
625645
req,
626-
))
627-
.expect("should route asset request with query string");
646+
);
628647

629648
assert_eq!(
630649
resp.get_status(),
@@ -667,14 +686,13 @@ fn asset_routes_pass_redirect_responses_through() {
667686
Arc::clone(&http_client) as Arc<dyn PlatformHttpClient>,
668687
);
669688

670-
let resp = futures::executor::block_on(route_request(
689+
let resp = buffered_route_response(
671690
&settings,
672691
&orchestrator,
673692
&integration_registry,
674693
&services,
675694
req,
676-
))
677-
.expect("should route redirecting asset request");
695+
);
678696

679697
assert_eq!(
680698
resp.get_status(),
@@ -691,6 +709,7 @@ fn asset_routes_pass_redirect_responses_through() {
691709
#[test]
692710
fn asset_routes_skip_non_get_head_requests() {
693711
let mut settings = create_test_settings();
712+
settings.publisher.origin_url = "https://".to_string();
694713
settings.proxy.asset_routes = vec![ProxyAssetRoute::new(
695714
"/.images/",
696715
"https://assets.example.com",
@@ -707,18 +726,17 @@ fn asset_routes_skip_non_get_head_requests() {
707726
Arc::clone(&http_client) as Arc<dyn PlatformHttpClient>,
708727
);
709728

710-
let resp = futures::executor::block_on(route_request(
729+
let resp = buffered_route_response(
711730
&settings,
712731
&orchestrator,
713732
&integration_registry,
714733
&services,
715734
req,
716-
))
717-
.expect("should route non-asset POST request");
735+
);
718736

719737
assert_eq!(
720738
resp.get_status(),
721-
StatusCode::SERVICE_UNAVAILABLE,
739+
StatusCode::BAD_GATEWAY,
722740
"should fall through to publisher fallback for POST requests"
723741
);
724742
assert!(
@@ -744,14 +762,13 @@ fn built_in_routes_take_precedence_over_asset_routes() {
744762

745763
let req = Request::get("https://test.com/.well-known/trusted-server.json");
746764
let services = test_runtime_services(&req);
747-
let resp = futures::executor::block_on(route_request(
765+
let resp = buffered_route_response(
748766
&settings,
749767
&orchestrator,
750768
&integration_registry,
751769
&services,
752770
req,
753-
))
754-
.expect("should route discovery request");
771+
);
755772
assert_eq!(
756773
resp.get_status(),
757774
StatusCode::OK,
@@ -772,14 +789,13 @@ fn integration_routes_take_precedence_over_asset_routes() {
772789

773790
let req = Request::get("https://test.com/prebid.js");
774791
let services = test_runtime_services(&req);
775-
let mut resp = futures::executor::block_on(route_request(
792+
let mut resp = buffered_route_response(
776793
&settings,
777794
&orchestrator,
778795
&integration_registry,
779796
&services,
780797
req,
781-
))
782-
.expect("should route integration request");
798+
);
783799
assert_eq!(
784800
resp.get_status(),
785801
StatusCode::OK,

crates/trusted-server-core/src/integrations/datadome.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ use crate::integrations::{
7171
AttributeRewriteAction, IntegrationAttributeContext, IntegrationAttributeRewriter,
7272
IntegrationEndpoint, IntegrationProxy, IntegrationRegistration,
7373
};
74+
use crate::platform::RuntimeServices;
7475
use crate::settings::{IntegrationConfig, Settings};
7576

7677
const DATADOME_INTEGRATION_ID: &str = "datadome";
@@ -404,6 +405,7 @@ impl IntegrationProxy for DataDomeIntegration {
404405
async fn handle(
405406
&self,
406407
_settings: &Settings,
408+
_services: &RuntimeServices,
407409
req: Request,
408410
) -> Result<Response, Report<TrustedServerError>> {
409411
let path = req.get_path();

crates/trusted-server-core/src/integrations/didomi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use validator::Validate;
1111
use crate::backend::BackendConfig;
1212
use crate::error::TrustedServerError;
1313
use crate::integrations::{IntegrationEndpoint, IntegrationProxy, IntegrationRegistration};
14+
use crate::platform::RuntimeServices;
1415
use crate::settings::{IntegrationConfig, Settings};
1516

1617
const DIDOMI_INTEGRATION_ID: &str = "didomi";
@@ -198,6 +199,7 @@ impl IntegrationProxy for DidomiIntegration {
198199
async fn handle(
199200
&self,
200201
_settings: &Settings,
202+
_services: &RuntimeServices,
201203
req: Request,
202204
) -> Result<Response, Report<TrustedServerError>> {
203205
let path = req.get_path();

crates/trusted-server-core/src/integrations/google_tag_manager.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::integrations::{
2828
IntegrationEndpoint, IntegrationProxy, IntegrationRegistration, IntegrationScriptContext,
2929
IntegrationScriptRewriter, ScriptRewriteAction,
3030
};
31+
use crate::platform::RuntimeServices;
3132
use crate::proxy::{proxy_request, ProxyRequestConfig};
3233
use crate::settings::{IntegrationConfig, Settings};
3334

@@ -427,6 +428,7 @@ impl IntegrationProxy for GoogleTagManagerIntegration {
427428
async fn handle(
428429
&self,
429430
settings: &Settings,
431+
services: &RuntimeServices,
430432
mut req: Request,
431433
) -> Result<Response, Report<TrustedServerError>> {
432434
let path = req.get_path().to_string();
@@ -482,7 +484,7 @@ impl IntegrationProxy for GoogleTagManagerIntegration {
482484
}
483485
};
484486

485-
let mut response = proxy_request(settings, req, proxy_config)
487+
let mut response = proxy_request(settings, req, proxy_config, services)
486488
.await
487489
.change_context(Self::error("Failed to proxy GTM request"))?;
488490

@@ -611,6 +613,7 @@ mod tests {
611613
IntegrationDocumentState, IntegrationRegistry, IntegrationScriptContext,
612614
IntegrationScriptRewriter, ScriptRewriteAction,
613615
};
616+
use crate::platform::test_support::noop_services;
614617
use crate::settings::Settings;
615618
use crate::streaming_processor::{Compression, PipelineConfig, StreamingPipeline};
616619

@@ -1213,7 +1216,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
12131216

12141217
let settings = make_settings();
12151218
let response = integration
1216-
.handle(&settings, req)
1219+
.handle(&settings, &noop_services(), req)
12171220
.await
12181221
.expect("handle should not return error");
12191222

@@ -1248,7 +1251,7 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
12481251

12491252
let settings = make_settings();
12501253
let response = integration
1251-
.handle(&settings, req)
1254+
.handle(&settings, &noop_services(), req)
12521255
.await
12531256
.expect("handle should not return error");
12541257

crates/trusted-server-core/src/integrations/gpt.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use crate::integrations::{
4949
IntegrationEndpoint, IntegrationHeadInjector, IntegrationHtmlContext, IntegrationProxy,
5050
IntegrationRegistration,
5151
};
52+
use crate::platform::RuntimeServices;
5253
use crate::proxy::{proxy_request, ProxyRequestConfig};
5354
use crate::settings::{IntegrationConfig, Settings};
5455

@@ -238,12 +239,13 @@ impl GptIntegration {
238239
async fn proxy_gpt_asset(
239240
&self,
240241
settings: &Settings,
242+
services: &RuntimeServices,
241243
req: Request,
242244
target_url: &str,
243245
context: &str,
244246
) -> Result<Response, Report<TrustedServerError>> {
245247
let config = Self::build_proxy_config(target_url, &req);
246-
let response = proxy_request(settings, req, config)
248+
let response = proxy_request(settings, req, config, services)
247249
.await
248250
.change_context(Self::error(context))?;
249251

@@ -287,12 +289,14 @@ impl GptIntegration {
287289
async fn handle_script_serving(
288290
&self,
289291
settings: &Settings,
292+
services: &RuntimeServices,
290293
req: Request,
291294
) -> Result<Response, Report<TrustedServerError>> {
292295
let script_url = &self.config.script_url;
293296
log::info!("Fetching GPT script from: {}", script_url);
294297
self.proxy_gpt_asset(
295298
settings,
299+
services,
296300
req,
297301
script_url,
298302
&format!("Failed to fetch GPT script from {script_url}"),
@@ -309,6 +313,7 @@ impl GptIntegration {
309313
async fn handle_pagead_proxy(
310314
&self,
311315
settings: &Settings,
316+
services: &RuntimeServices,
312317
req: Request,
313318
) -> Result<Response, Report<TrustedServerError>> {
314319
let original_path = req.get_path();
@@ -320,6 +325,7 @@ impl GptIntegration {
320325
log::info!("GPT proxy: forwarding to {}", target_url);
321326
self.proxy_gpt_asset(
322327
settings,
328+
services,
323329
req,
324330
&target_url,
325331
&format!("Failed to fetch GPT resource from {target_url}"),
@@ -376,16 +382,17 @@ impl IntegrationProxy for GptIntegration {
376382
async fn handle(
377383
&self,
378384
settings: &Settings,
385+
services: &RuntimeServices,
379386
req: Request,
380387
) -> Result<Response, Report<TrustedServerError>> {
381388
let path = req.get_path();
382389

383390
if path == "/integrations/gpt/script" {
384-
self.handle_script_serving(settings, req).await
391+
self.handle_script_serving(settings, services, req).await
385392
} else if path.starts_with("/integrations/gpt/pagead/")
386393
|| path.starts_with("/integrations/gpt/tag/")
387394
{
388-
self.handle_pagead_proxy(settings, req).await
395+
self.handle_pagead_proxy(settings, services, req).await
389396
} else {
390397
Err(Report::new(Self::error(format!(
391398
"Unknown GPT route: {}",

crates/trusted-server-core/src/integrations/lockr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::integrations::{
2323
AttributeRewriteAction, IntegrationAttributeContext, IntegrationAttributeRewriter,
2424
IntegrationEndpoint, IntegrationProxy, IntegrationRegistration,
2525
};
26+
use crate::platform::RuntimeServices;
2627
use crate::settings::{IntegrationConfig, Settings};
2728

2829
const LOCKR_INTEGRATION_ID: &str = "lockr";
@@ -303,6 +304,7 @@ impl IntegrationProxy for LockrIntegration {
303304
async fn handle(
304305
&self,
305306
settings: &Settings,
307+
_services: &RuntimeServices,
306308
req: Request,
307309
) -> Result<Response, Report<TrustedServerError>> {
308310
let path = req.get_path();

0 commit comments

Comments
 (0)