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

Function TestHeadersFromConfiguration

router/router_test.go:82–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

80}
81
82func TestHeadersFromConfiguration(t *testing.T) {
83 mode.Set(mode.Prod)
84 db := testdb.NewDBWithDefaultUser(t)
85 defer db.Close()
86
87 config := config.Configuration{PassStrength: 5}
88 config.Server.ResponseHeaders = map[string]string{
89 "New-Cool-Header": "Nice",
90 "Access-Control-Allow-Origin": "http://test1.com",
91 }
92
93 g, closable := Create(db.GormDatabase,
94 &model.VersionInfo{Version: "1.0.0", BuildDate: "2018-02-20-17:30:47", Commit: "asdasds"},
95 &config,
96 )
97 server := httptest.NewServer(g)
98
99 defer func() {
100 closable()
101 server.Close()
102 }()
103
104 req, err := http.NewRequest("GET", fmt.Sprintf("%s/%s", server.URL, "version"), nil)
105 req.Header.Add("Content-Type", "application/json")
106 assert.Nil(t, err)
107
108 res, err := client.Do(req)
109 assert.Nil(t, err)
110 assert.Equal(t, "http://test1.com", res.Header.Get("Access-Control-Allow-Origin"))
111 assert.Equal(t, "Nice", res.Header.Get("New-Cool-Header"))
112}
113
114func TestHeadersFromCORSConfig(t *testing.T) {
115 mode.Set(mode.Prod)

Callers

nothing calls this directly

Calls 5

SetFunction · 0.92
NewDBWithDefaultUserFunction · 0.92
CreateFunction · 0.85
DoMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…