Skip to content

Commit ee025bd

Browse files
committed
test(stack-encrypt): pin the one substitution only the position rule catches
Design decision 8 keeps the consecutive-position check, and the design record's example for it (corrected on #1361) is a read of one array element answered with the element itself and then the other element's child in place of its own, self tag rewritten: selector, label, depth and child count all agree, and only the row's authenticated position refuses it. No committed test isolated that case; the closest ones are also caught by the child counts or the selectors. This one opens to {"x": 2} for {"x": 1} with the j comparison in rebuild_walked removed. Refs #1363 Claude-Session: https://claude.ai/code/session_01N7bCqa3ZVJMcEE99RzVqEu
1 parent ba9a87f commit ee025bd

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎packages/stack-encrypt/tests/json_read_checks.rs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,37 @@ mod given_the_rows_of_a_read {
474474
assertions::wrong_entry(open_value(&cipher, a.open(rows)).await, NEXT);
475475
}
476476

477+
/// The one substitution only the consecutive-position rule catches
478+
/// (design decision 8): a read of `$.nested.list[0]` answered with the
479+
/// element itself (5) and then the other element's `x` (8) in place of
480+
/// its own (6), carrying 6's self tag. Every element's `x` shares one
481+
/// selector, the label is `x` either way, the depth and the parent's
482+
/// child count agree, and the forged self tag matches; the row's
483+
/// authenticated position, 8 where 6 is due, is the one thing that
484+
/// refuses it. Opened, it would read `{"x": 2}` for `{"x": 1}`.
485+
#[tokio::test]
486+
async fn another_elements_child_in_place_of_the_nodes_own_is_refused_by_its_position() {
487+
let (cipher, _) = cipher().await;
488+
let doc = seal(&cipher, &fixture()).await;
489+
let first = key(&cipher, "$.nested.list[0]").await;
490+
let honest = walk(&doc, &first);
491+
assert_eq!(
492+
honest.iter().map(|n| n.ordinal()).collect::<Vec<_>>(),
493+
[5, 6],
494+
"the element and its x"
495+
);
496+
assert_eq!(
497+
open_value(&cipher, first.open(honest)).await.unwrap(),
498+
json!({"x": 1})
499+
);
500+
let own_x = serde_json::to_value(doc.node(6).unwrap()).unwrap()["x"]
501+
.as_str()
502+
.unwrap()
503+
.to_owned();
504+
let swapped = with_x(vec![row(&doc, 5, Some(0)), row(&doc, 8, Some(1))], 1, own_x);
505+
assertions::wrong_entry(open_value(&cipher, first.open(swapped)).await, NEXT);
506+
}
507+
477508
#[tokio::test]
478509
async fn the_sealed_root_among_read_rows_is_refused() {
479510
let (cipher, _) = cipher().await;

0 commit comments

Comments
 (0)