mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-01-04 07:39:43 -06:00
* re-add new testing harness * add healthcheck port and pick random grpc port to listen on * feat: parallel load tests and faster tests * make parallelism = 5 * fix: lint * add linter to pre * fix: add back rampup fixes * reduce matrix on PR, add matrix to pre-release step * make load tests less likely to block * make limit strategy group round robin * uncomment lines
101 lines
2.7 KiB
Go
101 lines
2.7 KiB
Go
//go:build !e2e && !load && !rampup && !integration
|
|
|
|
package encryption
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewLocalEncryptionValidKeyset(t *testing.T) {
|
|
// Generate a new keyset
|
|
aes256Gcm, privateEc256, publicEc256, err := GenerateLocalKeys()
|
|
assert.NoError(t, err)
|
|
|
|
// Create encryption service
|
|
_, err = NewLocalEncryption(aes256Gcm, privateEc256, publicEc256)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestNewLocalEncryptionInvalidKeyset(t *testing.T) {
|
|
invalidKeysetBytes := []byte("invalid keyset")
|
|
|
|
// Create encryption service with invalid keyset
|
|
_, err := NewLocalEncryption(invalidKeysetBytes, invalidKeysetBytes, invalidKeysetBytes)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestEncryptDecrypt(t *testing.T) {
|
|
aes256Gcm, privateEc256, publicEc256, _ := GenerateLocalKeys()
|
|
svc, _ := NewLocalEncryption(aes256Gcm, privateEc256, publicEc256)
|
|
|
|
plaintext := []byte("test message")
|
|
dataID := "123"
|
|
|
|
// Encrypt
|
|
ciphertext, err := svc.Encrypt(plaintext, dataID)
|
|
assert.NoError(t, err)
|
|
|
|
// Decrypt
|
|
decryptedText, err := svc.Decrypt(ciphertext, dataID)
|
|
assert.NoError(t, err)
|
|
|
|
// Check if decrypted text matches original plaintext
|
|
assert.Equal(t, plaintext, decryptedText)
|
|
}
|
|
|
|
func TestEncryptDecryptStringBase64(t *testing.T) {
|
|
aes256Gcm, privateEc256, publicEc256, _ := GenerateLocalKeys()
|
|
svc, _ := NewLocalEncryption(aes256Gcm, privateEc256, publicEc256)
|
|
|
|
plaintext := "test message"
|
|
dataID := "456"
|
|
|
|
// Encrypt
|
|
ciphertext, err := svc.EncryptString(plaintext, dataID)
|
|
assert.NoError(t, err)
|
|
|
|
// Decrypt
|
|
decryptedText, err := svc.DecryptString(ciphertext, dataID)
|
|
assert.NoError(t, err)
|
|
|
|
// Check if decrypted text matches original plaintext
|
|
assert.Equal(t, plaintext, decryptedText)
|
|
}
|
|
|
|
func TestDecryptWithInvalidKey(t *testing.T) {
|
|
aes256Gcm, privateEc256, publicEc256, _ := GenerateLocalKeys()
|
|
svc, _ := NewLocalEncryption(aes256Gcm, privateEc256, publicEc256)
|
|
|
|
plaintext := []byte("test message")
|
|
dataID := "123"
|
|
|
|
// Encrypt
|
|
ciphertext, _ := svc.Encrypt(plaintext, dataID)
|
|
|
|
// Generate a new keyset for decryption
|
|
aes256Gcm, privateEc256, publicEc256, _ = GenerateLocalKeys()
|
|
newSvc, _ := NewLocalEncryption(aes256Gcm, privateEc256, publicEc256)
|
|
|
|
// Attempt to decrypt with a different key
|
|
_, err := newSvc.Decrypt(ciphertext, dataID)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func TestEncryptDecryptWithEmptyDataID(t *testing.T) {
|
|
aes256Gcm, privateEc256, publicEc256, _ := GenerateLocalKeys()
|
|
svc, _ := NewLocalEncryption(aes256Gcm, privateEc256, publicEc256)
|
|
|
|
plaintext := []byte("test message")
|
|
emptyDataID := ""
|
|
|
|
// Encrypt with empty data ID
|
|
_, err := svc.Encrypt(plaintext, emptyDataID)
|
|
assert.Error(t, err)
|
|
|
|
// Decrypt with empty data ID
|
|
_, err = svc.Decrypt(plaintext, emptyDataID)
|
|
assert.Error(t, err)
|
|
}
|