Skip to content

Commit 65b99e0

Browse files
authored
fix: Support older Go version (#176)
* release fix to support older go versions
1 parent 93db014 commit 65b99e0

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

.github/workflows/test-and-deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
steps:
3636
- name: Setup Go environment
3737
uses: actions/setup-go@v2
38+
with:
39+
go-version: ${{ matrix.go }}
3840

3941
- name: Checkout twilio-go
4042
uses: actions/checkout@v2

client/request_validator.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,10 @@ func (rv *RequestValidator) ValidateBody(url string, body []byte, expectedSignat
5757
return false
5858
}
5959

60-
if parsed.Query().Has("bodySHA256") {
61-
bodySHA256 := parsed.Query().Get("bodySHA256")
62-
if len(bodySHA256) == 0 {
63-
return false
64-
}
65-
return rv.Validate(url, map[string]string{}, expectedSignature) &&
66-
rv.validateBody(body, bodySHA256)
67-
} else {
68-
// For x-www-form-urlencoded Request body
60+
bodySHA256 := parsed.Query().Get("bodySHA256")
61+
62+
// For x-www-form-urlencoded Request body
63+
if len(bodySHA256) == 0 {
6964
parsedBody, err := urllib.ParseQuery(string(body))
7065
if err != nil {
7166
return false
@@ -77,17 +72,16 @@ func (rv *RequestValidator) ValidateBody(url string, body []byte, expectedSignat
7772
}
7873
return rv.Validate(url, params, expectedSignature)
7974
}
75+
76+
return rv.Validate(url, map[string]string{}, expectedSignature) &&
77+
rv.validateBody(body, bodySHA256)
8078
}
8179

8280
func compare(x, y string) bool {
8381
return subtle.ConstantTimeCompare([]byte(x), []byte(y)) == 1
8482
}
8583

8684
func (rv *RequestValidator) validateBody(body []byte, expectedSHA string) bool {
87-
if len(expectedSHA) == 0 {
88-
return true
89-
}
90-
9185
hasher := sha256.New()
9286
_, err := hasher.Write(body)
9387
if err != nil {

0 commit comments

Comments
 (0)