Skip to content

Commit

Permalink
opening db with wrong key should fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanschalm committed Sep 24, 2021
1 parent 8e7c481 commit aab5d8e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions storage/badger/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,29 @@ func TestInitSecret(t *testing.T) {
require.Error(t, err)
})
}

// opening a database which has previously been opened with encryption enabled,
// using a different encryption key, should fail
func TestEncryptionKeyMismatch(t *testing.T) {
unittest.RunWithTempDir(t, func(dir string) {

// open a database with encryption enabled
key1 := unittest.SeedFixture(32)
db := unittest.TypedBadgerDB(t, dir, func(options badger.Options) (*badger.DB, error) {
options = options.WithEncryptionKey(key1)
return badger.Open(options)
})
db.Close()

// open the same database with a different key
key2 := unittest.SeedFixture(32)
opts := badger.
DefaultOptions(dir).
WithKeepL0InMemory(true).
WithEncryptionKey(key2).
WithLogger(nil)
_, err := badger.Open(opts)
// opening the database should return an error
require.Error(t, err)
})
}

0 comments on commit aab5d8e

Please sign in to comment.