fix(anatomy): R5.3 __proto__ field segments refused, seed identity guard over the whole seed tree, hashed id comparisons
This commit is contained in:
1 parent
3ece1a64b1
commit
f245b3ec25
7 files changed
+86
-33
No files matched your search
@@ -309,7 +309,8 @@ fn synthetic_seed(document_json: &str) -> String {
|
||||
}
|
||||
|
||||
/// Cases the TypeScript accepted and the port refuses, declared in RUST.md §11.12.
|
||||
const DECLARED_REFUSALS: [&str; 3] = [
|
||||
const DECLARED_REFUSALS: [&str; 4] = [
|
||||
"declared-proto-segment-overwritten",
|
||||
"declared-set-without-value-drops-key",
|
||||
"declared-children-string-renamed-then-removed",
|
||||
"declared-children-object-then-added-to",
|
||||
@@ -386,7 +387,12 @@ fn the_synthetic_cases_match_the_typescript_or_are_refused_alike() {
|
||||
let error = outcome
|
||||
.err()
|
||||
.unwrap_or_else(|| panic!("{name}: the TypeScript refused, the port accepted"));
|
||||
if name == "declared-children-object-then-added-to" {
|
||||
if name == "declared-proto-segment-overwritten" {
|
||||
assert!(
|
||||
error.to_string().contains("reserved key \"__proto__\""),
|
||||
"{name}"
|
||||
);
|
||||
} else if name == "declared-children-object-then-added-to" {
|
||||
assert!(error.to_string().contains("that is not a list"), "{name}");
|
||||
} else if name == "declared-children-string-renamed-then-removed" {
|
||||
assert!(
|
||||
@@ -441,7 +447,7 @@ fn the_synthetic_cases_match_the_typescript_or_are_refused_alike() {
|
||||
"{name} seed"
|
||||
);
|
||||
}
|
||||
assert_eq!((compared, refused), (14, 66));
|
||||
assert_eq!((compared, refused), (14, 67));
|
||||
let reference_cases = frozen["reference_cases"].as_array().unwrap();
|
||||
assert_eq!(reference_cases.len(), 7);
|
||||
for case in reference_cases {
|
||||
@@ -517,17 +523,12 @@ fn mobility(document: &Value) -> &Value {
|
||||
/// strict, so the key cannot reach the document. The only accepted form is a key a later op
|
||||
/// replaces: the document is then the one the later op alone gives; one record traces the
|
||||
/// overwritten write. The TypeScript refused that form (structuredClone of the function read).
|
||||
/// `__proto__` is refused at the op (`a_proto_segment_is_refused_at_the_op`).
|
||||
#[test]
|
||||
fn an_inherited_member_name_is_a_plain_key_and_bypasses_nothing() {
|
||||
let renamed = json!({ "fr": "Mobilité", "en": "Mobility" });
|
||||
let set_name = json!({ "op": "set", "target": MOBILITY, "field": "name", "value": renamed });
|
||||
for member in [
|
||||
"constructor",
|
||||
"toString",
|
||||
"__proto__",
|
||||
"hasOwnProperty",
|
||||
"valueOf",
|
||||
] {
|
||||
for member in ["constructor", "toString", "hasOwnProperty", "valueOf"] {
|
||||
let field = format!("name.{member}");
|
||||
let write = json!({ "op": "set", "target": MOBILITY, "field": field, "value": "x" });
|
||||
let kept = mini_apply(json!([write])).unwrap_err();
|
||||
@@ -753,3 +754,25 @@ fn the_document_cannot_hold_more_values_than_the_bound() {
|
||||
let error = mini_apply(json!([op])).unwrap_err();
|
||||
assert!(error.contains("more than 200000 values"), "{error}");
|
||||
}
|
||||
|
||||
/// A `__proto__` segment had no faithful reading in the TypeScript (a prototype set, a
|
||||
/// polluted `Object.prototype`, or nothing written): the port refuses it at the op.
|
||||
#[test]
|
||||
fn a_proto_segment_is_refused_at_the_op() {
|
||||
let renamed = json!({ "fr": "a", "en": "b" });
|
||||
let set_name = json!({ "op": "set", "target": MOBILITY, "field": "name", "value": renamed });
|
||||
for field in [
|
||||
"name.__proto__",
|
||||
"name.__proto__.x",
|
||||
"description.__proto__.fr",
|
||||
] {
|
||||
let write = json!({ "op": "set", "target": MOBILITY, "field": field, "value": "x" });
|
||||
for ops in [json!([write]), json!([write, set_name])] {
|
||||
let error = mini_apply(ops).unwrap_err();
|
||||
assert!(
|
||||
error.contains("CHG-001 op 0: reserved key \"__proto__\""),
|
||||
"{field}: {error}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user