(t *testing.T)
| 11 | ) |
| 12 | |
| 13 | func TestCorsConfig(t *testing.T) { |
| 14 | mode.Set(mode.Prod) |
| 15 | serverConf := config.Configuration{} |
| 16 | serverConf.Server.Cors.AllowOrigins = []string{"http://test.com"} |
| 17 | serverConf.Server.Cors.AllowHeaders = []string{"content-type"} |
| 18 | serverConf.Server.Cors.AllowMethods = []string{"GET"} |
| 19 | |
| 20 | actual := CorsConfig(&serverConf) |
| 21 | allowF := actual.AllowOriginFunc |
| 22 | actual.AllowOriginFunc = nil // func cannot be checked with equal |
| 23 | |
| 24 | assert.Equal(t, cors.Config{ |
| 25 | AllowAllOrigins: false, |
| 26 | AllowHeaders: []string{"content-type"}, |
| 27 | AllowMethods: []string{"GET"}, |
| 28 | MaxAge: 12 * time.Hour, |
| 29 | AllowBrowserExtensions: true, |
| 30 | }, actual) |
| 31 | assert.NotNil(t, allowF) |
| 32 | assert.True(t, allowF("http://test.com")) |
| 33 | assert.False(t, allowF("https://test.com")) |
| 34 | assert.False(t, allowF("https://other.com")) |
| 35 | } |
| 36 | |
| 37 | func TestEmptyCorsConfigWithResponseHeaders(t *testing.T) { |
| 38 | mode.Set(mode.Prod) |
nothing calls this directly
no test coverage detected
searching dependent graphs…