MCPcopy
hub / github.com/gofiber/fiber / Test_HSTSHeaders

Function Test_HSTSHeaders

middleware/helmet/helmet_test.go:207–241  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

205}
206
207func Test_HSTSHeaders(t *testing.T) {
208 t.Parallel()
209
210 tests := []struct {
211 name string
212 scheme string
213 expected string
214 config Config
215 }{
216 {
217 name: "TLS request with max age sets header",
218 config: Config{HSTSMaxAge: 60},
219 scheme: "https",
220 expected: "max-age=60; includeSubDomains",
221 },
222 {
223 name: "TLS request with zero max age omits header",
224 config: Config{HSTSMaxAge: 0},
225 scheme: "https",
226 },
227 {
228 name: "HTTP request with max age omits header",
229 config: Config{HSTSMaxAge: 60},
230 scheme: "http",
231 },
232 }
233
234 for _, tt := range tests {
235 t.Run(tt.name, func(t *testing.T) {
236 t.Parallel()
237
238 require.Equal(t, tt.expected, hstsHeaderForRequest(t, &tt.config, tt.scheme))
239 })
240 }
241}
242
243func Test_HSTSHeadersPanicsOnNegativeMaxAge(t *testing.T) {
244 t.Parallel()

Callers

nothing calls this directly

Calls 1

hstsHeaderForRequestFunction · 0.85

Tested by

no test coverage detected