fix: read imported member records with retained legacy data keys
Deploy olons-admin production / deploy (push) Successful in 7m14s
Deploy olons-admin production / deploy (push) Successful in 7m14s
This commit is contained in:
@@ -81,6 +81,28 @@ func TestDecryptFieldKeepsLegacyHotGoDataReadable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecryptFieldReadsImportedHotGoKeyWithoutChangingCurrentKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
setFieldTestConfig(t, map[string]interface{}{"dataKey": "imported-original-data-key"})
|
||||
encoded, err := EncryptField(ctx, "迁移前的资料")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
setFieldTestConfig(t, map[string]interface{}{"dataKey": "current-data-key", "legacyDataKeys": []string{"imported-original-data-key"}, "financeMasterKey": "current-finance-master-key-with-at-least-32-characters"})
|
||||
plain, err := DecryptField(ctx, encoded)
|
||||
if err != nil || plain != "迁移前的资料" {
|
||||
t.Fatalf("imported record unreadable: %v", err)
|
||||
}
|
||||
current, err := EncryptField(ctx, "当前资料")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plain, err = DecryptField(ctx, current)
|
||||
if err != nil || plain != "当前资料" {
|
||||
t.Fatalf("current key was not preserved: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func setFieldTestConfig(t *testing.T, security map[string]interface{}) {
|
||||
t.Helper()
|
||||
data, err := json.Marshal(map[string]interface{}{"security": security})
|
||||
|
||||
Reference in New Issue
Block a user