fix(import): единая идентичность внешних URI (#96)
Единая transport-canonical идентичность внешних документов; normalizer v6 с immutable historical replay; matrix 1.0.4 / corpus 1.0.5. PR CI run840 success, локальная приёмка и independent review выполнены. Co-authored-by: bsodfather <bsodfather@gmail.com>
This commit was merged in pull request #96.
This commit is contained in:
1 parent
178093e81b
commit
1b6db09bd1
22 files changed
+1669
-353
No files matched your search
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"corpus_version": "1.0.4",
|
||||
"matrix_version": "1.0.3",
|
||||
"corpus_version": "1.0.5",
|
||||
"matrix_version": "1.0.4",
|
||||
"digest_algorithm": "sha256",
|
||||
"canonical_digest_definition": "SHA-256 of compact JSON with lexicographically ordered keys; null for malformed JSON",
|
||||
"documents": [
|
||||
@@ -14407,7 +14407,29 @@
|
||||
"warning_findings": [],
|
||||
"blocker_findings": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "hostile-13",
|
||||
"file": "regression-uri-encoded-dot.yaml",
|
||||
"sha256": "9c3f73debd2f51449904c6691939e3bb3f8958f9562eac8b105cdf23a92cbc2d",
|
||||
"canonical_digest": null,
|
||||
"origin": "synthetic: Epic 2 external URI transport regression",
|
||||
"license": "CC0-1.0 synthetic; no third-party content",
|
||||
"specification_version": "OpenAPI 3.1",
|
||||
"classification": "hostile",
|
||||
"expected_preview": {}
|
||||
},
|
||||
{
|
||||
"id": "hostile-14",
|
||||
"file": "regression-uri-query-quote.yaml",
|
||||
"sha256": "b1c879285d4f5bfa64004fcc0dced1e115a1423d8a4c3a4c9a0699894e776c8f",
|
||||
"canonical_digest": null,
|
||||
"origin": "synthetic: Epic 2 external URI transport regression",
|
||||
"license": "CC0-1.0 synthetic; no third-party content",
|
||||
"specification_version": "OpenAPI 3.1",
|
||||
"classification": "hostile",
|
||||
"expected_preview": {}
|
||||
}
|
||||
],
|
||||
"compatibility_impact": "Corpus 1.0.4 is a metadata-only SemVer increment aligning its manifest with support matrix 1.0.3; fixture contents and checksums are unchanged. Corpus 1.0.3 added hostile-security-scope.json: a document-level basic requirement remains selectable on the inherited candidate while an explicit security: [] override stays public; malformed or unsupported requirements retain scoped blockers. Support matrix 1.0.3 adds executable blockers for undeclared path placeholders and object/array schema defaults across OpenAPI 3.0, OpenAPI 3.1, and Swagger 2.0 while preserving scalar defaults and previously supported behavior."
|
||||
"compatibility_impact": "Corpus 1.0.5 adds two hostile external-URI regression fixtures (regression-uri-encoded-dot.yaml, regression-uri-query-quote.yaml) and the reference_uri.rs positive-snapshot oracle: an encoded-dot path segment and an apostrophe query now canonicalize to the URL transport identity, so a supplied snapshot resolves while the default-deny pass and all statuses/denominators are unchanged. Support matrix 1.0.4 records the shared external HTTP(S) URI canonicalization contract without changing any construct status. Corpus 1.0.4 was a metadata-only SemVer increment aligning its manifest with support matrix 1.0.3; fixture contents and checksums were unchanged."
|
||||
}
|
||||
@@ -31,7 +31,7 @@ fn ac_1_support_matrix_rows_have_exact_construct_contracts() {
|
||||
let matrix_text = fs::read_to_string(tests_root().join("support-matrix.yaml"))
|
||||
.expect("support matrix exists");
|
||||
let matrix: serde_yaml::Value = serde_yaml::from_str(&matrix_text).expect("valid YAML");
|
||||
assert_eq!(matrix["matrix_version"].as_str(), Some("1.0.3"));
|
||||
assert_eq!(matrix["matrix_version"].as_str(), Some("1.0.4"));
|
||||
assert!(
|
||||
matrix["compatibility_impact"]
|
||||
.as_str()
|
||||
@@ -696,73 +696,100 @@ fn ac_1_support_matrix_rows_have_exact_construct_contracts() {
|
||||
row["specification_version"] == version && row["construct_id"] == construct
|
||||
})
|
||||
.unwrap();
|
||||
let reference = if external {
|
||||
"https://schemas.example.test/root.yaml#/Item"
|
||||
} else if version == "Swagger 2.0" {
|
||||
// The allowlisted-external row must exercise the same transport
|
||||
// canonicalization the materializer keys snapshots with. The
|
||||
// expected keys below are static literals, independent of the
|
||||
// production `canonical_external_document_uri` helper: a
|
||||
// percent-encoded dot segment collapses to its parent path and an
|
||||
// apostrophe in the query is percent-encoded (`%27`).
|
||||
let external_document = "Item: { type: object, properties: { id: { type: string } } }";
|
||||
let external_variants: [(&str, &str); 3] = [
|
||||
(
|
||||
"https://schemas.example.test/root.yaml#/Item",
|
||||
"https://schemas.example.test/root.yaml",
|
||||
),
|
||||
(
|
||||
"https://schemas.example.test/a/%2e%2e/root.yaml#/Item",
|
||||
"https://schemas.example.test/root.yaml",
|
||||
),
|
||||
(
|
||||
"https://schemas.example.test/schema.json?filter='x'#/Item",
|
||||
"https://schemas.example.test/schema.json?filter=%27x%27",
|
||||
),
|
||||
];
|
||||
let local_reference = if version == "Swagger 2.0" {
|
||||
"#/definitions/Item"
|
||||
} else {
|
||||
"#/components/schemas/Item"
|
||||
};
|
||||
let schema = json!({"$ref":reference});
|
||||
let response = if version == "Swagger 2.0" {
|
||||
json!({"description":"ok","schema":schema})
|
||||
let variants = if external {
|
||||
external_variants
|
||||
.iter()
|
||||
.map(|(reference, canonical_uri)| (*reference, Some(*canonical_uri)))
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
json!({"description":"ok","content":{"application/json":{"schema":schema}}})
|
||||
vec![(local_reference, None)]
|
||||
};
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
let mut root = json!({"swagger":"2.0","info":{"title":"Reference probe","version":"1"},"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
|
||||
if !external {
|
||||
root["definitions"] =
|
||||
json!({"Item":{"type":"object","properties":{"id":{"type":"string"}}}});
|
||||
}
|
||||
root
|
||||
} else {
|
||||
let mut root = json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Reference probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
|
||||
if !external {
|
||||
root["components"] = json!({"schemas":{"Item":{"type":"object","properties":{"id":{"type":"string"}}}}});
|
||||
}
|
||||
root
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = if external {
|
||||
let external_source =
|
||||
"Item: { type: object, properties: { id: { type: string } } }";
|
||||
let snapshot = crank_import::rest::ExternalDocumentSnapshot {
|
||||
canonical_uri: "https://schemas.example.test/root.yaml".to_owned(),
|
||||
digest: SourceDigest::parse(hex(external_source.as_bytes())).unwrap(),
|
||||
document: external_source.to_owned(),
|
||||
for (reference, canonical_uri) in variants {
|
||||
let schema = json!({"$ref":reference});
|
||||
let response = if version == "Swagger 2.0" {
|
||||
json!({"description":"ok","schema":schema})
|
||||
} else {
|
||||
json!({"description":"ok","content":{"application/json":{"schema":schema}}})
|
||||
};
|
||||
let digest = SourceDigest::parse(hex(source.as_bytes())).unwrap();
|
||||
normalize_verified_bundle(
|
||||
&source,
|
||||
digest,
|
||||
&[snapshot],
|
||||
&NormalizationConfig::default(),
|
||||
)
|
||||
.unwrap()
|
||||
} else {
|
||||
normalize(&source).unwrap()
|
||||
};
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
assert_eq!(row["status"], "supported");
|
||||
assert!(
|
||||
!ir.reference_graph.edges.is_empty(),
|
||||
"{version} {construct} did not resolve through a source-backed edge"
|
||||
);
|
||||
assert!(
|
||||
ir.unresolved_references.is_empty(),
|
||||
"{version} {construct} remains unresolved"
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
ir.operations[0].response_variants[0].schema.as_ref().map(|schema| &schema.kind),
|
||||
Some(NormalizedSchemaKind::Object { properties, .. }) if properties.contains_key("id")
|
||||
),
|
||||
"{version} {construct} resolved schema was not projected into the operation"
|
||||
);
|
||||
assert_actionable(&ir, &format!("{version} {construct}"));
|
||||
assert_eq!(row["expected_finding"], "none");
|
||||
let probe = if version == "Swagger 2.0" {
|
||||
let mut root = json!({"swagger":"2.0","info":{"title":"Reference probe","version":"1"},"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
|
||||
if !external {
|
||||
root["definitions"] =
|
||||
json!({"Item":{"type":"object","properties":{"id":{"type":"string"}}}});
|
||||
}
|
||||
root
|
||||
} else {
|
||||
let mut root = json!({"openapi":if version == "OpenAPI 3.0" {"3.0.3"} else {"3.1.0"},
|
||||
"info":{"title":"Reference probe","version":"1"},"servers":[{"url":"https://matrix.example.test"}],"paths":{"/probe":{"get":{"operationId":"referenceProbe","responses":{"200":response}}}}});
|
||||
if !external {
|
||||
root["components"] = json!({"schemas":{"Item":{"type":"object","properties":{"id":{"type":"string"}}}}});
|
||||
}
|
||||
root
|
||||
};
|
||||
let source = serde_json::to_string(&probe).unwrap();
|
||||
let ir = if let Some(canonical_uri) = canonical_uri {
|
||||
let snapshot = crank_import::rest::ExternalDocumentSnapshot {
|
||||
canonical_uri: canonical_uri.to_owned(),
|
||||
digest: SourceDigest::parse(hex(external_document.as_bytes())).unwrap(),
|
||||
document: external_document.to_owned(),
|
||||
};
|
||||
let digest = SourceDigest::parse(hex(source.as_bytes())).unwrap();
|
||||
normalize_verified_bundle(
|
||||
&source,
|
||||
digest,
|
||||
&[snapshot],
|
||||
&NormalizationConfig::default(),
|
||||
)
|
||||
.unwrap()
|
||||
} else {
|
||||
normalize(&source).unwrap()
|
||||
};
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
assert_eq!(row["status"], "supported");
|
||||
assert!(
|
||||
!ir.reference_graph.edges.is_empty(),
|
||||
"{version} {construct} did not resolve through a source-backed edge ({reference})"
|
||||
);
|
||||
assert!(
|
||||
ir.unresolved_references.is_empty(),
|
||||
"{version} {construct} remains unresolved ({reference})"
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
ir.operations[0].response_variants[0].schema.as_ref().map(|schema| &schema.kind),
|
||||
Some(NormalizedSchemaKind::Object { properties, .. }) if properties.contains_key("id")
|
||||
),
|
||||
"{version} {construct} resolved schema was not projected into the operation ({reference})"
|
||||
);
|
||||
assert_actionable(&ir, &format!("{version} {construct} {reference}"));
|
||||
assert_eq!(row["expected_finding"], "none");
|
||||
}
|
||||
probed(construct);
|
||||
}
|
||||
for code in 200..300 {
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
//! Positive and default-deny oracle for external HTTP(S) URI transport parity.
|
||||
//!
|
||||
//! These two regression fixtures pin the F1 defect: an encoded-dot path segment
|
||||
//! (`%2e%2e`) and an apostrophe query (`'`). Under the default configuration the
|
||||
//! external `$ref` must stay default-denied (the document-level pass
|
||||
//! `corpus.rs` characterizes); once a snapshot keyed by the URL transport
|
||||
//! canonical form is supplied, the reference must resolve. Keeping the positive
|
||||
//! snapshot oracle here, separate from the default-deny pass, means neither can
|
||||
//! mask the other, and both run the real pure resolver.
|
||||
|
||||
use super::*;
|
||||
use crank_import::rest::{
|
||||
ExternalDocumentSnapshot, NormalizedSchemaKind, SourceDigest, normalize_verified_bundle,
|
||||
};
|
||||
|
||||
struct Case {
|
||||
file: &'static str,
|
||||
/// The raw `$ref` exactly as it appears in the fixture.
|
||||
reference: &'static str,
|
||||
/// The `url::Url` transport canonical form the materializer would store.
|
||||
canonical_uri: &'static str,
|
||||
}
|
||||
|
||||
const CASES: &[Case] = &[
|
||||
Case {
|
||||
file: "regression-uri-encoded-dot.yaml",
|
||||
reference: "https://schemas.example.test/a/%2e%2e/root.yaml#/Item",
|
||||
canonical_uri: "https://schemas.example.test/root.yaml",
|
||||
},
|
||||
Case {
|
||||
file: "regression-uri-query-quote.yaml",
|
||||
reference: "https://schemas.example.test/schema.json?filter='x'#/Item",
|
||||
canonical_uri: "https://schemas.example.test/schema.json?filter=%27x%27",
|
||||
},
|
||||
];
|
||||
|
||||
fn fixture(file: &str) -> String {
|
||||
fs::read_to_string(tests_root().join("corpus").join(file))
|
||||
.unwrap_or_else(|error| panic!("{file}: {error}"))
|
||||
}
|
||||
|
||||
fn digest(byte: char) -> SourceDigest {
|
||||
SourceDigest::parse(byte.to_string().repeat(64)).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_deny_pass_keeps_each_external_uri_blocked_without_snapshots() {
|
||||
for case in CASES {
|
||||
let source = fixture(case.file);
|
||||
assert!(
|
||||
source.contains(case.reference),
|
||||
"{} fixture lost its raw $ref",
|
||||
case.file
|
||||
);
|
||||
let ir = normalize(&source).unwrap_or_else(|error| panic!("{}: {error}", case.file));
|
||||
validate_normalized_ir(&ir).unwrap();
|
||||
assert!(
|
||||
ir.findings
|
||||
.iter()
|
||||
.chain(
|
||||
ir.operations
|
||||
.iter()
|
||||
.flat_map(|operation| &operation.findings)
|
||||
)
|
||||
.any(|finding| finding.code == "external_reference_disabled"),
|
||||
"{} must default-deny its external $ref without a snapshot",
|
||||
case.file
|
||||
);
|
||||
assert!(
|
||||
ir.reference_graph.edges.is_empty(),
|
||||
"{} must not resolve without a supplied snapshot",
|
||||
case.file
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positive_snapshot_oracle_resolves_each_transport_canonical_uri() {
|
||||
let snapshot_document =
|
||||
"Item: { type: object, required: [id], properties: { id: { type: string } } }";
|
||||
for case in CASES {
|
||||
let source = fixture(case.file);
|
||||
let snapshots = vec![ExternalDocumentSnapshot {
|
||||
canonical_uri: case.canonical_uri.to_owned(),
|
||||
digest: digest('b'),
|
||||
document: snapshot_document.to_owned(),
|
||||
}];
|
||||
let config = NormalizationConfig {
|
||||
external_references_enabled: true,
|
||||
..NormalizationConfig::default()
|
||||
};
|
||||
let ir = normalize_verified_bundle(&source, digest('a'), &snapshots, &config)
|
||||
.unwrap_or_else(|error| panic!("{}: {error}", case.file));
|
||||
assert!(
|
||||
!ir.operations[0]
|
||||
.findings
|
||||
.iter()
|
||||
.any(|finding| finding.code == "external_reference_unavailable"),
|
||||
"{} resolved against the transport key but still reported unavailable: {:?}",
|
||||
case.file,
|
||||
ir.operations[0].findings
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
ir.operations[0]
|
||||
.response_schema
|
||||
.as_ref()
|
||||
.map(|schema| &schema.kind),
|
||||
Some(NormalizedSchemaKind::Object { properties, .. })
|
||||
if properties.contains_key("id")
|
||||
),
|
||||
"{} resolved schema must keep its `id` property",
|
||||
case.file
|
||||
);
|
||||
assert_eq!(ir.reference_graph.edges.len(), 1, "{}", case.file);
|
||||
assert_eq!(
|
||||
ir.reference_graph.edges[0].target.snapshot_digest,
|
||||
digest('b')
|
||||
);
|
||||
assert_eq!(ir.reference_graph.dependency_digests, vec![digest('b')]);
|
||||
assert!(ir.unresolved_references.is_empty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
openapi: 3.1.0
|
||||
info: { title: External URI encoded-dot regression, version: '1' }
|
||||
servers: [{ url: https://api.example.test }]
|
||||
paths:
|
||||
/items:
|
||||
get:
|
||||
operationId: encodedDot
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: 'https://schemas.example.test/a/%2e%2e/root.yaml#/Item' }
|
||||
@@ -0,0 +1,13 @@
|
||||
openapi: 3.1.0
|
||||
info: { title: External URI query-quote regression, version: '1' }
|
||||
servers: [{ url: https://api.example.test }]
|
||||
paths:
|
||||
/items:
|
||||
get:
|
||||
operationId: quotedQuery
|
||||
responses:
|
||||
'200':
|
||||
description: ok
|
||||
content:
|
||||
application/json:
|
||||
schema: { $ref: "https://schemas.example.test/schema.json?filter='x'#/Item" }
|
||||
Reference in new issue
Block a user