-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into msg-logs-paginate
- Loading branch information
Showing
41 changed files
with
1,567 additions
and
1,020 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package authtoken | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func FuzzParse(f *testing.F) { | ||
f.Add("01020304-0506-0708-090a-0b0c0d0e0f10") // v0 | ||
f.Add("01020304-0506-0708-090a-0b0c0d0e0f1z") // v0 invalid | ||
|
||
f.Add("U9obklyVC0wduWIy75nbivABDxwc-rANyqNA4CZQzhkJHuNlUCfJDPpcG6W9bEIPddqPbh-sxMS1Km87jC9yLASp3i1UWtdDu2udCzM=") // v1 | ||
f.Add("U9obklyVC0wduWIy75nbivABDxwc-rANyqNA4CZQzhkJHuNlUCfJDPpcG6W9bEIPddqPbh-sxMS1Km87jC9yLASp3i1UWtdDu2udCzM==") // v1, invalid base64 | ||
|
||
f.Add("VgICAQIDBAUGBwgJCgsMDQ4PEAAAAAAAAAU5c2ln") // v2 | ||
|
||
f.Fuzz(func(t *testing.T, a string) { | ||
verifyFn := func(t Type, payload, signature []byte) (isValid bool, isOldKey bool) { | ||
return true, true | ||
} | ||
tok, _, err := Parse(a, verifyFn) | ||
if err != nil { | ||
return | ||
} | ||
|
||
s, err := tok.Encode(func(payload []byte) (signature []byte, err error) { | ||
return []byte("sig"), nil | ||
}) | ||
require.NoError(t, err) | ||
|
||
tok2, _, err := Parse(s, verifyFn) | ||
require.NoError(t, err) | ||
assert.Equal(t, tok, tok2) | ||
}) | ||
} |
2 changes: 2 additions & 0 deletions
2
.../testdata/fuzz/FuzzParse/55252af6e78583606e5e18afbd3c823376f613401644d6fbc0ac13fe08a6a784
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
string("VgI00000000000000000000000000000000") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package slack | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/target/goalert/config" | ||
"github.com/target/goalert/permission" | ||
) | ||
|
||
func TestValidateRequestSignature(t *testing.T) { | ||
// Values pulled directly from: https://api.slack.com/authentication/verifying-requests-from-slack | ||
var cfg config.Config | ||
cfg.Slack.SigningSecret = "8f742231b10e8888abcd99yyyzzz85a5" | ||
|
||
req, err := http.NewRequestWithContext(cfg.Context(context.Background()), "POST", "http://example.com", strings.NewReader("token=xyzz0WbapA4vBCDEFasx0q6G&team_id=T1DC2JH3J&team_domain=testteamnow&channel_id=G8PSS9T3V&channel_name=foobar&user_id=U2CERLKJA&user_name=roadrunner&command=%2Fwebhook-collect&text=&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT1DC2JH3J%2F397700885554%2F96rGlfmibIGlgcZRskXaIFfN&trigger_id=398738663015.47445629121.803a0bc887a14d10d2c447fce8b6703c")) | ||
require.NoError(t, err) | ||
|
||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
req.Header.Set("X-Slack-Request-Timestamp", "1531420618") | ||
req.Header.Set("X-Slack-Signature", "v0=a2114d57b48eac39b9ad189dd8316235a7b4a8d21a10bd27519666489c69b503") | ||
|
||
err = validateRequestSignature(time.Unix(1531420618, 0), req) | ||
assert.NoError(t, err) | ||
|
||
req, err = http.NewRequestWithContext(cfg.Context(context.Background()), "POST", "http://example.com", strings.NewReader("token=xyzz0WbapA4vBCDEFasx0q6G&team_id=T1DC2JH3J&team_domain=testteamnow&channel_id=G8PSS9T3V&channel_name=foobar&user_id=U2CERLKJA&user_name=roadrunner&command=%2Fwebhook-collect&text=&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT1DC2JH3J%2F397700885554%2F96rGlfmibIGlgcZRskXaIFfN&trigger_id=398738663015.47445629121.803a0bc887a14d10d2c447fce8b6703c")) | ||
require.NoError(t, err) | ||
|
||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
req.Header.Set("X-Slack-Request-Timestamp", "15314206189") // changed timestamp | ||
req.Header.Set("X-Slack-Signature", "v0=a2114d57b48eac39b9ad189dd8316235a7b4a8d21a10bd27519666489c69b503") | ||
|
||
// different timestamp should invalidate the signature | ||
err = validateRequestSignature(time.Unix(1531420618, 0), req) | ||
assert.True(t, permission.IsUnauthorized(err), "expected unauthorized error, got: %v", err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package slack | ||
|
||
import ( | ||
"crypto/hmac" | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// Signature generates a signature for a Slack request. | ||
func Signature(signingSecret string, ts time.Time, data []byte) string { | ||
h := hmac.New(sha256.New, []byte(signingSecret)) | ||
_, err := fmt.Fprintf(h, "v0:%d:%s", ts.Unix(), data) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return "v0=" + hex.EncodeToString(h.Sum(nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package slack | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSignature(t *testing.T) { | ||
// example pulled directly from: https://api.slack.com/authentication/verifying-requests-from-slack | ||
sig := Signature("8f742231b10e8888abcd99yyyzzz85a5", time.Unix(1531420618, 0), []byte("token=xyzz0WbapA4vBCDEFasx0q6G&team_id=T1DC2JH3J&team_domain=testteamnow&channel_id=G8PSS9T3V&channel_name=foobar&user_id=U2CERLKJA&user_name=roadrunner&command=%2Fwebhook-collect&text=&response_url=https%3A%2F%2Fhooks.slack.com%2Fcommands%2FT1DC2JH3J%2F397700885554%2F96rGlfmibIGlgcZRskXaIFfN&trigger_id=398738663015.47445629121.803a0bc887a14d10d2c447fce8b6703c")) | ||
|
||
assert.Equal(t, "v0=a2114d57b48eac39b9ad189dd8316235a7b4a8d21a10bd27519666489c69b503", sig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...stdata/fuzz/FuzzJMESPath/56b1dff6e89281145efa3f46de8e3710d757f144714d54b9b5826e7701ded458
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
go test fuzz v1 | ||
string("A\u0080") |
Oops, something went wrong.