MCPcopy
hub / github.com/gotify/server / TestCorsConfig

Function TestCorsConfig

auth/cors_test.go:13–35  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func 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
37func TestEmptyCorsConfigWithResponseHeaders(t *testing.T) {
38 mode.Set(mode.Prod)

Callers

nothing calls this directly

Calls 2

SetFunction · 0.92
CorsConfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…