mirror of
https://github.com/netbirdio/netbird.git
synced 2024-11-29 19:43:57 +01:00
da7b6b11ad
Extend the deleted user info with the username - Because initially, we did not store the user name in the activity db Sometimes, we can not provide the user name in the API response. Fix service user deletion - In case of service user deletion, do not invoke the IdP delete function - Prevent self deletion
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerateKey(t *testing.T) {
|
|
testData := "exampl@netbird.io"
|
|
key, err := GenerateKey()
|
|
if err != nil {
|
|
t.Fatalf("failed to generate key: %s", err)
|
|
}
|
|
ee, err := NewFieldEncrypt(key)
|
|
if err != nil {
|
|
t.Fatalf("failed to init email encryption: %s", err)
|
|
}
|
|
|
|
encrypted := ee.Encrypt(testData)
|
|
if encrypted == "" {
|
|
t.Fatalf("invalid encrypted text")
|
|
}
|
|
|
|
decrypted, err := ee.Decrypt(encrypted)
|
|
if err != nil {
|
|
t.Fatalf("failed to decrypt data: %s", err)
|
|
}
|
|
|
|
if decrypted != testData {
|
|
t.Fatalf("decrypted data is not match with test data: %s, %s", testData, decrypted)
|
|
}
|
|
}
|
|
|
|
func TestCorruptKey(t *testing.T) {
|
|
testData := "exampl@netbird.io"
|
|
key, err := GenerateKey()
|
|
if err != nil {
|
|
t.Fatalf("failed to generate key: %s", err)
|
|
}
|
|
ee, err := NewFieldEncrypt(key)
|
|
if err != nil {
|
|
t.Fatalf("failed to init email encryption: %s", err)
|
|
}
|
|
|
|
encrypted := ee.Encrypt(testData)
|
|
if encrypted == "" {
|
|
t.Fatalf("invalid encrypted text")
|
|
}
|
|
|
|
newKey, err := GenerateKey()
|
|
if err != nil {
|
|
t.Fatalf("failed to generate key: %s", err)
|
|
}
|
|
|
|
ee, err = NewFieldEncrypt(newKey)
|
|
if err != nil {
|
|
t.Fatalf("failed to init email encryption: %s", err)
|
|
}
|
|
|
|
res, _ := ee.Decrypt(encrypted)
|
|
if res == testData {
|
|
t.Fatalf("incorrect decryption, the result is: %s", res)
|
|
}
|
|
}
|