6
6
"log"
7
7
"os"
8
8
"os/signal"
9
+ "strings"
9
10
"testing"
10
11
"time"
11
12
25
26
clientSecret = flag .String ("client-sec" , "static-client-secret" , "Client Secret, set empty to be random" )
26
27
deviceFlow = flag .Bool ("device-flow" , false , "Enable device flow" )
27
28
// 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." )
29
31
)
30
32
31
33
func main () {
@@ -54,6 +56,31 @@ type withClientSecret struct {
54
56
// RunIDP needs the testing.T because our oidctest package requires the
55
57
// testing.T.
56
58
func 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
+
57
84
return func (t * testing.T ) {
58
85
idp := oidctest .NewFakeIDP (t ,
59
86
oidctest .WithServing (),
@@ -63,6 +90,7 @@ func RunIDP() func(t *testing.T) {
63
90
oidctest .WithStaticCredentials (* clientID , * clientSecret ),
64
91
oidctest .WithIssuer ("http://localhost:4500" ),
65
92
oidctest .WithLogger (slog .Make (sloghuman .Sink (os .Stderr ))),
93
+ oidctest .With429 (tooManyRequestParams ),
66
94
)
67
95
id , sec := idp .AppCredentials ()
68
96
prov := idp .WellknownConfig ()
0 commit comments