feat(import): complete OpenAPI onboarding and verify delivery
CI / Rust Checks (pull_request) Failing after 1s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped

This commit is contained in:
bsodfather committed 2026-10-09 17:50:38 +03:00
1 parent bb3e376767
commit e93de7015a
244 files changed
+57020 -5139

No files matched your search

@@ -1,15 +1,9 @@
use admin_api::service::{
AdminServiceBuilder, AuthProfilePayload, OpenApiAuthMapping, OpenApiImportCreatePayload,
OpenApiImportCreateResponse, OpenApiUpload, OpenApiUploadLocale, SecretPayload,
AdminServiceBuilder, OpenApiImportCreatePayload, OpenApiUpload, OpenApiUploadLocale,
};
use crank_core::{
AuthConfig, AuthKind, BearerAuthConfig, SecretId, SecretKind, Workspace, WorkspaceId,
WorkspaceStatus,
};
use crank_registry::{CreateWorkspaceRequest, ImportJobStatus};
use serde_json::json;
use crank_core::WorkspaceId;
use crank_registry::ImportJobStatus;
use serial_test::serial;
use sha2::Digest;
use super::common::{
test_auth_settings, test_registry, test_secret_crypto, test_service, test_storage_root,
@@ -17,7 +11,120 @@ use super::common::{
mod external_references;
mod http_contract;
mod security;
mod import_plan_apply;
mod import_plan_create;
mod large_preview;
mod upload_outcomes;
mod v5_replay;
#[tokio::test]
#[serial]
async fn upload_rejects_credential_literals_before_persisting_source_artifacts() {
let registry = test_registry().await;
let storage_root = test_storage_root("openapi_import_storage_redaction");
let service = test_service(
registry.clone(),
storage_root,
test_auth_settings(),
test_secret_crypto(),
);
let workspace_id = WorkspaceId::new("ws_default");
let upload = OpenApiUpload {
bytes: br#"{
"openapi":"3.0.3",
"info":{"title":"Redaction persistence","version":"1"},
"servers":[{"url":"https://bare-canary@api.example.test/v1?api_key=query-canary"}],
"components":{"securitySchemes":{"key":{"type":"apiKey","in":"header","name":"X-Api-Key"}}},
"paths":{"/private":{"get":{
"operationId":"privateOperation",
"parameters":[{"name":"X-Api-Key","in":"header","example":"opaque-canary-42"}],
"responses":{"200":{"description":"ok"}},
"x-client-secret":true
}}}
}"#
.to_vec(),
mime_type: "application/json".to_owned(),
locale: OpenApiUploadLocale::En,
};
let error = service
.preview_openapi_import(&workspace_id, upload)
.await
.expect_err("credential-bearing uploads must be rejected before persistence");
let rendered_error = format!("{error:?}");
assert!(
rendered_error.contains("invalid_document"),
"unexpected typed error: {rendered_error}"
);
for canary in ["bare-canary", "query-canary", "opaque-canary-42"] {
assert!(
!rendered_error.contains(canary),
"API error leaked {canary}"
);
}
let source_count: i64 =
sqlx::query_scalar("select count(*) from artifact_sources where workspace_id = $1")
.bind(workspace_id.as_str())
.fetch_one(registry.pool())
.await
.unwrap();
assert_eq!(source_count, 0, "unsafe upload created an artifact source");
}
#[tokio::test]
#[serial]
async fn legacy_apply_rejects_required_auth_without_binding_before_creating_draft() {
let registry = test_registry().await;
let service = test_service(
registry.clone(),
test_storage_root("openapi_import_unresolved_auth"),
test_auth_settings(),
test_secret_crypto(),
);
let workspace_id = WorkspaceId::new("ws_default");
let upload = OpenApiUpload {
bytes: br#"{
"openapi":"3.0.3",
"info":{"title":"Required auth","version":"1"},
"servers":[{"url":"https://api.example.test"}],
"components":{"securitySchemes":{"bearer":{"type":"http","scheme":"bearer"}}},
"security":[{"bearer":[]}],
"paths":{"/secure":{"get":{"operationId":"secureOperation","responses":{"200":{"description":"ok"}}}}}
}"#
.to_vec(),
mime_type: "application/json".to_owned(),
locale: OpenApiUploadLocale::En,
};
let preview = service
.preview_openapi_import(&workspace_id, upload)
.await
.unwrap();
let result = service
.create_openapi_import(
&workspace_id,
&preview.job_id.as_str().into(),
OpenApiImportCreatePayload {
selected_operation_keys: vec!["GET /secure".to_owned()],
server_url: None,
conflict_mode: "rename".to_owned(),
},
)
.await;
let error = result.expect_err("legacy apply cannot bypass unresolved required auth");
assert!(format!("{error:?}").contains("invalid_document"));
assert!(
service
.list_operations(&workspace_id)
.await
.unwrap()
.is_empty()
);
let job = registry
.get_import_job(&workspace_id, &preview.job_id.as_str().into())
.await
.unwrap()
.unwrap();
assert_eq!(job.status, ImportJobStatus::Failed);
}
const OPENAPI3: &str = r#"
openapi: 3.0.3
@@ -85,11 +192,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-v5"
crank_import::rest::NORMALIZER_VERSION
);
assert_eq!(
preview_job.preview_payload["normalization"]["projection_version"],
"preview-v5"
crank_import::rest::PROJECTION_VERSION
);
assert!(preview_job.preview_payload["normalization"]["ir_fingerprint"].is_string());
@@ -99,7 +206,6 @@ 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(),
},
@@ -118,7 +224,6 @@ 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(),
},
@@ -171,7 +276,6 @@ 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(),
},
@@ -194,7 +298,6 @@ 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(),
},
@@ -224,7 +327,6 @@ 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(),
};
@@ -266,7 +368,6 @@ 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(),
};
@@ -321,7 +422,6 @@ 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(),
},
@@ -363,7 +463,6 @@ 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(),
},
@@ -440,7 +539,6 @@ 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(),
}
@@ -509,7 +607,6 @@ 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(),
},
@@ -564,7 +661,6 @@ 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(),
},
@@ -652,7 +748,6 @@ 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(),
},
@@ -671,7 +766,6 @@ 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(),
},
@@ -753,7 +847,6 @@ 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(),
},