diff --git a/backend/windmill-api-integration-tests/tests/scripts.rs b/backend/windmill-api-integration-tests/tests/scripts.rs index d7c8f5ca95..bc05db85f7 100644 --- a/backend/windmill-api-integration-tests/tests/scripts.rs +++ b/backend/windmill-api-integration-tests/tests/scripts.rs @@ -1085,5 +1085,19 @@ async fn test_path_listing_and_exists_scope_filtering(db: Pool) -> any let resp = get(format!("{api}/variables/exists/f/b/x")).await?; assert_eq!(resp.status(), 403, "{}", resp.text().await?); + // App embed tokens reach `resources/exists` with a path-less `resources:run`. + sqlx::query( + "INSERT INTO token (token_hash, token_prefix, token, email, label, super_admin, scopes) VALUES + (encode(sha256('RES_RUN_TOKEN'::bytea), 'hex'), 'RES_RUN_TO', 'RES_RUN_TOKEN', 'test@windmill.dev', 'embed', true, ARRAY['resources:run'])", + ) + .execute(&db) + .await?; + let resp = client() + .get(format!("{api}/resources/exists/f/b/r")) + .header("Authorization", "Bearer RES_RUN_TOKEN") + .send() + .await?; + assert_eq!(resp.status(), 200, "{}", resp.text().await?); + Ok(()) } diff --git a/backend/windmill-api-scripts/src/scripts.rs b/backend/windmill-api-scripts/src/scripts.rs index 4fd1c4c215..a7f388e6e0 100644 --- a/backend/windmill-api-scripts/src/scripts.rs +++ b/backend/windmill-api-scripts/src/scripts.rs @@ -4946,12 +4946,14 @@ impl From for CiTestResult { } } -/// The scope domain a CI test result's tested item is read under. -fn ci_tested_item_scope_domain(kind: &str) -> &'static str { - if kind == "flow" { - "flows" - } else { - "scripts" +/// The scope domain a CI test result's tested item is read under, for the kinds +/// `parse_ci_test_item` can record. +fn ci_tested_item_scope_domain(kind: &str) -> Option<&'static str> { + match kind { + "script" => Some("scripts"), + "flow" => Some("flows"), + "resource" => Some("resources"), + _ => None, } } @@ -4961,9 +4963,9 @@ async fn get_ci_test_results( Path((w_id, kind, path)): Path<(String, String, StripPath)>, ) -> JsonResult> { let path = path.to_path(); - check_scopes(&authed, || { - format!("{}:read:{}", ci_tested_item_scope_domain(&kind), path) - })?; + let domain = ci_tested_item_scope_domain(&kind) + .ok_or_else(|| Error::BadRequest(format!("unknown tested item kind: {kind}")))?; + check_scopes(&authed, || format!("{}:read:{}", domain, path))?; let expected_trigger = format!("{}/{}", kind, path); // Exact matches — uses the primary ci_test_reference index. @@ -5076,10 +5078,13 @@ async fn get_ci_test_results_batch( let mut paths_by_kind: HashMap> = HashMap::new(); let scripts_allowed = build_scope_path_predicate(&authed, "scripts", "read"); let flows_allowed = build_scope_path_predicate(&authed, "flows", "read"); + let resources_allowed = build_scope_path_predicate(&authed, "resources", "read"); for item in &req.items { let allowed = match ci_tested_item_scope_domain(&item.kind) { - "flows" => flows_allowed(&item.path), - _ => scripts_allowed(&item.path), + Some("scripts") => scripts_allowed(&item.path), + Some("flows") => flows_allowed(&item.path), + Some("resources") => resources_allowed(&item.path), + _ => false, }; if !allowed { continue;