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

Function Test_CSRF_Extractor_Metadata

middleware/csrf/config_test.go:150–193  ·  view source on GitHub ↗

Test extractor metadata

(t *testing.T)

Source from the content-addressed store, hash-verified

148
149// Test extractor metadata
150func Test_CSRF_Extractor_Metadata(t *testing.T) {
151 t.Parallel()
152
153 testCases := []struct {
154 name string
155 expectedKey string
156 extractor extractors.Extractor
157 expectedSource extractors.Source
158 }{
159 {
160 name: "FromHeader",
161 extractor: extractors.FromHeader("X-Custom-Token"),
162 expectedSource: extractors.SourceHeader,
163 expectedKey: "X-Custom-Token",
164 },
165 {
166 name: "FromForm",
167 extractor: extractors.FromForm("_token"),
168 expectedSource: extractors.SourceForm,
169 expectedKey: "_token",
170 },
171 {
172 name: "FromQuery",
173 extractor: extractors.FromQuery("token"),
174 expectedSource: extractors.SourceQuery,
175 expectedKey: "token",
176 },
177 {
178 name: "FromParam",
179 extractor: extractors.FromParam("id"),
180 expectedSource: extractors.SourceParam,
181 expectedKey: "id",
182 },
183 }
184
185 for _, tc := range testCases {
186 t.Run(tc.name, func(t *testing.T) {
187 t.Parallel()
188 require.Equal(t, tc.expectedSource, tc.extractor.Source)
189 require.Equal(t, tc.expectedKey, tc.extractor.Key)
190 require.NotNil(t, tc.extractor.Extract)
191 })
192 }
193}
194
195// Test chain extractor metadata
196func Test_CSRF_Chain_Extractor_Metadata(t *testing.T) {

Callers

nothing calls this directly

Calls 4

FromHeaderFunction · 0.92
FromFormFunction · 0.92
FromQueryFunction · 0.92
FromParamFunction · 0.92

Tested by

no test coverage detected