Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FeiniuBus/signer
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-its-andy committed Dec 11, 2017
2 parents b35066a + 6920493 commit 6163f98
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions hmac_v1_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (ctx *signingCtx) buildCanonicalString() {
uri = ctx.URL.EscapedPath()
}

ctx.URL.RawQuery = strings.Replace(ctx.Query.Encode(), "+", "%20", -1)
ctx.canonicalString = strings.Join([]string{
ctx.Method,
uri,
Expand Down
34 changes: 32 additions & 2 deletions hmac_v1_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package signer

import (
"bytes"
"encoding/json"
"net/http"
"net/url"
Expand Down Expand Up @@ -46,6 +47,35 @@ func TestSignPutRequest(t *testing.T) {
assert.True(t, validator.Verify(req), "Expect is true")
}

func TestCSharpValidator(t *testing.T) {
b := `{"name":"config_appsettings","env":"Development","attrs":{"mysql_profile":"mysql","mysql_db":"feiniubus_app_version","mysql_env":"Development","redis_profile":"redis","redis_db":"2","redis_env":"Development","mongo_profile":"mongo","mongo_env":"Development","mongo_db":"system_config"},"lang":"CSharp"}`
uri, _ := url.Parse("http://172.16.2.117:5100/cc/v1/fetch")

header := make(http.Header)
header.Set("Accept", "application/json")
header.Set("Host", "172.16.2.117:5100")
header.Set("User-Agent", "Polaris-sdk-dotnet-coreclr/.NET_CORE/4.6.00001.0 OS/Darwin_17.2.0_Darwin_Kernel_Version_17.2.0:_Fri_Sep_29_18:27:05_PDT_2017;_root:xnu-4570.20.62~3/RELEASE_X86_64")
header.Set("Connection", "keep-alive")
header.Set("Accept-Encoding", "gzip")
header.Set("X-FeiniuBus-Date", "20171121T104103Z")
header.Set("Content-Type", "application/json")
header.Set("Content-Length", "302")
header.Set("Authorization", "FNBUS1-HMAC-SHA256 Credential=11E7BEAB19F97FF1878AFA163EE05ADE/20171121/feiniubus_request,SignedHeaders=accept;accept-encoding;connection;content-type;host;user-agent,Signature=6b4ec6f5d845aa5b0587ff64d0448fdc41393c8977f471c7a7f14503a8dc12e1")

req := &Request{
Body: bytes.NewReader([]byte(b)),
URL: uri,
Method: "POST",
Header: header,
}

validator := NewHMACValidatorV1(func(id string) (string, error) {
return "3a57527a8b38f4ddf86609cfba26f86bef045186d59b4994487437947ba733d2", nil
})

assert.True(t, validator.Verify(req), "Expect is true")
}

func TestValidator(t *testing.T) {
b := body{
Name: "xqlun",
Expand All @@ -68,8 +98,8 @@ func TestValidator(t *testing.T) {

func TestSignGetRequest(t *testing.T) {
values := url.Values{}
values.Set("id", "uuid")
values.Set("type", "Topic")
values.Set("type", "uuid")
values.Set("id", "Topic")

req := buildGetRequest(values)
signer := buildSigner()
Expand Down
1 change: 1 addition & 0 deletions hmac_v1_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (ctx *verifyCtx) buildCanonicalString() {
uri = ctx.URL.EscapedPath()
}

ctx.URL.RawQuery = ctx.Query.Encode()
ctx.canonicalString = strings.Join([]string{
ctx.Method,
uri,
Expand Down

0 comments on commit 6163f98

Please sign in to comment.