66 "log"
77 "os"
88 "os/signal"
9+ "strings"
910 "testing"
1011 "time"
1112
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
3133func main () {
@@ -54,6 +56,31 @@ type withClientSecret struct {
5456// RunIDP needs the testing.T because our oidctest package requires the
5557// testing.T.
5658func RunIDP () func (t * testing.T ) {
59+ tooManyRequestParams := oidctest.With429Arguments {}
60+ if * tooManyRequests != "" {
61+ for _ , v := range strings .Split (* tooManyRequests , "," ) {
62+ v = strings .ToLower (strings .TrimSpace (v ))
63+ switch v {
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\n View the `testidp/main.go` for valid values." , v )
80+ }
81+ }
82+ }
83+
5784 return func (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