-
Notifications
You must be signed in to change notification settings - Fork 10
Add auction endpoint request handling coverage #690
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 |
|---|---|---|
|
|
@@ -3,9 +3,10 @@ use std::sync::Arc; | |
|
|
||
| use edgezero_core::key_value_store::NoopKvStore; | ||
| use error_stack::Report; | ||
| use fastly::http::StatusCode; | ||
| use fastly::http::{header, StatusCode}; | ||
| use fastly::Request; | ||
| use trusted_server_core::auction::build_orchestrator; | ||
| use serde_json::json; | ||
| use trusted_server_core::auction::{build_orchestrator, AuctionOrchestrator}; | ||
| use trusted_server_core::integrations::IntegrationRegistry; | ||
| use trusted_server_core::platform::{ | ||
| ClientInfo, GeoInfo, PlatformBackend, PlatformBackendSpec, PlatformConfigStore, PlatformError, | ||
|
|
@@ -117,9 +118,8 @@ impl PlatformGeo for NoopGeo { | |
| } | ||
| } | ||
|
|
||
| fn create_test_settings() -> Settings { | ||
| let settings = Settings::from_toml( | ||
| r#" | ||
| fn base_route_settings_toml() -> &'static str { | ||
| r#" | ||
| [[handlers]] | ||
| path = "^/admin" | ||
| username = "admin" | ||
|
|
@@ -138,21 +138,35 @@ fn create_test_settings() -> Settings { | |
| enabled = false | ||
| config_store_id = "test-config-store-id" | ||
| secret_store_id = "test-secret-store-id" | ||
| "# | ||
| } | ||
|
|
||
| [consent] | ||
| consent_store = "missing-consent-store" | ||
|
|
||
| fn prebid_integration_toml() -> &'static str { | ||
| r#" | ||
| [integrations.prebid] | ||
| enabled = true | ||
| server_url = "https://test-prebid.com/openrtb2/auction" | ||
| "# | ||
| } | ||
|
|
||
| fn create_test_settings() -> Settings { | ||
| let base = base_route_settings_toml(); | ||
| let prebid = prebid_integration_toml(); | ||
| let config = format!( | ||
| r#"{base} | ||
|
|
||
| [consent] | ||
| consent_store = "missing-consent-store" | ||
|
|
||
| {prebid} | ||
|
|
||
| [auction] | ||
| enabled = true | ||
| providers = ["prebid"] | ||
| timeout_ms = 2000 | ||
| "#, | ||
| ) | ||
| .expect("should parse adapter route test settings"); | ||
| ); | ||
| let settings = Settings::from_toml(&config).expect("should parse adapter route test settings"); | ||
|
|
||
| assert_eq!( | ||
| JWKS_CONFIG_STORE_NAME, "jwks_store", | ||
|
|
@@ -162,6 +176,32 @@ fn create_test_settings() -> Settings { | |
| settings | ||
| } | ||
|
|
||
| fn create_auction_test_settings_without_consent_store(providers: &str) -> Settings { | ||
| let base = base_route_settings_toml(); | ||
| let prebid = prebid_integration_toml(); | ||
| let config = format!( | ||
| r#"{base} | ||
|
|
||
| {prebid} | ||
|
|
||
| [auction] | ||
| enabled = true | ||
| providers = {providers} | ||
| timeout_ms = 2000 | ||
| "#, | ||
| ); | ||
|
|
||
| Settings::from_toml(&config).expect("should parse adapter auction route test settings") | ||
| } | ||
|
|
||
| fn build_route_stack(settings: &Settings) -> (AuctionOrchestrator, IntegrationRegistry) { | ||
| let orchestrator = build_orchestrator(settings).expect("should build auction orchestrator"); | ||
| let integration_registry = | ||
| IntegrationRegistry::new(settings).expect("should create integration registry"); | ||
|
|
||
| (orchestrator, integration_registry) | ||
| } | ||
|
|
||
| fn test_runtime_services(req: &Request) -> RuntimeServices { | ||
| RuntimeServices::builder() | ||
| .config_store(Arc::new(StubJwksConfigStore)) | ||
|
|
@@ -178,6 +218,45 @@ fn test_runtime_services(req: &Request) -> RuntimeServices { | |
| .build() | ||
| } | ||
|
|
||
| fn route_auction(settings: &Settings, body: impl Into<Vec<u8>>) -> fastly::Response { | ||
| let (orchestrator, integration_registry) = build_route_stack(settings); | ||
| let req = Request::post("https://test.com/auction") | ||
| .with_header(header::CONTENT_TYPE, "application/json") | ||
| .with_body(body.into()); | ||
| let services = test_runtime_services(&req); | ||
|
|
||
| futures::executor::block_on(route_request( | ||
| settings, | ||
| &orchestrator, | ||
| &integration_registry, | ||
| &services, | ||
| req, | ||
| )) | ||
| .expect("should route auction request") | ||
| } | ||
|
|
||
| fn valid_banner_ad_unit_body() -> Vec<u8> { | ||
| serde_json::to_vec(&json!({ | ||
| "adUnits": [ | ||
| { | ||
| "code": "div-gpt-ad-1", | ||
| "mediaTypes": { | ||
| "banner": { | ||
| "sizes": [[300, 250]] | ||
| } | ||
| }, | ||
| "bids": [ | ||
|
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. ⛏ nitpick — This |
||
| { | ||
| "bidder": "missing-provider", | ||
| "params": {} | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| })) | ||
| .expect("should serialize valid auction route test body") | ||
| } | ||
|
|
||
| #[test] | ||
| fn configured_missing_consent_store_only_breaks_consent_routes() { | ||
| let settings = create_test_settings(); | ||
|
|
@@ -249,3 +328,59 @@ fn configured_missing_consent_store_only_breaks_consent_routes() { | |
| "should scope consent store failures to the consent-dependent routes" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn malformed_auction_json_returns_bad_request() { | ||
| let settings = create_auction_test_settings_without_consent_store(r#"["prebid"]"#); | ||
|
|
||
| let mut response = route_auction(&settings, "{not-json"); | ||
|
|
||
| assert_eq!( | ||
| response.get_status(), | ||
| StatusCode::BAD_REQUEST, | ||
| "should reject malformed JSON as a client request error" | ||
| ); | ||
| assert!( | ||
| response.take_body_str().contains("Bad request"), | ||
| "should return a client-facing bad request message" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn invalid_auction_banner_size_returns_bad_request() { | ||
| let settings = create_auction_test_settings_without_consent_store(r#"["prebid"]"#); | ||
| let body = serde_json::to_vec(&json!({ | ||
| "adUnits": [ | ||
| { | ||
| "code": "div-gpt-ad-1", | ||
| "mediaTypes": { | ||
| "banner": { | ||
| "sizes": [[300]] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| })) | ||
| .expect("should serialize invalid auction route test body"); | ||
|
|
||
| let response = route_auction(&settings, body); | ||
|
|
||
| assert_eq!( | ||
| response.get_status(), | ||
| StatusCode::BAD_REQUEST, | ||
| "should reject semantically invalid banner sizes as a client request error" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn auction_request_with_empty_provider_list_returns_bad_gateway() { | ||
| let settings = create_auction_test_settings_without_consent_store("[]"); | ||
|
|
||
| let response = route_auction(&settings, valid_banner_ad_unit_body()); | ||
|
|
||
| assert_eq!( | ||
| response.get_status(), | ||
| StatusCode::BAD_GATEWAY, | ||
|
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 — This test uses Consider a route test with a registered-but-disabled provider so the request reaches the new branch end-to-end. |
||
| "should surface no-provider orchestration failures as gateway errors" | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.