-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
49 lines (39 loc) · 1.11 KB
/
message_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
49
package entities
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestSignedMessage(t *testing.T) {
ent, err := GetEncrypterSignerEntityForTest("TEST")
assert.NoError(t, err)
assert.NotNil(t, ent)
m := &SignedMessage{Payload: []byte("message"), ID: []byte(ent.ID())}
err = m.Sign(ent)
assert.NoError(t, err)
v, err := m.Verify(ent)
assert.NoError(t, err)
assert.True(t, v)
}
func TestSignedMessageErr(t *testing.T) {
ent, err := GetEncrypterSignerEntityForTest("TEST")
assert.NoError(t, err)
assert.NotNil(t, ent)
m := &SignedMessage{Payload: []byte("message"), ID: []byte(ent.ID())}
err = m.Sign(nil)
assert.Error(t, err)
_, err = m.Verify(nil)
assert.Error(t, err)
m = &SignedMessage{Payload: []byte("message"), Sig: []byte("barf")}
_, err = m.Verify(nil)
assert.Error(t, err)
}
func TestSignedMessageMarshaller(t *testing.T) {
m1 := &SignedMessage{Payload: []byte("message"), Sig: []byte("sig"), ID: []byte("ID")}
m2 := &SignedMessage{}
b, err := m1.ToBytes()
assert.NoError(t, err)
err = m2.FromBytes(b)
assert.NoError(t, err)
assert.True(t, reflect.DeepEqual(m1, m2))
}