-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcrypto_test.go
41 lines (37 loc) · 1.36 KB
/
crypto_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import "testing"
func TestConfigEncryption(t *testing.T) {
// Testing encryptConfig
plainText := "Test string."
if encrypted, err := encryptConfig(plainText); err != nil {
t.Errorf("encryptConfig returned an error: %s", err.Error())
} else {
if decrypted, err := decryptConfig(encrypted); decrypted != plainText {
t.Errorf("decryptConfig(encryptConfig('%s')) == %s, should be '%s'", plainText, decrypted, plainText)
} else if err != nil {
t.Errorf("decryptConfig returned an error: %s", err.Error())
}
}
}
func TestAESEncryption(t *testing.T) {
plainText := "Test string."
password := "Password1!"
encrypted := encryptString(password, plainText)
if decrypted := decryptString(password, encrypted); decrypted != plainText {
t.Errorf("decryptConfig(encryptConfig('%s')) == %s, should be '%s'", plainText, decrypted, plainText)
}
}
func TestObfuscation(t *testing.T) {
// Testing obfuscateData
plainText := "I am data!"
cipherText := "I am data!"
if err := obfuscateData(&cipherText); err != nil {
t.Errorf("obfuscateData returned an error: %s", err.Error())
} else {
if err := deobfuscateData(&cipherText); cipherText != plainText {
t.Errorf("deobfuscateData(obfuscateData(%s)) == %s, should be '%s'", plainText, cipherText, plainText)
} else if err != nil {
t.Errorf("deobufscateData returned an error: %s", err.Error())
}
}
}