-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyhandling_test.go
More file actions
55 lines (44 loc) · 1.16 KB
/
keyhandling_test.go
File metadata and controls
55 lines (44 loc) · 1.16 KB
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
49
50
51
52
53
54
55
package pgp
import (
"fmt"
"log"
"testing"
"github.com/stretchr/testify/assert"
)
func mockPublicProvider(k string, scope string) (string, error) {
switch scope {
case "public":
return qwertPub, nil
case "private":
return qwertPrivate, nil
}
return "", fmt.Errorf("wrong scope")
}
func Test_getEntitiesByKeyProvider(t *testing.T) {
recipients := []string{"a@insitu.de", "b@insitu.de"}
entities, err := getEntitiesByKeyProvider(recipients, mockPublicProvider, "public")
if err != nil {
t.Errorf("mocked keyprovider failed")
}
for _, e := range entities {
if e.PrivateKey != nil {
assert.Equal(t, nil, e.PrivateKey, "private key should not be set")
}
assert.NotEqual(t, nil, e.PrimaryKey, "public key must be set")
}
}
// Just a small test to see if the right entity was returned (the Identity is checked)
func Test_getEntity(t *testing.T) {
entity, err := newEntity(qwertPub)
if err != nil {
log.Fatal(err)
}
_, ok := entity.Identities["qwert <qwert@mail.xy>"]
assert.Equal(t, ok, true)
entity, err = newEntity(qwertPrivate)
if err != nil {
log.Fatal(err)
}
_, ok = entity.Identities["qwert <qwert@mail.xy>"]
assert.Equal(t, ok, true)
}