| 105 | } |
| 106 | |
| 107 | func (s *ServerTestSuite) TestWithCORS() { |
| 108 | tests := []struct { |
| 109 | name string |
| 110 | corsAllowOrigin string |
| 111 | expectedOrigin string |
| 112 | expectedMethods string |
| 113 | }{ |
| 114 | { |
| 115 | name: "WithCORSOrigin", |
| 116 | corsAllowOrigin: "https://example.com", |
| 117 | expectedOrigin: "https://example.com", |
| 118 | expectedMethods: "GET, OPTIONS", |
| 119 | }, |
| 120 | { |
| 121 | name: "NoCORSOrigin", |
| 122 | corsAllowOrigin: "", |
| 123 | expectedOrigin: "", |
| 124 | expectedMethods: "", |
| 125 | }, |
| 126 | } |
| 127 | |
| 128 | for _, tt := range tests { |
| 129 | s.Run(tt.name, func() { |
| 130 | s.config().CORSAllowOrigin = tt.corsAllowOrigin |
| 131 | |
| 132 | s.router().GET("/test", s.router().WithCORS(s.mockHandler)) |
| 133 | |
| 134 | req := httptest.NewRequest(http.MethodGet, "/test", nil) |
| 135 | rw := httptest.NewRecorder() |
| 136 | |
| 137 | s.router().ServeHTTP(rw, req) |
| 138 | |
| 139 | s.Equal(tt.expectedOrigin, rw.Header().Get(httpheaders.AccessControlAllowOrigin)) |
| 140 | s.Equal(tt.expectedMethods, rw.Header().Get(httpheaders.AccessControlAllowMethods)) |
| 141 | }) |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | func (s *ServerTestSuite) TestWithSecret() { |
| 146 | tests := []struct { |