coller/src/internal/encryption_test.go
Julien Riou ef9aca1f3b
Initial commit
Signed-off-by: Julien Riou <julien@riou.xyz>
2025-08-21 16:22:03 +02:00

44 lines
899 B
Go

package internal
import (
"testing"
)
func TestEncryptAndDecrypt(t *testing.T) {
plaintext := "test"
password := "test"
wrongPassword := password + "wrong"
ciphertext, err := Encrypt([]byte(plaintext), password)
if err != nil {
t.Errorf("unexpected error when encrypting: %v", err)
return
}
if plaintext == string(ciphertext) {
t.Errorf("plaintext and ciphertext are equal")
return
}
cleartext, err := Decrypt(ciphertext, password)
if err != nil {
t.Errorf("unexpected error when decrypting: %v", err)
return
}
if string(cleartext) != string(plaintext) {
t.Errorf("got '%s', expected '%s'", cleartext, plaintext)
return
}
if password == wrongPassword {
t.Errorf("passwords must be different")
return
}
_, err = Decrypt(ciphertext, wrongPassword)
if err == nil {
t.Errorf("expected error when decrypting with a wrong password, got none")
return
}
}