-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwire_test.go
61 lines (53 loc) · 1.29 KB
/
wire_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
50
51
52
53
54
55
56
57
58
59
60
61
package sshsig
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_signedData_Marshal(t *testing.T) {
t.Run("has magic preamble", func(t *testing.T) {
s := signedData{}
m := s.Marshal()
assert.Equal(t, magicPreamble[:], m[:6])
})
}
func Test_blob_Valid(t *testing.T) {
t.Run("unsupported version", func(t *testing.T) {
b := blob{
Version: 0,
}
assert.ErrorIs(t, b.Validate(), ErrUnsupportedSignatureVersion)
})
t.Run("invalid magic preamble", func(t *testing.T) {
b := blob{
Version: sigVersion,
MagicPreamble: [6]byte{'a', 'b', 'c', 'd', 'e', 'f'},
}
assert.ErrorIs(t, b.Validate(), ErrInvalidMagicPreamble)
})
t.Run("unsupported hash algorithm", func(t *testing.T) {
b := blob{
Version: sigVersion,
MagicPreamble: magicPreamble,
HashAlgorithm: "foo",
}
assert.ErrorIs(t, b.Validate(), ErrUnsupportedHashAlgorithm)
})
t.Run("valid", func(t *testing.T) {
b := blob{
Version: sigVersion,
MagicPreamble: magicPreamble,
HashAlgorithm: "sha256",
}
assert.NoError(t, b.Validate())
})
}
func Test_blob_Marshal(t *testing.T) {
t.Run("has magic preamble", func(t *testing.T) {
b := blob{
Version: 1,
MagicPreamble: magicPreamble,
}
m := b.Marshal()
assert.Equal(t, magicPreamble[:], m[:6])
})
}