@@ -67,4 +67,166 @@ mod tests {
6767 "DECRYPTION FAILED: Round-trip value doesn't match original!"
6868 ) ;
6969 }
70+
71+ #[ tokio:: test]
72+ async fn float8_encryption_sanity_check ( ) {
73+ trace ( ) ;
74+ clear ( ) . await ;
75+
76+ let id = random_id ( ) ;
77+ let plaintext: f64 = 3.14159 ;
78+
79+ // Insert through proxy (should encrypt)
80+ let client = connect_with_tls ( PROXY ) . await ;
81+ let sql = "INSERT INTO encrypted (id, encrypted_float8) VALUES ($1, $2)" ;
82+ client. query ( sql, & [ & id, & plaintext] ) . await . unwrap ( ) ;
83+
84+ // Verify encryption occurred
85+ assert_encrypted_numeric ( id, "encrypted_float8" , plaintext) . await ;
86+
87+ // Round-trip: query through proxy should decrypt back to original
88+ let sql = "SELECT encrypted_float8 FROM encrypted WHERE id = $1" ;
89+ let rows = client. query ( sql, & [ & id] ) . await . unwrap ( ) ;
90+ assert_eq ! ( rows. len( ) , 1 , "Expected exactly one row for round-trip" ) ;
91+ let decrypted: f64 = rows[ 0 ] . get ( 0 ) ;
92+ assert ! (
93+ ( decrypted - plaintext) . abs( ) < f64 :: EPSILON ,
94+ "DECRYPTION FAILED: Round-trip value doesn't match original!"
95+ ) ;
96+ }
97+
98+ #[ tokio:: test]
99+ async fn bool_encryption_sanity_check ( ) {
100+ trace ( ) ;
101+ clear ( ) . await ;
102+
103+ let id = random_id ( ) ;
104+ let plaintext: bool = true ;
105+
106+ // Insert through proxy (should encrypt)
107+ let client = connect_with_tls ( PROXY ) . await ;
108+ let sql = "INSERT INTO encrypted (id, encrypted_bool) VALUES ($1, $2)" ;
109+ client. query ( sql, & [ & id, & plaintext] ) . await . unwrap ( ) ;
110+
111+ // Verify encryption occurred
112+ assert_encrypted_text ( id, "encrypted_bool" , & plaintext. to_string ( ) ) . await ;
113+
114+ // Round-trip: query through proxy should decrypt back to original
115+ let sql = "SELECT encrypted_bool FROM encrypted WHERE id = $1" ;
116+ let rows = client. query ( sql, & [ & id] ) . await . unwrap ( ) ;
117+ assert_eq ! ( rows. len( ) , 1 , "Expected exactly one row for round-trip" ) ;
118+ let decrypted: bool = rows[ 0 ] . get ( 0 ) ;
119+ assert_eq ! (
120+ decrypted, plaintext,
121+ "DECRYPTION FAILED: Round-trip value doesn't match original!"
122+ ) ;
123+ }
124+
125+ #[ tokio:: test]
126+ async fn date_encryption_sanity_check ( ) {
127+ trace ( ) ;
128+ clear ( ) . await ;
129+
130+ let id = random_id ( ) ;
131+ let plaintext = NaiveDate :: from_ymd_opt ( 2024 , 6 , 15 ) . unwrap ( ) ;
132+
133+ // Insert through proxy (should encrypt)
134+ let client = connect_with_tls ( PROXY ) . await ;
135+ let sql = "INSERT INTO encrypted (id, encrypted_date) VALUES ($1, $2)" ;
136+ client. query ( sql, & [ & id, & plaintext] ) . await . unwrap ( ) ;
137+
138+ // Verify encryption occurred
139+ assert_encrypted_text ( id, "encrypted_date" , & plaintext. to_string ( ) ) . await ;
140+
141+ // Round-trip: query through proxy should decrypt back to original
142+ let sql = "SELECT encrypted_date FROM encrypted WHERE id = $1" ;
143+ let rows = client. query ( sql, & [ & id] ) . await . unwrap ( ) ;
144+ assert_eq ! ( rows. len( ) , 1 , "Expected exactly one row for round-trip" ) ;
145+ let decrypted: NaiveDate = rows[ 0 ] . get ( 0 ) ;
146+ assert_eq ! (
147+ decrypted, plaintext,
148+ "DECRYPTION FAILED: Round-trip value doesn't match original!"
149+ ) ;
150+ }
151+
152+ #[ tokio:: test]
153+ async fn int2_encryption_sanity_check ( ) {
154+ trace ( ) ;
155+ clear ( ) . await ;
156+
157+ let id = random_id ( ) ;
158+ let plaintext: i16 = 42 ;
159+
160+ // Insert through proxy (should encrypt)
161+ let client = connect_with_tls ( PROXY ) . await ;
162+ let sql = "INSERT INTO encrypted (id, encrypted_int2) VALUES ($1, $2)" ;
163+ client. query ( sql, & [ & id, & plaintext] ) . await . unwrap ( ) ;
164+
165+ // Verify encryption occurred
166+ assert_encrypted_numeric ( id, "encrypted_int2" , plaintext) . await ;
167+
168+ // Round-trip: query through proxy should decrypt back to original
169+ let sql = "SELECT encrypted_int2 FROM encrypted WHERE id = $1" ;
170+ let rows = client. query ( sql, & [ & id] ) . await . unwrap ( ) ;
171+ assert_eq ! ( rows. len( ) , 1 , "Expected exactly one row for round-trip" ) ;
172+ let decrypted: i16 = rows[ 0 ] . get ( 0 ) ;
173+ assert_eq ! (
174+ decrypted, plaintext,
175+ "DECRYPTION FAILED: Round-trip value doesn't match original!"
176+ ) ;
177+ }
178+
179+ #[ tokio:: test]
180+ async fn int4_encryption_sanity_check ( ) {
181+ trace ( ) ;
182+ clear ( ) . await ;
183+
184+ let id = random_id ( ) ;
185+ let plaintext: i32 = 12345 ;
186+
187+ // Insert through proxy (should encrypt)
188+ let client = connect_with_tls ( PROXY ) . await ;
189+ let sql = "INSERT INTO encrypted (id, encrypted_int4) VALUES ($1, $2)" ;
190+ client. query ( sql, & [ & id, & plaintext] ) . await . unwrap ( ) ;
191+
192+ // Verify encryption occurred
193+ assert_encrypted_numeric ( id, "encrypted_int4" , plaintext) . await ;
194+
195+ // Round-trip: query through proxy should decrypt back to original
196+ let sql = "SELECT encrypted_int4 FROM encrypted WHERE id = $1" ;
197+ let rows = client. query ( sql, & [ & id] ) . await . unwrap ( ) ;
198+ assert_eq ! ( rows. len( ) , 1 , "Expected exactly one row for round-trip" ) ;
199+ let decrypted: i32 = rows[ 0 ] . get ( 0 ) ;
200+ assert_eq ! (
201+ decrypted, plaintext,
202+ "DECRYPTION FAILED: Round-trip value doesn't match original!"
203+ ) ;
204+ }
205+
206+ #[ tokio:: test]
207+ async fn int8_encryption_sanity_check ( ) {
208+ trace ( ) ;
209+ clear ( ) . await ;
210+
211+ let id = random_id ( ) ;
212+ let plaintext: i64 = 9876543210 ;
213+
214+ // Insert through proxy (should encrypt)
215+ let client = connect_with_tls ( PROXY ) . await ;
216+ let sql = "INSERT INTO encrypted (id, encrypted_int8) VALUES ($1, $2)" ;
217+ client. query ( sql, & [ & id, & plaintext] ) . await . unwrap ( ) ;
218+
219+ // Verify encryption occurred
220+ assert_encrypted_numeric ( id, "encrypted_int8" , plaintext) . await ;
221+
222+ // Round-trip: query through proxy should decrypt back to original
223+ let sql = "SELECT encrypted_int8 FROM encrypted WHERE id = $1" ;
224+ let rows = client. query ( sql, & [ & id] ) . await . unwrap ( ) ;
225+ assert_eq ! ( rows. len( ) , 1 , "Expected exactly one row for round-trip" ) ;
226+ let decrypted: i64 = rows[ 0 ] . get ( 0 ) ;
227+ assert_eq ! (
228+ decrypted, plaintext,
229+ "DECRYPTION FAILED: Round-trip value doesn't match original!"
230+ ) ;
231+ }
70232}
0 commit comments