-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature_value_parser_test.go
80 lines (77 loc) · 2.44 KB
/
signature_value_parser_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
package httpsign
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParserSignatureValue(t *testing.T) {
tests := []struct {
name string
input string
params map[string]string
err error
}{
{
name: `Missing = character`,
input: `keyId="rsa-key-1",algorithm"rsa-sha256",headers="(request-target) host date digest",signature="Hello world"`,
err: ErrMissingEqualCharacter,
},
{
name: `Missing = character`,
input: `keyId="rsa-key-1",algorithm"rsa-sha256",headers="(request-target) host date digest",signature="Hello world"`,
err: ErrMissingEqualCharacter,
},
{
name: `Missing " at end value`,
input: `keyId="rsa-key-1",algorithm="rsa-sha256,headers="(request-target) host date digest",signature="Hello world"`,
err: ErrMissingDoubleQuote,
},
{
name: `Missing " at begin value`,
input: `keyId="rsa-key-1",algorithm=rsa-sha256",headers="(request-target) host date digest",signature="Hello world"`,
err: ErrMissingDoubleQuote,
},
{
name: `number value`,
input: `keyId="",algorithm="rsa-sha256",created=1686625874,headers="(request-target) host date digest",signature="Hello world"`,
params: map[string]string{
"keyId": "",
"algorithm": "rsa-sha256",
"created": "1686625874",
"headers": "(request-target) host date digest",
"signature": "Hello world",
},
err: nil,
},
{
name: `empty value`,
input: `keyId="",algorithm="rsa-sha256",headers="(request-target) host date digest",signature="Hello world"`,
params: map[string]string{
"keyId": "",
"algorithm": "rsa-sha256",
"headers": "(request-target) host date digest",
"signature": "Hello world",
},
err: nil,
},
{
name: `correct test`,
input: `keyId="rsa-key-1",algorithm="rsa-sha256",headers="(request-target) host date digest",signature="70AaN3BDO0XC9QbtgksgCy2jJvmOvshq8VmjSthdXC+sgcgrKrl9WME4DbZv4W7UZKElvCemhDLHQ1Nln9GMkQ=="`,
params: map[string]string{
"keyId": "rsa-key-1",
"algorithm": "rsa-sha256",
"headers": "(request-target) host date digest",
"signature": "70AaN3BDO0XC9QbtgksgCy2jJvmOvshq8VmjSthdXC+sgcgrKrl9WME4DbZv4W7UZKElvCemhDLHQ1Nln9GMkQ==",
},
err: nil,
},
}
for _, tc := range tests {
results, err := parseSignatureValue(tc.input)
require.Equal(t, tc.err, err, tc.name)
if err != nil {
continue
}
assert.Equal(t, tc.params, results, tc.name)
}
}