1- //! The v4 counterpart of `catalog_parity.rs`: every v4 inventory entry must be
2- //! the catalog domain it claims, under the `eql_v4` names, and the version
3- //! boundary between the two generations must hold in both directions. A v3
4- //! payload that a v4 type accepted would let a cipherstash-client value be
5- //! read as a Stack Encrypt one (ADR-0002), so these are pinned with literals
6- //! rather than through the helpers they check.
1+ //! Every v4 inventory entry is the eql-domains catalog domain it claims,
2+ //! under its `eql_v4` name and schema id, and a v4 type admits only `"v": 4`.
3+ //! The expected names and ids are written as literals rather than through the
4+ //! helpers they check.
75
86// `eql_bindings::v4` exists only with the `stack-encrypt` feature.
97#![ cfg( feature = "stack-encrypt" ) ]
108
11- use eql_bindings:: { v3 , v4 } ;
9+ use eql_bindings:: v4 ;
1210use eql_domains:: { Term , CATALOG } ;
1311use serde_json:: { json, Value } ;
1412
1513/// The catalog's scalar domains under their v4 names, in catalog order. v4 has
16- /// no SteVec bindings, so only scalar domains appear.
14+ /// no SteVec bindings, so only scalar domains appear. The catalog spells each
15+ /// name with the `eql_v3_` prefix, which is swapped for v4's.
1716fn expected_v4_domains ( ) -> Vec < String > {
1817 CATALOG
1918 . iter ( )
@@ -26,7 +25,7 @@ fn expected_v4_domains() -> Vec<String> {
2625 . map ( |name| {
2726 let bare = name
2827 . strip_prefix ( eql_domains:: PUBLIC_TYPNAME_PREFIX )
29- . unwrap_or_else ( || panic ! ( "{name} does not carry the v3 typname prefix" ) ) ;
28+ . unwrap_or_else ( || panic ! ( "{name} does not carry the catalog typname prefix" ) ) ;
3029 format ! ( "{}{bare}" , v4:: PUBLIC_TYPNAME_PREFIX )
3130 } )
3231 . collect ( )
@@ -58,32 +57,19 @@ fn stored_entries_name_public_v4_domains_and_v4_schema_ids() {
5857
5958#[ test]
6059fn query_entries_live_in_the_eql_v4_schema ( ) {
61- let v3_queries: Vec < String > = v3:: all_query ( )
62- . iter ( )
63- . filter ( |e| e. term_json_keys ( ) . is_some ( ) )
64- . map ( |e| e. domain ( ) . to_string ( ) )
65- . collect ( ) ;
66- let v4_queries: Vec < String > = v4:: all_query ( )
67- . iter ( )
68- . map ( |e| {
69- let sql = e. sql_domain ( ) ;
70- assert ! ( sql. starts_with( "eql_v4.query_" ) , "{sql}" ) ;
71- e. domain ( ) . to_string ( )
72- } )
73- . collect ( ) ;
74- assert_eq ! (
75- v4_queries, v3_queries,
76- "each scalar query twin exists in v4 under the same name"
77- ) ;
60+ for entry in v4:: all_query ( ) {
61+ let sql = entry. sql_domain ( ) ;
62+ assert ! ( sql. starts_with( "eql_v4.query_" ) , "{sql}" ) ;
63+ }
7864}
7965
8066#[ test]
8167fn term_keys_match_the_catalog ( ) {
8268 let entries = v4:: all ( ) ;
8369 for spec in CATALOG {
8470 for domain in spec. domains . iter ( ) . filter ( |d| d. is_scalar ( ) ) {
85- let v3_name = spec. domain_name ( domain) ;
86- let name = v3_name . replacen ( "eql_v3_" , "eql_v4_" , 1 ) ;
71+ let catalog_name = spec. domain_name ( domain) ;
72+ let name = catalog_name . replacen ( "eql_v3_" , "eql_v4_" , 1 ) ;
8773 let entry = entries
8874 . iter ( )
8975 . find ( |e| e. domain ( ) == name)
@@ -97,7 +83,7 @@ fn term_keys_match_the_catalog() {
9783 }
9884}
9985
100- fn text_eq ( version : u8 ) -> Value {
86+ fn text_eq ( version : u16 ) -> Value {
10187 json ! ( {
10288 "v" : version,
10389 "i" : { "t" : "users" , "c" : "email" } ,
@@ -106,24 +92,27 @@ fn text_eq(version: u8) -> Value {
10692 } )
10793}
10894
109- /// The boundary the move to v4 relies on: the payloads are otherwise
110- /// well-formed, so only the version can be what refuses them .
95+ /// The payload is otherwise well-formed, so only the version can be what
96+ /// refuses it .
11197#[ test]
112- fn each_generation_refuses_the_other_version ( ) {
98+ fn a_v4_type_admits_only_version_4 ( ) {
11399 assert ! ( serde_json:: from_value:: <v4:: text:: TextEq >( text_eq( 4 ) ) . is_ok( ) ) ;
114- assert ! ( serde_json:: from_value:: <v3:: text:: TextEq >( text_eq( 3 ) ) . is_ok( ) ) ;
115-
116- let err = serde_json:: from_value :: < v4:: text:: TextEq > ( text_eq ( 3 ) ) . unwrap_err ( ) ;
117- assert ! ( err. to_string( ) . contains( "version 3" ) , "{err}" ) ;
118- let err = serde_json:: from_value :: < v3:: text:: TextEq > ( text_eq ( 4 ) ) . unwrap_err ( ) ;
119- assert ! ( err. to_string( ) . contains( "version 4" ) , "{err}" ) ;
100+ for version in [ 0 , 3 , 5 ] {
101+ let err = serde_json:: from_value :: < v4:: text:: TextEq > ( text_eq ( version) ) . unwrap_err ( ) ;
102+ assert ! (
103+ err. to_string( ) . contains( & format!(
104+ "unsupported EQL schema version {version} (expected 4)"
105+ ) ) ,
106+ "{err}"
107+ ) ;
108+ }
120109
121110 // And through the inventory, which is how a caller holding only a name
122111 // validates a payload.
123- let v4_entry = v4:: all ( )
112+ let entry = v4:: all ( )
124113 . into_iter ( )
125114 . find ( |e| e. domain ( ) == "eql_v4_text_eq" )
126115 . expect ( "eql_v4_text_eq in v4::all()" ) ;
127- assert ! ( v4_entry . parse_value( & text_eq( 4 ) ) . is_ok( ) ) ;
128- assert ! ( v4_entry . parse_value( & text_eq( 3 ) ) . is_err( ) ) ;
116+ assert ! ( entry . parse_value( & text_eq( 4 ) ) . is_ok( ) ) ;
117+ assert ! ( entry . parse_value( & text_eq( 3 ) ) . is_err( ) ) ;
129118}
0 commit comments