MCPcopy Index your code
hub / github.com/coder/coder / TestHSTS

Function TestHSTS

coderd/httpmw/hsts_test.go:13–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestHSTS(t *testing.T) {
14 t.Parallel()
15
16 tests := []struct {
17 Name string
18 MaxAge int
19 Options []string
20
21 wantErr bool
22 expectHeader string
23 }{
24 {
25 Name: "Empty",
26 MaxAge: 0,
27 Options: nil,
28 },
29 {
30 Name: "NoAge",
31 MaxAge: 0,
32 Options: []string{"includeSubDomains"},
33 },
34 {
35 Name: "NegativeAge",
36 MaxAge: -100,
37 Options: []string{"includeSubDomains"},
38 },
39 {
40 Name: "Age",
41 MaxAge: 1000,
42 Options: []string{},
43 expectHeader: "max-age=1000",
44 },
45 {
46 Name: "AgeSubDomains",
47 MaxAge: 1000,
48 // Mess with casing
49 Options: []string{"INCLUDESUBDOMAINS"},
50 expectHeader: "max-age=1000; includeSubDomains",
51 },
52 {
53 Name: "AgePreload",
54 MaxAge: 1000,
55 Options: []string{"Preload"},
56 expectHeader: "max-age=1000; preload",
57 },
58 {
59 Name: "AllOptions",
60 MaxAge: 1000,
61 Options: []string{"preload", "includeSubDomains"},
62 expectHeader: "max-age=1000; preload; includeSubDomains",
63 },
64
65 // Error values
66 {
67 Name: "BadOption",
68 MaxAge: 100,
69 Options: []string{"not-valid"},
70 wantErr: true,

Callers

nothing calls this directly

Calls 9

HSTSConfigOptionsFunction · 0.92
HSTSFunction · 0.92
RunMethod · 0.65
GetMethod · 0.65
WriteHeaderMethod · 0.45
ErrorMethod · 0.45
ServeHTTPMethod · 0.45
EqualMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected