-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder_opts_test.go
118 lines (108 loc) · 2.6 KB
/
builder_opts_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package ocmf_go
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"testing"
"github.com/stretchr/testify/suite"
)
type builderOptsTestSuite struct {
suite.Suite
}
func (s *builderOptsTestSuite) TestWithSignatureAlgorithm() {
tests := []struct {
name string
algorithm SignatureAlgorithm
want bool
}{
{
name: "ECDSA-secp192k1-SHA256",
algorithm: SignatureAlgorithmECDSAsecp192k1SHA256,
want: true,
},
{
name: "ECDSA-secp256k1-SHA256",
algorithm: SignatureAlgorithmECDSAsecp256k1SHA256,
want: true,
},
{
name: "ECDSA-secp384r1-SHA256",
algorithm: SignatureAlgorithmECDSAsecp384r1SHA256,
want: true,
},
{
name: "ECDSA-brainpool256r1-SHA256",
algorithm: SignatureAlgorithmECDSAbrainpool256r11SHA256,
want: true,
},
{
name: "ECDSA-secp256r1-SHA256",
algorithm: SignatureAlgorithmECDSAsecp256r1SHA256,
want: true,
},
{
name: "ECDSA-secp192r1-SHA256",
algorithm: SignatureAlgorithmECDSAsecp192r1SHA256,
want: true,
},
{
name: "Unknown algorithm",
algorithm: SignatureAlgorithm("ABCD"),
want: false,
},
{
name: "Empty algorithm",
algorithm: SignatureAlgorithm(""),
want: false,
},
}
for _, tt := range tests {
s.T().Run(tt.name, func(t *testing.T) {
curve := elliptic.P256()
privateKey, err := ecdsa.GenerateKey(curve, rand.Reader)
s.Require().NoError(err)
builder := NewBuilder(privateKey, WithSignatureAlgorithm(tt.algorithm))
if tt.name == "Unknown algorithm" || tt.name == "Empty algorithm" {
s.NotEqual(tt.algorithm, builder.signature.Algorithm)
} else {
s.Equal(tt.algorithm, builder.signature.Algorithm)
}
})
}
}
func (s *builderOptsTestSuite) TestWithWithSignatureEncoding() {
tests := []struct {
name string
encoding SignatureEncoding
}{
{
name: "Base64 encoding",
encoding: SignatureEncodingBase64,
},
{
name: "Hex encoding",
encoding: SignatureEncodingHex,
},
{
name: "Empty encoding",
encoding: SignatureEncoding(""),
},
{
name: "Unknown encoding",
encoding: SignatureEncoding("ABDD"),
},
}
for _, tt := range tests {
s.T().Run(tt.name, func(t *testing.T) {
builder := NewBuilder(nil, WithSignatureEncoding(tt.encoding))
if tt.encoding == SignatureEncodingBase64 || tt.encoding == SignatureEncodingHex {
s.Equal(tt.encoding, builder.signature.Encoding)
} else {
s.NotEqual(tt.encoding, builder.signature.Encoding)
}
})
}
}
func TestBuilderOpts(t *testing.T) {
suite.Run(t, new(builderOptsTestSuite))
}