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

Function With429

coderd/coderdtest/oidctest/idp.go:403–444  ·  view source on GitHub ↗

With429 will emulate a 429 response for the selected paths.

(params With429Arguments)

Source from the content-addressed store, hash-verified

401
402// With429 will emulate a 429 response for the selected paths.
403func With429(params With429Arguments) func(*FakeIDP) {
404 return func(f *FakeIDP) {
405 f.middlewares = append(f.middlewares, func(next http.Handler) http.Handler {
406 return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
407 if params.AllPaths {
408 http.Error(rw, "429, being manually blocked (all)", http.StatusTooManyRequests)
409 return
410 }
411 if params.TokenPath && strings.Contains(r.URL.Path, tokenPath) {
412 http.Error(rw, "429, being manually blocked (token)", http.StatusTooManyRequests)
413 return
414 }
415 if params.AuthorizePath && strings.Contains(r.URL.Path, authorizePath) {
416 http.Error(rw, "429, being manually blocked (authorize)", http.StatusTooManyRequests)
417 return
418 }
419 if params.KeysPath && strings.Contains(r.URL.Path, keysPath) {
420 http.Error(rw, "429, being manually blocked (keys)", http.StatusTooManyRequests)
421 return
422 }
423 if params.UserInfoPath && strings.Contains(r.URL.Path, userInfoPath) {
424 http.Error(rw, "429, being manually blocked (userinfo)", http.StatusTooManyRequests)
425 return
426 }
427 if params.RevokePath && strings.Contains(r.URL.Path, revokeTokenPath) {
428 http.Error(rw, "429, being manually blocked (revoke)", http.StatusTooManyRequests)
429 return
430 }
431 if params.DeviceAuth && strings.Contains(r.URL.Path, deviceAuth) {
432 http.Error(rw, "429, being manually blocked (device-auth)", http.StatusTooManyRequests)
433 return
434 }
435 if params.DeviceVerify && strings.Contains(r.URL.Path, deviceVerify) {
436 http.Error(rw, "429, being manually blocked (device-verify)", http.StatusTooManyRequests)
437 return
438 }
439
440 next.ServeHTTP(rw, r)
441 })
442 })
443 }
444}
445
446const (
447 // nolint:gosec // It thinks this is a secret lol

Callers 1

RunIDPFunction · 0.92

Calls 3

ErrorMethod · 0.45
ContainsMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected