@@ -12,6 +12,7 @@ mod tests {
1212 connect_with_tls, random_id, random_limited, trace, PROXY ,
1313 } ;
1414 use chrono:: NaiveDate ;
15+ use serde_json;
1516
1617 #[ tokio:: test]
1718 async fn text_encryption_sanity_check ( ) {
@@ -39,4 +40,31 @@ mod tests {
3940 "DECRYPTION FAILED: Round-trip value doesn't match original!"
4041 ) ;
4142 }
43+
44+ #[ tokio:: test]
45+ async fn jsonb_encryption_sanity_check ( ) {
46+ trace ( ) ;
47+ clear ( ) . await ;
48+
49+ let id = random_id ( ) ;
50+ let plaintext_json = serde_json:: json!( { "key" : "value" , "number" : 42 } ) ;
51+
52+ // Insert through proxy (should encrypt)
53+ let client = connect_with_tls ( PROXY ) . await ;
54+ let sql = "INSERT INTO encrypted (id, encrypted_jsonb) VALUES ($1, $2)" ;
55+ client. query ( sql, & [ & id, & plaintext_json] ) . await . unwrap ( ) ;
56+
57+ // Verify encryption occurred
58+ assert_encrypted_jsonb ( id, & plaintext_json) . await ;
59+
60+ // Round-trip: query through proxy should decrypt back to original
61+ let sql = "SELECT encrypted_jsonb FROM encrypted WHERE id = $1" ;
62+ let rows = client. query ( sql, & [ & id] ) . await . unwrap ( ) ;
63+ assert_eq ! ( rows. len( ) , 1 , "Expected exactly one row for round-trip" ) ;
64+ let decrypted: serde_json:: Value = rows[ 0 ] . get ( 0 ) ;
65+ assert_eq ! (
66+ decrypted, plaintext_json,
67+ "DECRYPTION FAILED: Round-trip value doesn't match original!"
68+ ) ;
69+ }
4270}
0 commit comments