feat(import): bind OpenAPI security schemes safely

This commit is contained in:
bsodfather committed 2026-09-27 23:42:11 +03:00
1 parent c562d5368d
commit 41a0e46110
38 files changed
+4651 -590

No files matched your search

@@ -1,9 +1,15 @@
use admin_api::service::{
AdminServiceBuilder, OpenApiImportCreatePayload, OpenApiUpload, OpenApiUploadLocale,
AdminServiceBuilder, AuthProfilePayload, OpenApiAuthMapping, OpenApiImportCreatePayload,
OpenApiImportCreateResponse, OpenApiUpload, OpenApiUploadLocale, SecretPayload,
};
use crank_core::WorkspaceId;
use crank_registry::ImportJobStatus;
use crank_core::{
AuthConfig, AuthKind, BearerAuthConfig, SecretId, SecretKind, Workspace, WorkspaceId,
WorkspaceStatus,
};
use crank_registry::{CreateWorkspaceRequest, ImportJobStatus};
use serde_json::json;
use serial_test::serial;
use sha2::Digest;
use super::common::{
test_auth_settings, test_registry, test_secret_crypto, test_service, test_storage_root,
@@ -11,6 +17,7 @@ use super::common::{
mod external_references;
mod http_contract;
mod security;
const OPENAPI3: &str = r#"
openapi: 3.0.3
@@ -78,11 +85,11 @@ async fn previews_openapi_and_creates_draft_operations() {
assert_eq!(preview_job.status, ImportJobStatus::Pending);
assert_eq!(
preview_job.preview_payload["normalization"]["normalizer_version"],
"normalized-ir-v4"
"normalized-ir-v5"
);
assert_eq!(
preview_job.preview_payload["normalization"]["projection_version"],
"preview-v4"
"preview-v5"
);
assert!(preview_job.preview_payload["normalization"]["ir_fingerprint"].is_string());
@@ -92,6 +99,7 @@ async fn previews_openapi_and_creates_draft_operations() {
&preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "skip".to_owned(),
},
@@ -110,6 +118,7 @@ async fn previews_openapi_and_creates_draft_operations() {
&preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "skip".to_owned(),
},
@@ -162,6 +171,7 @@ async fn previews_openapi_and_creates_draft_operations() {
&skip_preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "skip".to_owned(),
},
@@ -184,6 +194,7 @@ async fn previews_openapi_and_creates_draft_operations() {
&rename_preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "rename".to_owned(),
},
@@ -213,6 +224,7 @@ async fn unknown_selected_operations_are_persisted_in_the_canonical_replay() {
.unwrap();
let payload = OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned(), "GET /missing".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "skip".to_owned(),
};
@@ -254,6 +266,7 @@ async fn concurrent_openapi_import_replays_the_same_atomic_result() {
let job_id = preview.job_id.as_str().into();
let payload = OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "rename".to_owned(),
};
@@ -308,6 +321,7 @@ async fn concurrent_openapi_import_replays_the_same_atomic_result() {
&job_id,
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "skip".to_owned(),
},
@@ -349,6 +363,7 @@ async fn apply_fails_closed_when_the_preview_parser_contract_drifts() {
&job_id,
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "rename".to_owned(),
},
@@ -425,6 +440,7 @@ async fn apply_fails_closed_for_each_normalization_contract_field_and_digest_sha
&job_id,
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "rename".to_owned(),
}
@@ -493,6 +509,7 @@ async fn legacy_job_without_normalization_contract_replays_until_expiry() {
&job_id,
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /v2/latest".to_owned()],
auth_mappings: vec![],
server_url: Some("https://api.frankfurter.dev".to_owned()),
conflict_mode: "skip".to_owned(),
},
@@ -547,6 +564,7 @@ paths:
&preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /valid".to_owned()],
auth_mappings: vec![],
server_url: None,
conflict_mode: "skip".to_owned(),
},
@@ -634,6 +652,7 @@ paths:
&valid_preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /valid".to_owned()],
auth_mappings: vec![],
server_url: None,
conflict_mode: "skip".to_owned(),
},
@@ -652,6 +671,7 @@ paths:
&full_preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /valid".to_owned(), "GET /broken".to_owned()],
auth_mappings: vec![],
server_url: None,
conflict_mode: "rename".to_owned(),
},
@@ -733,6 +753,7 @@ components:
&preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /referenced".to_owned()],
auth_mappings: vec![],
server_url: None,
conflict_mode: "skip".to_owned(),
},