-
Notifications
You must be signed in to change notification settings - Fork 0
/
starkRecords_test.go
45 lines (38 loc) · 985 Bytes
/
starkRecords_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
42
43
44
45
package stark
import (
"strings"
"testing"
starkcrypto "github.com/will-rowe/stark/src/crypto"
)
// TestRecord tests the record constructor and the UUID field encryption.
func TestRecord(t *testing.T) {
// construct a record
testAlias := "test label for a record"
rec, err := NewRecord(SetAlias(testAlias), SetDescription(testDescription))
if err != nil {
t.Fatal(err)
}
if rec.GetAlias() != strings.ReplaceAll(testAlias, " ", "_") {
t.Fatal("did not set alias for record")
}
originalUUID := rec.GetUuid()
// get a cipher key
cipherKey, err := starkcrypto.Password2cipherkey("some password")
if err != nil {
t.Fatal(err)
}
// encrypt
if err := rec.Encrypt(cipherKey); err != nil {
t.Fatal(err)
}
if rec.GetUuid() == originalUUID {
t.Fatal("record UUID field was not encrypted")
}
// decrypt
if err := rec.Decrypt(cipherKey); err != nil {
t.Fatal(err)
}
if rec.GetUuid() != originalUUID {
t.Fatal("record UUID field was not decrypted")
}
}