package crypto_test import ( "bytes" "math/rand" "testing" "edge-infra.dev/pkg/edge/iam/crypto" ) func TestEncryption(t *testing.T) { data := []byte("Hello, world!") key := createEncryptionKey() ciphertext, _ := crypto.Encrypt(data, key) plaintext, _ := crypto.Decrypt(ciphertext, key) if !bytes.Equal(data, plaintext) { t.Errorf("input data does not match up with decrypted data") } } func TestJSONEncryption(t *testing.T) { data := []byte(`{"number": 2,"title": "test","url": "https://google.com"}`) key := createEncryptionKey() encryptedJSON, _ := crypto.EncryptJSON(data, key) plaintext, _ := crypto.DecryptJSON(encryptedJSON, key) if !bytes.Equal(data, plaintext) { t.Errorf("input data does not match up with decrypted data") } } func createEncryptionKey() []byte { charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" length := 32 key := make([]byte, length) for i := range key { key[i] = charset[rand.Intn(len(charset))] //nolint:gosec } return key }