-
Notifications
You must be signed in to change notification settings - Fork 5
/
signer_test.go
71 lines (59 loc) · 2.18 KB
/
signer_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
package iopipe
import (
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/aws/aws-lambda-go/lambdacontext"
. "github.com/smartystreets/goconvey/convey"
)
func TestSigner_GetSignerURL(t *testing.T) {
regions := []Region{
Region{Region: "", URL: "https://signer.us-west-2.iopipe.com/"},
Region{Region: "ap-northeast-1", URL: "https://signer.ap-northeast-1.iopipe.com/"},
Region{Region: "ap-southeast-2", URL: "https://signer.ap-southeast-2.iopipe.com/"},
Region{Region: "eu-west-1", URL: "https://signer.eu-west-1.iopipe.com/"},
Region{Region: "us-east-1", URL: "https://signer.us-east-1.iopipe.com/"},
Region{Region: "us-east-2", URL: "https://signer.us-east-2.iopipe.com/"},
Region{Region: "us-west-1", URL: "https://signer.us-west-1.iopipe.com/"},
Region{Region: "us-west-2", URL: "https://signer.us-west-2.iopipe.com/"},
}
Convey("GetSignerURL should return the correct URL for the region", t, func() {
for _, region := range regions {
So(GetSignerURL(region.Region), ShouldEqual, region.URL)
}
})
}
func TestSigner_GetSignedRequest(t *testing.T) {
Convey("GetSignedRequest should return a signed request", t, func() {
ts := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "application/json")
signerResponse := &SignerResponse{
JWTAccess: "foobar",
SignedRequest: "https://some-url",
URL: "https://some-url",
}
signerResponseJSONBytes, _ := json.Marshal(signerResponse)
fmt.Fprintln(res, string(signerResponseJSONBytes))
}))
defer ts.Close()
oldRegion := os.Getenv("AWS_REGION")
defer os.Setenv("AWS_REGION", oldRegion)
os.Setenv("AWS_REGION", "mock")
os.Setenv("MOCK_SERVER", ts.URL)
a := NewAgent(Config{Debug: True()})
lc := &lambdacontext.LambdaContext{
AwsRequestID: "123",
InvokedFunctionArn: "Foo::Bar::Baz",
}
hw := &HandlerWrapper{agent: a, lambdaContext: lc}
r := NewReport(hw)
res, err := GetSignedRequest(r, ".txt")
So(err, ShouldBeNil)
So(res.JWTAccess, ShouldEqual, "foobar")
So(res.SignedRequest, ShouldEqual, "https://some-url")
So(res.URL, ShouldEqual, "https://some-url")
})
}