-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_sign_test.go
35 lines (29 loc) · 1.19 KB
/
api_sign_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
package hook_test
import (
"testing"
hook "github.com/innopals/sls-logrus-hook"
"github.com/stretchr/testify/assert"
)
func TestApiSign(t *testing.T) {
// GET
headers := make(map[string]string)
headers[hook.HeaderLogVersion] = "0.6.0"
headers[hook.HeaderLogSignatureMethod] = "hmac-sha1"
headers[hook.HeaderHost] = "test.cn-hangzhou.log.aliyuncs.com"
headers[hook.HeaderDate] = "Wed, 29 May 2019 16:00:00 GMT"
sign := hook.APISign("63D0CEA9D550E495FDE1B81310951BD7", "POST", headers, "logstores/test")
assert.Equal(t, "KYke+ObziWJpOk305xnagI/omps=", sign)
// POST
headers = make(map[string]string)
headers[hook.HeaderLogVersion] = "0.6.0"
headers[hook.HeaderLogSignatureMethod] = "hmac-sha1"
headers[hook.HeaderHost] = "test.cn-hangzhou.log.aliyuncs.com"
headers[hook.HeaderDate] = "Wed, 29 May 2019 16:00:00 GMT"
// Content: "Hello world!"
headers[hook.HeaderContentMd5] = "86FB269D190D2C85F6E0468CECA42A20"
headers[hook.HeaderContentLength] = "12"
headers[hook.HeaderContentType] = "text/plain"
headers[hook.HeaderLogBodyRawSize] = "0"
sign = hook.APISign("2974A71FE7FCCEF63C436826DD53BA6D", "POST", headers, "logstores/test")
assert.Equal(t, "L+jYhsQtv23obfVMhZFbFhQecD4=", sign)
}