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

Function TestSafeQueryParams

coderd/httpmw/loggermw/logger_internal_test.go:333–401  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

331}
332
333func TestSafeQueryParams(t *testing.T) {
334 t.Parallel()
335
336 tests := []struct {
337 name string
338 params url.Values
339 expected map[string]interface{}
340 }{
341 {
342 name: "safe parameters",
343 params: url.Values{
344 "page": []string{"1"},
345 "limit": []string{"10"},
346 "filter": []string{"active"},
347 "sort": []string{"name"},
348 "offset": []string{"2"},
349 "ids": []string{"some-id,another-id", "second-param"},
350 "template_ids": []string{"some-id,another-id", "second-param"},
351 },
352 expected: map[string]interface{}{
353 "query_page": "1",
354 "query_limit": "10",
355 "query_offset": "2",
356 "query_ids_count": "3",
357 "query_template_ids_count": "3",
358 },
359 },
360 {
361 name: "unknown/sensitive parameters",
362 params: url.Values{
363 "token": []string{"secret-token"},
364 "api_key": []string{"secret-key"},
365 "coder_signed_app_token": []string{"jwt-token"},
366 "coder_application_connect_api_key": []string{"encrypted-key"},
367 "client_secret": []string{"oauth-secret"},
368 "code": []string{"auth-code"},
369 },
370 expected: map[string]interface{}{},
371 },
372 {
373 name: "mixed parameters",
374 params: url.Values{
375 "page": []string{"1"},
376 "token": []string{"secret"},
377 "filter": []string{"active"},
378 },
379 expected: map[string]interface{}{
380 "query_page": "1",
381 },
382 },
383 }
384
385 for _, tt := range tests {
386 tt := tt
387 t.Run(tt.name, func(t *testing.T) {
388 t.Parallel()
389
390 fields := safeQueryParams(tt.params)

Callers

nothing calls this directly

Calls 3

safeQueryParamsFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected