-
Notifications
You must be signed in to change notification settings - Fork 18
/
keyring_test.go
48 lines (37 loc) · 1 KB
/
keyring_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
46
47
48
package proton_test
import (
"testing"
"github.com/ProtonMail/go-proton-api"
"github.com/ProtonMail/gopenpgp/v2/crypto"
"github.com/ProtonMail/gopenpgp/v2/helper"
"github.com/stretchr/testify/require"
)
func TestKeyring_Unlock(t *testing.T) {
r := require.New(t)
newKey := func(id, passphrase string) proton.Key {
arm, err := helper.GenerateKey(id, id+"@email.com", []byte(passphrase), "rsa", 2048)
r.NoError(err)
privKey, err := crypto.NewKeyFromArmored(arm)
r.NoError(err)
serial, err := privKey.Serialize()
r.NoError(err)
return proton.Key{
ID: id,
PrivateKey: serial,
Active: true,
}
}
keys := proton.Keys{
newKey("1", "good_phrase"),
newKey("2", "good_phrase"),
newKey("3", "bad_phrase"),
}
_, err := keys.Unlock([]byte("ugly_phrase"), nil)
r.Error(err)
kr, err := keys.Unlock([]byte("bad_phrase"), nil)
r.NoError(err)
r.Equal(1, kr.CountEntities())
kr, err = keys.Unlock([]byte("good_phrase"), nil)
r.NoError(err)
r.Equal(2, kr.CountEntities())
}