-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_verifier_test.go
73 lines (65 loc) · 1.91 KB
/
request_verifier_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
package alexa
import (
"crypto/x509"
"testing"
"time"
)
func TestURLVerifier(t *testing.T) {
cases := []struct {
url string
err bool
}{
{"https://s3.amazonaws.com/echo.api/echo-api-cert.pem", false},
{"https://s3.amazonaws.com:443/echo.api/echo-api-cert.pem", false},
{"https://s3.amazonaws.com/echo.api/../echo.api/echo-api-cert.pem", false},
{"://force-url-parse-to-fail", true},
{"http://s3.amazonaws.com/echo.api/echo-api-cert.pem", true},
{"https://notamazon.com/echo.api/echo-api-cert.pem", true},
{"https://s3.amazonaws.com/EcHo.aPi/echo-api-cert.pem", true},
{"https://s3.amazonaws.com/invalid.path/echo-api-cert.pem", true},
{"https://s3.amazonaws.com:563/echo.api/echo-api-cert.pem", true},
}
for _, c := range cases {
if err := verifyURL(c.url); (err == nil) == c.err {
t.Errorf("Did want err %t; got %s for %s", c.err, err, c.url)
}
}
}
func TestVerifyTimestamp(t *testing.T) {
cases := []struct {
timestamp string
err bool
}{
// Future
{time.Now().Add(100 * time.Second).Format(time.RFC3339), false},
{time.Now().Add(500 * time.Second).Format(time.RFC3339), true},
// Past
{time.Now().Add(-100 * time.Second).Format(time.RFC3339), false},
{time.Now().Add(-500 * time.Second).Format(time.RFC3339), true},
// Wacky dates
{"whoa", true},
}
for _, c := range cases {
if err := verifyTimestamp(c.timestamp); (err == nil) == c.err {
t.Errorf("Did want err %t; got %s for %s", c.err, err, c.timestamp)
}
}
}
func TestVerifySignature(t *testing.T) {
type args struct {
b64sig string
cert *x509.Certificate
bs []byte
}
cases := []struct {
args args
err bool
}{
{args{b64sig: "this is not base64"}, true},
}
for _, c := range cases {
if err := verifySignature(c.args.b64sig, c.args.cert, c.args.bs); (err == nil) == c.err {
t.Errorf("Did want err %t; got %s\n\t%x\n\t%+v\t\n%x", c.err, err, c.args.b64sig, c.args.cert, c.args.bs)
}
}
}