-
Notifications
You must be signed in to change notification settings - Fork 5
/
masterkey_test.go
45 lines (35 loc) · 1.01 KB
/
masterkey_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 main
import (
"os"
"testing"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/assert"
)
const (
testMKeyPath = "./testkey"
testPass = "passwd"
)
func TestCreateKey(t *testing.T) {
mkey := newMasterKey()
mkey.changePassword([]byte(testPass))
mkey.generateMasterKey(nil)
mkey.labels[0] = "HELLO"
assert.Nil(t, mkey.store(testMKeyPath))
loaded := newMasterKey()
assert.Nil(t, loaded.load([]byte(testPass), testMKeyPath))
assert.Equal(t, mkey.labels[0], loaded.labels[0])
os.Remove(testMKeyPath)
t.Log(hexutil.Encode(mkey.masterKey[:100]))
}
func TestCreateKeySalted(t *testing.T) {
mkey := newMasterKey()
mkey.generateMasterKey([]byte("added some salt"))
mkey.changePassword([]byte(testPass))
mkey.labels[0] = "HELLO"
assert.Nil(t, mkey.store(testMKeyPath))
loaded := newMasterKey()
assert.Nil(t, loaded.load([]byte(testPass), testMKeyPath))
assert.Equal(t, mkey.labels[0], loaded.labels[0])
os.Remove(testMKeyPath)
t.Log(hexutil.Encode(mkey.masterKey[:100]))
}