@@ -37,7 +37,7 @@ func TestEncryptionRequiresPassword(t *testing.T) {
3737
3838 _ , err := Open (t .TempDir (), config )
3939 require .Error (t , err , "should fail without password" )
40- assert .Contains (t , err .Error (), "no password provided " )
40+ assert .Contains (t , err .Error (), "no password" )
4141}
4242
4343func TestEncryptionInitialization (t * testing.T ) {
@@ -56,7 +56,7 @@ func TestEncryptionInitialization(t *testing.T) {
5656
5757 stats := db .EncryptionStats ()
5858 assert .True (t , stats ["enabled" ].(bool ))
59- assert .Equal (t , "AES-256-GCM " , stats ["algorithm" ])
59+ assert .Equal (t , "AES-256 (BadgerDB) " , stats ["algorithm" ])
6060 assert .Contains (t , stats ["key_derivation" ], "PBKDF2" )
6161}
6262
@@ -104,7 +104,7 @@ func TestEncryptionPersistsSalt(t *testing.T) {
104104 db1 .Close ()
105105
106106 // Verify salt file was created
107- saltFile := tmpDir + "/encryption .salt"
107+ saltFile := tmpDir + "/db .salt"
108108 saltData , err := os .ReadFile (saltFile )
109109 require .NoError (t , err )
110110 assert .Len (t , saltData , 32 , "salt should be 32 bytes" )
@@ -198,17 +198,10 @@ func TestEncryptionDataAtRest(t *testing.T) {
198198 })
199199 require .NoError (t , err )
200200
201- // Access raw storage to verify encryption at rest
202- rawNode , err := db .storage .GetNode (storageNodeID (node .ID ))
203- require .NoError (t , err )
204-
205- // The SSN in raw storage should be encrypted (starts with "enc:")
206- rawSSN , ok := rawNode .Properties ["ssn" ].(string )
207- require .True (t , ok , "ssn should be a string" )
208- assert .True (t , strings .HasPrefix (rawSSN , "enc:" ), "SSN should be encrypted at rest, got: %s" , rawSSN )
209- assert .NotEqual (t , sensitiveSSN , rawSSN , "SSN should not be stored in plaintext" )
201+ // For full-database encryption we cannot inspect raw storage (Badger handles it).
202+ // Instead, verify encryption is reported and data round-trips correctly.
203+ assert .True (t , db .IsEncryptionEnabled (), "encryption should be enabled" )
210204
211- // But when retrieved through DB API, it should be decrypted
212205 retrieved , err := db .GetNode (ctx , node .ID )
213206 require .NoError (t , err )
214207 assert .Equal (t , sensitiveSSN , retrieved .Properties ["ssn" ])
@@ -238,18 +231,8 @@ func TestEncryptionWithCustomFields(t *testing.T) {
238231 })
239232 require .NoError (t , err )
240233
241- // Check raw storage
242- rawNode , err := db .storage .GetNode (storageNodeID (node .ID ))
243- require .NoError (t , err )
244-
245- // Custom fields should be encrypted
246- rawSecret , _ := rawNode .Properties ["custom_secret" ].(string )
247- assert .True (t , strings .HasPrefix (rawSecret , "enc:" ), "custom_secret should be encrypted" )
248-
249- rawInternal , _ := rawNode .Properties ["internal_id" ].(string )
250- assert .True (t , strings .HasPrefix (rawInternal , "enc:" ), "internal_id should be encrypted" )
251-
252- // But when retrieved, they should be decrypted
234+ // With full-database encryption, Badger handles encryption transparently.
235+ // Just verify round-trip decryption works.
253236 retrieved , err := db .GetNode (ctx , node .ID )
254237 require .NoError (t , err )
255238 assert .Equal (t , "my-secret-value" , retrieved .Properties ["custom_secret" ])
@@ -588,20 +571,8 @@ func TestEncryptionWrongPassword(t *testing.T) {
588571 AutoLinksEnabled : false ,
589572 }
590573
591- db2 , err := Open (tmpDir , config2 )
592- require .NoError (t , err )
593- defer db2 .Close ()
594-
595- // Attempting to query should fail or return corrupted data
596- // This tests that wrong password doesn't silently work
597- result , err := db2 .ExecuteCypher (ctx , "MATCH (n:Secret) RETURN n.ssn" , nil )
598- if err == nil && len (result .Rows ) > 0 {
599- // If no error, the decrypted value should NOT be the original
600- // (wrong key produces garbage, not the original plaintext)
601- decryptedSSN := result .Rows [0 ][0 ]
602- // It might be the encrypted string or garbage - either way, not "123-45-6789"
603- t .Logf ("Decrypted with wrong password: %v" , decryptedSSN )
604- }
574+ _ , err = Open (tmpDir , config2 )
575+ require .Error (t , err , "should fail to open with wrong password" )
605576}
606577
607578func TestEncryptionEmptyProperties (t * testing.T ) {
0 commit comments