Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcbcf4ef

Browse files
authored
chore: add faking 429 responses from fake idp (#12365)
Required to trigger error condition in fe.See pull (#12367)
1 parenteba8cd7 commitcbcf4ef

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

‎coderd/coderdtest/oidctest/idp.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,56 @@ func WithIssuer(issuer string) func(*FakeIDP) {
244244
}
245245
}
246246

247+
typeWith429Argumentsstruct {
248+
AllPathsbool
249+
TokenPathbool
250+
AuthorizePathbool
251+
KeysPathbool
252+
UserInfoPathbool
253+
DeviceAuthbool
254+
DeviceVerifybool
255+
}
256+
257+
// With429 will emulate a 429 response for the selected paths.
258+
funcWith429(paramsWith429Arguments)func(*FakeIDP) {
259+
returnfunc(f*FakeIDP) {
260+
f.middlewares=append(f.middlewares,func(next http.Handler) http.Handler {
261+
returnhttp.HandlerFunc(func(rw http.ResponseWriter,r*http.Request) {
262+
ifparams.AllPaths {
263+
http.Error(rw,"429, being manually blocked (all)",http.StatusTooManyRequests)
264+
return
265+
}
266+
ifparams.TokenPath&&strings.Contains(r.URL.Path,tokenPath) {
267+
http.Error(rw,"429, being manually blocked (token)",http.StatusTooManyRequests)
268+
return
269+
}
270+
ifparams.AuthorizePath&&strings.Contains(r.URL.Path,authorizePath) {
271+
http.Error(rw,"429, being manually blocked (authorize)",http.StatusTooManyRequests)
272+
return
273+
}
274+
ifparams.KeysPath&&strings.Contains(r.URL.Path,keysPath) {
275+
http.Error(rw,"429, being manually blocked (keys)",http.StatusTooManyRequests)
276+
return
277+
}
278+
ifparams.UserInfoPath&&strings.Contains(r.URL.Path,userInfoPath) {
279+
http.Error(rw,"429, being manually blocked (userinfo)",http.StatusTooManyRequests)
280+
return
281+
}
282+
ifparams.DeviceAuth&&strings.Contains(r.URL.Path,deviceAuth) {
283+
http.Error(rw,"429, being manually blocked (device-auth)",http.StatusTooManyRequests)
284+
return
285+
}
286+
ifparams.DeviceVerify&&strings.Contains(r.URL.Path,deviceVerify) {
287+
http.Error(rw,"429, being manually blocked (device-verify)",http.StatusTooManyRequests)
288+
return
289+
}
290+
291+
next.ServeHTTP(rw,r)
292+
})
293+
})
294+
}
295+
}
296+
247297
const (
248298
// nolint:gosec // It thinks this is a secret lol
249299
tokenPath="/oauth2/token"

‎scripts/testidp/main.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"log"
77
"os"
88
"os/signal"
9+
"strings"
910
"testing"
1011
"time"
1112

@@ -25,7 +26,8 @@ var (
2526
clientSecret=flag.String("client-sec","static-client-secret","Client Secret, set empty to be random")
2627
deviceFlow=flag.Bool("device-flow",false,"Enable device flow")
2728
// By default, no regex means it will never match anything. So at least default to matching something.
28-
extRegex=flag.String("ext-regex",`^(https?://)?example\.com(/.*)?$`,"External auth regex")
29+
extRegex=flag.String("ext-regex",`^(https?://)?example\.com(/.*)?$`,"External auth regex")
30+
tooManyRequests=flag.String("429","","Simulate too many requests for a given endpoint.")
2931
)
3032

3133
funcmain() {
@@ -54,6 +56,31 @@ type withClientSecret struct {
5456
// RunIDP needs the testing.T because our oidctest package requires the
5557
// testing.T.
5658
funcRunIDP()func(t*testing.T) {
59+
tooManyRequestParams:= oidctest.With429Arguments{}
60+
if*tooManyRequests!="" {
61+
for_,v:=rangestrings.Split(*tooManyRequests,",") {
62+
v=strings.ToLower(strings.TrimSpace(v))
63+
switchv {
64+
case"all":
65+
tooManyRequestParams.AllPaths=true
66+
case"auth":
67+
tooManyRequestParams.AuthorizePath=true
68+
case"token":
69+
tooManyRequestParams.TokenPath=true
70+
case"keys":
71+
tooManyRequestParams.KeysPath=true
72+
case"userinfo":
73+
tooManyRequestParams.UserInfoPath=true
74+
case"device":
75+
tooManyRequestParams.DeviceAuth=true
76+
case"device-verify":
77+
tooManyRequestParams.DeviceVerify=true
78+
default:
79+
log.Printf("Unknown too-many-requests value: %s\nView the `testidp/main.go` for valid values.",v)
80+
}
81+
}
82+
}
83+
5784
returnfunc(t*testing.T) {
5885
idp:=oidctest.NewFakeIDP(t,
5986
oidctest.WithServing(),
@@ -63,6 +90,7 @@ func RunIDP() func(t *testing.T) {
6390
oidctest.WithStaticCredentials(*clientID,*clientSecret),
6491
oidctest.WithIssuer("http://localhost:4500"),
6592
oidctest.WithLogger(slog.Make(sloghuman.Sink(os.Stderr))),
93+
oidctest.With429(tooManyRequestParams),
6694
)
6795
id,sec:=idp.AppCredentials()
6896
prov:=idp.WellknownConfig()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp