@@ -5,8 +5,10 @@ import (
55 "encoding/base64"
66 "io/ioutil"
77 "math/rand"
8+ "net/url"
89 "os"
910 "strings"
11+ "time"
1012
1113 "github.com/aws/aws-lambda-go/events"
1214 "github.com/aws/aws-lambda-go/lambdacontext"
@@ -64,14 +66,19 @@ var _ = Describe("RequestAccessor tests", func() {
6466 Expect (binaryBody ).To (Equal (bodyBytes ))
6567 })
6668
69+ now := time .Now ().UTC ()
70+ urlEncodedTimestamp := url .QueryEscape (now .Format (time .RFC3339 ))
71+
6772 mqsRequest := getProxyRequest ("/hello" , "GET" )
6873 mqsRequest .MultiValueQueryStringParameters = map [string ][]string {
69- "hello" : {"1" },
70- "world" : {"2" , "3" },
74+ "hello" : {"1" },
75+ "world" : {"2" , "3" },
76+ url .QueryEscape ("urlEncoded:Timestamp" ): {urlEncodedTimestamp },
7177 }
7278 mqsRequest .QueryStringParameters = map [string ]string {
73- "hello" : "1" ,
74- "world" : "2" ,
79+ "hello" : "1" ,
80+ "world" : "2" ,
81+ url .QueryEscape ("urlEncoded:Timestamp" ): urlEncodedTimestamp ,
7582 }
7683 It ("Populates multiple value query string correctly" , func () {
7784 httpReq , err := accessor .EventToRequestWithContext (context .Background (), mqsRequest )
@@ -83,22 +90,28 @@ var _ = Describe("RequestAccessor tests", func() {
8390 Expect ("GET" ).To (Equal (httpReq .Method ))
8491
8592 query := httpReq .URL .Query ()
86- Expect (2 ).To (Equal (len (query )))
93+ Expect (3 ).To (Equal (len (query )))
8794 Expect (query ["hello" ]).ToNot (BeNil ())
8895 Expect (query ["world" ]).ToNot (BeNil ())
96+ Expect (query ["urlEncoded:Timestamp" ]).ToNot (BeNil ())
8997 Expect (1 ).To (Equal (len (query ["hello" ])))
9098 Expect (2 ).To (Equal (len (query ["world" ])))
99+ Expect (1 ).To (Equal (len (query ["urlEncoded:Timestamp" ])))
91100 Expect ("1" ).To (Equal (query ["hello" ][0 ]))
92101 Expect ("2" ).To (Equal (query ["world" ][0 ]))
93102 Expect ("3" ).To (Equal (query ["world" ][1 ]))
103+ parsedTime , err := time .Parse (time .RFC3339 , query ["urlEncoded:Timestamp" ][0 ])
104+ Expect (err ).To (BeNil ())
105+ Expect (parsedTime ).To (BeTemporally ("~" , now , time .Second ))
94106 })
95107
96108 // Support `QueryStringParameters` for backward compatibility.
97109 // https://github.com/awslabs/aws-lambda-go-api-proxy/issues/37
98110 qsRequest := getProxyRequest ("/hello" , "GET" )
99111 qsRequest .QueryStringParameters = map [string ]string {
100- "hello" : "1" ,
101- "world" : "2" ,
112+ "hello" : "1" ,
113+ "world" : "2" ,
114+ url .QueryEscape ("urlEncoded:Timestamp" ): urlEncodedTimestamp ,
102115 }
103116 It ("Populates query string correctly" , func () {
104117 httpReq , err := accessor .EventToRequestWithContext (context .Background (), qsRequest )
@@ -109,13 +122,16 @@ var _ = Describe("RequestAccessor tests", func() {
109122 Expect ("GET" ).To (Equal (httpReq .Method ))
110123
111124 query := httpReq .URL .Query ()
112- Expect (2 ).To (Equal (len (query )))
125+ Expect (3 ).To (Equal (len (query )))
113126 Expect (query ["hello" ]).ToNot (BeNil ())
114127 Expect (query ["world" ]).ToNot (BeNil ())
115128 Expect (1 ).To (Equal (len (query ["hello" ])))
116129 Expect (1 ).To (Equal (len (query ["world" ])))
117130 Expect ("1" ).To (Equal (query ["hello" ][0 ]))
118131 Expect ("2" ).To (Equal (query ["world" ][0 ]))
132+ parsedTime , err := time .Parse (time .RFC3339 , query ["urlEncoded:Timestamp" ][0 ])
133+ Expect (err ).To (BeNil ())
134+ Expect (parsedTime ).To (BeTemporally ("~" , now , time .Second ))
119135 })
120136
121137 mvhRequest := getProxyRequest ("/hello" , "GET" )
0 commit comments