diff --git a/identity-engine/embedded-auth-with-sdk/config/config.go b/identity-engine/embedded-auth-with-sdk/config/config.go index e007775..95a2c38 100644 --- a/identity-engine/embedded-auth-with-sdk/config/config.go +++ b/identity-engine/embedded-auth-with-sdk/config/config.go @@ -16,6 +16,9 @@ package config +import "net/http" + type Config struct { - Testing bool + Testing bool + HttpClient *http.Client } diff --git a/identity-engine/embedded-auth-with-sdk/harness/testing_harness.go b/identity-engine/embedded-auth-with-sdk/harness/testing_harness.go index 6728e78..9b4390d 100644 --- a/identity-engine/embedded-auth-with-sdk/harness/testing_harness.go +++ b/identity-engine/embedded-auth-with-sdk/harness/testing_harness.go @@ -110,8 +110,11 @@ func NewTestHarness() *TestHarness { func (th *TestHarness) InitializeTestSuite(ctx *godog.TestSuiteContext) { rand.Seed(time.Now().UnixNano()) ctx.BeforeSuite(func() { + httpClient := &http.Client{Timeout: time.Second * 30} + httpClient.Transport = &testThrottledTransport{} cfg := &config.Config{ - Testing: true, + Testing: true, + HttpClient: httpClient, } _, client, err := okta.NewClient( context.Background(), @@ -134,6 +137,16 @@ func (th *TestHarness) InitializeTestSuite(ctx *godog.TestSuiteContext) { }) } +type testThrottledTransport struct{} + +func (t *testThrottledTransport) RoundTrip(req *http.Request) (*http.Response, error) { + // Rapid concurrent connections that can be exhibited in an automated test + // harness can get rate limited. + // https://developer.okta.com/docs/reference/rl-additional-limits/ + time.Sleep(time.Millisecond * 75) + return http.DefaultTransport.RoundTrip(req) +} + func (th *TestHarness) depopulateMary() { users, _, _ := th.oktaClient.User.ListUsers(context.Background(), &query.Params{ Q: "Mary", diff --git a/identity-engine/embedded-auth-with-sdk/server/server.go b/identity-engine/embedded-auth-with-sdk/server/server.go index 0b5330b..4bb39c4 100644 --- a/identity-engine/embedded-auth-with-sdk/server/server.go +++ b/identity-engine/embedded-auth-with-sdk/server/server.go @@ -62,6 +62,14 @@ func NewServer(c *config.Config) *Server { log.Fatalf("new client error: %+v", err) } + // NOTE: The cucumber testing harness Okta uses to ensure the golang samples + // remain operational needs to be throttled so it doesn't get rate limited + // by too many concurrent requests in tests. The idx client allows the + // ability to set a custom http client and we make use of that feature here. + if c.HttpClient != nil { + idx = idx.WithHTTPClient(c.HttpClient) + } + return &Server{ config: c, idxClient: idx,