File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ package rest
2
+
3
+ import (
4
+ "net/http"
5
+ "testing"
6
+
7
+ "github.com/ant0ine/go-json-rest/rest/test"
8
+ )
9
+
10
+ func TestCorsMiddlewareEmptyAccessControlRequestHeaders (t * testing.T ) {
11
+ api := NewApi ()
12
+
13
+ // the middleware to test
14
+ api .Use (& CorsMiddleware {
15
+ OriginValidator : func (_ string , _ * Request ) bool {
16
+ return true
17
+ },
18
+ AllowedMethods : []string {
19
+ "GET" ,
20
+ "POST" ,
21
+ "PUT" ,
22
+ },
23
+ AllowedHeaders : []string {
24
+ "Origin" ,
25
+ "Referer" ,
26
+ },
27
+ })
28
+
29
+ // wrap all
30
+ handler := api .MakeHandler ()
31
+
32
+ req , _ := http .NewRequest ("OPTIONS" , "http://localhost" , nil )
33
+ req .Header .Set ("Origin" , "http://another.host" )
34
+ req .Header .Set ("Access-Control-Request-Method" , "PUT" )
35
+ req .Header .Set ("Access-Control-Request-Headers" , "" )
36
+
37
+ recorded := test .RunRequest (t , handler , req )
38
+ t .Logf ("recorded: %+v\n " , recorded .Recorder )
39
+ recorded .CodeIs (200 )
40
+ recorded .HeaderIs ("Access-Control-Allow-Methods" , "GET,POST,PUT" )
41
+ recorded .HeaderIs ("Access-Control-Allow-Headers" , "Origin,Referer" )
42
+ recorded .HeaderIs ("Access-Control-Allow-Origin" , "http://another.host" )
43
+ }
You can’t perform that action at this time.
0 commit comments