forked from rclone/go-proton-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyring_test.go
More file actions
48 lines (37 loc) · 973 Bytes
/
Copy pathkeyring_test.go
File metadata and controls
48 lines (37 loc) · 973 Bytes
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
import (
"testing"
"github.com/ProtonMail/gopenpgp/v3/crypto"
"github.com/stretchr/testify/require"
)
func TestKeyring_Unlock(t *testing.T) {
r := require.New(t)
pgp := crypto.PGP()
newKey := func(id, passphrase string) Key {
key, err := pgp.KeyGeneration().AddUserId(id, id+"@email.com").New().GenerateKey()
r.NoError(err)
defer key.ClearPrivateParams()
locked, err := pgp.LockKey(key, []byte(passphrase))
r.NoError(err)
serial, err := locked.Serialize()
r.NoError(err)
return Key{
ID: id,
PrivateKey: serial,
Active: true,
}
}
keys := 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())
}