mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
feat(secrets): implement SecretStore interface and StaticStore/LocalStore for credential management
This commit is contained in:
parent
ccce61694b
commit
ee1fc327e2
13 changed files with 531 additions and 34 deletions
41
pkg/secrets/encryption_test.go
Normal file
41
pkg/secrets/encryption_test.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package secrets
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDeriveAESKey(t *testing.T) {
|
||||
masterKey := []byte("testmasterkey")
|
||||
secretID := "mySecretID"
|
||||
key1 := deriveAESKey(masterKey, secretID)
|
||||
key2 := deriveAESKey(masterKey, secretID)
|
||||
|
||||
if len(key1) != 32 {
|
||||
t.Errorf("derived key should be 32 bytes, got %d", len(key1))
|
||||
}
|
||||
if string(key1) != string(key2) {
|
||||
t.Errorf("keys derived from same secretID should match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptDecryptAESGCM(t *testing.T) {
|
||||
masterKey := []byte("anotherTestMasterKey")
|
||||
secretID := "testSecret"
|
||||
plaintext := "Hello, secrets!"
|
||||
|
||||
key := deriveAESKey(masterKey, secretID)
|
||||
|
||||
encrypted, err := encryptAESGCM(key, []byte(plaintext))
|
||||
if err != nil {
|
||||
t.Fatalf("encryption failed: %v", err)
|
||||
}
|
||||
|
||||
decrypted, err := decryptAESGCM(key, encrypted)
|
||||
if err != nil {
|
||||
t.Fatalf("decryption failed: %v", err)
|
||||
}
|
||||
|
||||
if decrypted != plaintext {
|
||||
t.Errorf("expected %q, got %q", plaintext, decrypted)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue