From 9a2a408e5ae550d3ce5c6a4ef1c34148ba35469b Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sat, 7 Nov 2020 22:36:44 +0200 Subject: [PATCH 01/14] Added maximum allowed backoff value --- okta/config.go | 7 +++++++ okta/requestExecutor.go | 27 +++++++++++---------------- tests/mocks.go | 6 +++--- tests/unit/retry_logic_test.go | 4 ++-- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/okta/config.go b/okta/config.go index 85a4a0650..424719e65 100644 --- a/okta/config.go +++ b/okta/config.go @@ -40,6 +40,7 @@ type config struct { RequestTimeout int64 `yaml:"requestTimeout" envconfig:"OKTA_CLIENT_REQUEST_TIMEOUT"` RateLimit struct { MaxRetries int32 `yaml:"maxRetries" envconfig:"OKTA_CLIENT_RATE_LIMIT_MAX_RETRIES"` + MaxBackoff int64 `yaml:"maxBackoff" envconfig:"OKTA_CLIENT_RATE_LIMIT_MAX_BACKOFF"` } `yaml:"rateLimit"` OrgUrl string `yaml:"orgUrl" envconfig:"OKTA_CLIENT_ORGURL"` Token string `yaml:"token" envconfig:"OKTA_CLIENT_TOKEN"` @@ -155,6 +156,12 @@ func WithRateLimitMaxRetries(maxRetries int32) ConfigSetter { } } +func WithRateLimitMaxBackOff(maxBackoff int64) ConfigSetter { + return func(c *config) { + c.Okta.Client.RateLimit.MaxBackoff = maxBackoff + } +} + func WithAuthorizationMode(authzMode string) ConfigSetter { return func(c *config) { c.Okta.Client.AuthorizationMode = authzMode diff --git a/okta/requestExecutor.go b/okta/requestExecutor.go index 578c1b6b3..aaf876e88 100644 --- a/okta/requestExecutor.go +++ b/okta/requestExecutor.go @@ -284,12 +284,7 @@ func (re *RequestExecutor) doWithRetries(ctx context.Context, req *http.Request, return resp, errors.New("a 429 response must include the x-retry-limit-reset and date headers") } - if tooManyRequests(resp) { - err := backoffPause(ctx, retryCount, resp) - if err != nil { - return nil, err - } - } + backoffPause(re.config.Okta.Client.RateLimit.MaxBackoff, resp) retryCount++ req.Header.Add("X-Okta-Retry-For", resp.Header.Get("X-Okta-Request-Id")) @@ -315,18 +310,18 @@ func tryDrainBody(body io.ReadCloser) error { return nil } -func backoffPause(ctx context.Context, retryCount int32, response *http.Response) error { - if response.StatusCode == http.StatusTooManyRequests { - backoffSeconds := Get429BackoffTime(ctx, response) - time.Sleep(time.Duration(backoffSeconds) * time.Second) - - return nil +func backoffPause(maxBackOff int64, response *http.Response) { + if response != nil && response.StatusCode == http.StatusTooManyRequests { + backoffSeconds := Get429BackoffTime(response) + if backoffSeconds > maxBackOff { + time.Sleep(time.Duration(maxBackOff) * time.Second) + } else { + time.Sleep(time.Duration(backoffSeconds) * time.Second) + } } - - return nil } -func Get429BackoffTime(ctx context.Context, response *http.Response) int64 { +func Get429BackoffTime(response *http.Response) int64 { var limitResetMap []int for _, time := range response.Header["X-Rate-Limit-Reset"] { @@ -336,7 +331,7 @@ func Get429BackoffTime(ctx context.Context, response *http.Response) int64 { sort.Ints(limitResetMap) - requestDate, _ := time.Parse("Mon, 02 Jan 2006 15:04:05 Z", response.Header.Get("Date")) + requestDate, _ := time.Parse("Mon, 02 Jan 2006 15:04:05 GMT", response.Header.Get("Date")) requestDateUnix := requestDate.Unix() backoffSeconds := int64(limitResetMap[0]) - requestDateUnix + 1 return backoffSeconds diff --git a/tests/mocks.go b/tests/mocks.go index af0b1746f..c6267a84b 100644 --- a/tests/mocks.go +++ b/tests/mocks.go @@ -32,7 +32,7 @@ func Mock429Response() *http.Response { header.Add("X-Rate-Limit-Reset", strconv.FormatInt(time.Now().Unix()+1, 10)) header.Add("X-Okta-Request-id", "a-request-id") header.Add("Content-Type", "application/json") - header.Add("Date", zulu.Format("Mon, 02 Jan 2006 15:04:05 Z")) + header.Add("Date", zulu.Format("Mon, 02 Jan 2006 15:04:05 GMT")) return &http.Response{ Status: strconv.Itoa(429), @@ -50,7 +50,7 @@ func Mock429ResponseNoResetHeader() *http.Response { header.Add("X-Okta-Now", strconv.FormatInt(zulu.Unix(), 10)) header.Add("X-Okta-Request-id", "a-request-id") header.Add("Content-Type", "application/json") - header.Add("Date", zulu.Format("Mon, 02 Jan 2006 15:04:05 Z")) + header.Add("Date", zulu.Format("Mon, 02 Jan 2006 15:04:05 GMT")) return &http.Response{ Status: strconv.Itoa(429), @@ -88,7 +88,7 @@ func Mock429ResponseMultipleHeaders() *http.Response { header.Add("X-Rate-Limit-Reset", strconv.FormatInt(time.Now().Unix()+10, 10)) header.Add("X-Okta-Request-id", "a-request-id") header.Add("Content-Type", "application/json") - header.Add("Date", zulu.Format("Mon, 02 Jan 2006 15:04:05 Z")) + header.Add("Date", zulu.Format("Mon, 02 Jan 2006 15:04:05 GMT")) return &http.Response{ Status: strconv.Itoa(429), diff --git a/tests/unit/retry_logic_test.go b/tests/unit/retry_logic_test.go index 0b1196417..ebe84e998 100644 --- a/tests/unit/retry_logic_test.go +++ b/tests/unit/retry_logic_test.go @@ -133,13 +133,13 @@ func Test_a_429_with_no_date_header_throws_error(t *testing.T) { } func Test_gets_the_correct_backoff_time(t *testing.T) { - backoff := okta.Get429BackoffTime(context.TODO(), tests.Mock429Response()) + backoff := okta.Get429BackoffTime(tests.Mock429Response()) require.Equal(t, int64(2), backoff, "backoff time should have only been 1 second") } func Test_with_multiple_x_rate_limit_request_times_still_retries(t *testing.T) { - backoff := okta.Get429BackoffTime(context.TODO(), tests.Mock429ResponseMultipleHeaders()) + backoff := okta.Get429BackoffTime(tests.Mock429ResponseMultipleHeaders()) require.Equal(t, int64(11), backoff, "Backoff time should handle the correct header") } From ccf6d8a0c8d31e1b1734b3a8c0e6f5f4f85afeb2 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sat, 7 Nov 2020 22:39:29 +0200 Subject: [PATCH 02/14] Added default value for maximum backoff --- okta/okta.go | 1 + 1 file changed, 1 insertion(+) diff --git a/okta/okta.go b/okta/okta.go index 2166d8621..d38812ec9 100644 --- a/okta/okta.go +++ b/okta/okta.go @@ -151,6 +151,7 @@ func setConfigDefaults(c *config) { WithTestingDisableHttpsCheck(false), WithRequestTimeout(0), WithRateLimitMaxRetries(2), + WithRateLimitMaxBackOff(15), WithAuthorizationMode("SSWS")) for _, confSetter := range conf { From 514c3af7845957f749edcad5959e5943eba22ddd Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sun, 8 Nov 2020 14:51:47 +0200 Subject: [PATCH 03/14] Added request timeout into the ctx --- go.mod | 1 + go.sum | 4 + okta/requestExecutor.go | 132 ++++++++++++++++++--------------- tests/unit/retry_logic_test.go | 15 +--- 4 files changed, 83 insertions(+), 69 deletions(-) diff --git a/go.mod b/go.mod index 2b9cd830c..f160e5bfc 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,7 @@ module github.com/okta/okta-sdk-golang/v2 require ( + github.com/cenkalti/backoff/v4 v4.1.0 github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-yaml/yaml v2.1.0+incompatible github.com/google/go-cmp v0.4.0 // indirect diff --git a/go.sum b/go.sum index 17cb11bdc..bf97f2fd6 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,7 @@ +github.com/cenkalti/backoff v1.1.0 h1:QnvVp8ikKCDWOsFheytRCoYWYPO/ObCTBGxT19Hc+yE= +github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= +github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc= +github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/okta/requestExecutor.go b/okta/requestExecutor.go index aaf876e88..949f38780 100644 --- a/okta/requestExecutor.go +++ b/okta/requestExecutor.go @@ -31,11 +31,11 @@ import ( "net/url" nUrl "net/url" "reflect" - "sort" "strconv" "strings" "time" + "github.com/cenkalti/backoff/v4" "github.com/okta/okta-sdk-golang/v2/okta/cache" "gopkg.in/square/go-jose.v2" "gopkg.in/square/go-jose.v2/jwt" @@ -224,7 +224,6 @@ func (re *RequestExecutor) RefreshNext() *RequestExecutor { } func (re *RequestExecutor) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) { - requestStarted := time.Now().Unix() cacheKey := cache.CreateCacheKey(req) if req.Method != http.MethodGet { re.cache.Delete(cacheKey) @@ -238,7 +237,7 @@ func (re *RequestExecutor) Do(ctx context.Context, req *http.Request, v interfac if !inCache { - resp, err := re.doWithRetries(ctx, req, 0, requestStarted, nil) + resp, err := re.doWithRetries(ctx, req) if err != nil { return nil, err @@ -254,46 +253,76 @@ func (re *RequestExecutor) Do(ctx context.Context, req *http.Request, v interfac } -func (re *RequestExecutor) doWithRetries(ctx context.Context, req *http.Request, retryCount int32, requestStarted int64, lastResponse *http.Response) (*http.Response, error) { - iterationStart := time.Now().Unix() - maxRetries := re.config.Okta.Client.RateLimit.MaxRetries - requestTimeout := int64(re.config.Okta.Client.RequestTimeout) +type oktaBackoff struct { + retryCount, maxRetries int32 + startTime int64 + backoffDuration time.Duration + ctx context.Context + err error +} + +// NextBackOff returns the duration to wait before retrying the operation, +// or backoff. Stop to indicate that no more retries should be made. +func (o *oktaBackoff) NextBackOff() time.Duration { + // stop retrying if operation reached retry limit + if o.retryCount > o.maxRetries { + return backoff.Stop + } + return o.backoffDuration +} + +// Reset to initial state. +func (o *oktaBackoff) Reset() {} +func (o *oktaBackoff) Context() context.Context { + return o.ctx +} + +func (re *RequestExecutor) doWithRetries(ctx context.Context, req *http.Request) (*http.Response, error) { + var ( + resp *http.Response + err error + ) if req.Body != nil { bodyBytes, _ := ioutil.ReadAll(req.Body) req.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) } - - if requestTimeout > 0 && (iterationStart-requestStarted) >= requestTimeout { - return lastResponse, errors.New("reached the max request time") + if re.config.Okta.Client.RequestTimeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, time.Second*time.Duration(re.config.Okta.Client.RequestTimeout)) + defer cancel() } - - req = req.WithContext(ctx) - resp, err := re.httpClient.Do(req) - - if (err != nil || tooManyRequests(resp)) && retryCount < maxRetries { - if resp != nil { - err := tryDrainBody(resp.Body) - if err != nil { - return nil, err - } - - retryLimitReset := resp.Header.Get("X-Rate-Limit-Reset") - date := resp.Header.Get("Date") - if retryLimitReset == "" || date == "" { - return resp, errors.New("a 429 response must include the x-retry-limit-reset and date headers") - } - - backoffPause(re.config.Okta.Client.RateLimit.MaxBackoff, resp) - retryCount++ - - req.Header.Add("X-Okta-Retry-For", resp.Header.Get("X-Okta-Request-Id")) - req.Header.Add("X-Okta-Retry-Count", fmt.Sprint(retryCount)) - - resp, err = re.doWithRetries(ctx, req, retryCount, requestStarted, resp) + bOff := &oktaBackoff{ + ctx: ctx, + maxRetries: re.config.Okta.Client.RateLimit.MaxRetries, + startTime: time.Now().Unix(), + } + operation := func() error { + resp, err = re.httpClient.Do(req.WithContext(ctx)) + if err != nil { + // this is error is considered to be permanent and should not be retried + return backoff.Permanent(err) + } + if !tooManyRequests(resp) { + return nil } + if err = tryDrainBody(resp.Body); err != nil { + return err + } + backoffDuration, err := Get429BackoffTime(resp) + if err != nil { + return err + } + if re.config.Okta.Client.RateLimit.MaxBackoff < backoffDuration { + backoffDuration = re.config.Okta.Client.RateLimit.MaxBackoff + } + bOff.backoffDuration = time.Second * time.Duration(backoffDuration) + bOff.retryCount++ + req.Header.Add("X-Okta-Retry-For", resp.Header.Get("X-Okta-Request-Id")) + req.Header.Add("X-Okta-Retry-Count", fmt.Sprint(bOff.retryCount)) + return errors.New("to many requests") } - + err = backoff.Retry(operation, bOff) return resp, err } @@ -310,31 +339,18 @@ func tryDrainBody(body io.ReadCloser) error { return nil } -func backoffPause(maxBackOff int64, response *http.Response) { - if response != nil && response.StatusCode == http.StatusTooManyRequests { - backoffSeconds := Get429BackoffTime(response) - if backoffSeconds > maxBackOff { - time.Sleep(time.Duration(maxBackOff) * time.Second) - } else { - time.Sleep(time.Duration(backoffSeconds) * time.Second) - } +func Get429BackoffTime(resp *http.Response) (int64, error) { + requestDate, err := time.Parse("Mon, 02 Jan 2006 15:04:05 GMT", resp.Header.Get("Date")) + if err != nil { + // this is error is considered to be permanent and should not be retried + return 0, backoff.Permanent(errors.New(fmt.Sprintf("Date header is missing or invalid: %v", err))) } -} - -func Get429BackoffTime(response *http.Response) int64 { - var limitResetMap []int - - for _, time := range response.Header["X-Rate-Limit-Reset"] { - timestamp, _ := strconv.Atoi(time) - limitResetMap = append(limitResetMap, timestamp) + rateLimitReset, err := strconv.Atoi(resp.Header.Get("X-Rate-Limit-Reset")) + if err != nil { + // this is error is considered to be permanent and should not be retried + return 0, backoff.Permanent(errors.New(fmt.Sprintf("X-Rate-Limit-Reset header is missing or invalid: %v", err))) } - - sort.Ints(limitResetMap) - - requestDate, _ := time.Parse("Mon, 02 Jan 2006 15:04:05 GMT", response.Header.Get("Date")) - requestDateUnix := requestDate.Unix() - backoffSeconds := int64(limitResetMap[0]) - requestDateUnix + 1 - return backoffSeconds + return int64(rateLimitReset) - requestDate.Unix() + 1, nil } type Response struct { diff --git a/tests/unit/retry_logic_test.go b/tests/unit/retry_logic_test.go index ebe84e998..3ad544d84 100644 --- a/tests/unit/retry_logic_test.go +++ b/tests/unit/retry_logic_test.go @@ -20,12 +20,10 @@ import ( "context" "testing" - "github.com/stretchr/testify/require" - - "github.com/okta/okta-sdk-golang/v2/okta" - "github.com/jarcoal/httpmock" + "github.com/okta/okta-sdk-golang/v2/okta" "github.com/okta/okta-sdk-golang/v2/tests" + "github.com/stretchr/testify/require" ) func Test_429_Will_Automatically_Retry(t *testing.T) { @@ -133,13 +131,8 @@ func Test_a_429_with_no_date_header_throws_error(t *testing.T) { } func Test_gets_the_correct_backoff_time(t *testing.T) { - backoff := okta.Get429BackoffTime(tests.Mock429Response()) + backoff, err := okta.Get429BackoffTime(tests.Mock429Response()) + require.NoError(t, err) require.Equal(t, int64(2), backoff, "backoff time should have only been 1 second") } - -func Test_with_multiple_x_rate_limit_request_times_still_retries(t *testing.T) { - backoff := okta.Get429BackoffTime(tests.Mock429ResponseMultipleHeaders()) - - require.Equal(t, int64(11), backoff, "Backoff time should handle the correct header") -} From efdf250a17d89fb7cc2bc1ca2284b77eecf53185 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sun, 8 Nov 2020 16:14:44 +0200 Subject: [PATCH 04/14] Upgraded golang version --- .travis.yml | 2 +- Gopkg.lock | 48 ------------------------------------------------ Gopkg.toml | 41 ----------------------------------------- 3 files changed, 1 insertion(+), 90 deletions(-) delete mode 100644 Gopkg.lock delete mode 100644 Gopkg.toml diff --git a/.travis.yml b/.travis.yml index cee666727..d2e4b9447 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.12.x + - 1.13.x - tip script: diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index f78afa2df..000000000 --- a/Gopkg.lock +++ /dev/null @@ -1,48 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - name = "github.com/davecgh/go-spew" - packages = ["spew"] - revision = "346938d642f2ec3594ed81d874461961cd0faa76" - version = "v1.1.0" - -[[projects]] - name = "github.com/go-yaml/yaml" - packages = ["."] - revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" - version = "v2.2.1" - -[[projects]] - name = "github.com/kelseyhightower/envconfig" - packages = ["."] - revision = "f611eb38b3875cc3bd991ca91c51d06446afa14c" - version = "v1.3.0" - -[[projects]] - name = "github.com/patrickmn/go-cache" - packages = ["."] - revision = "a3647f8e31d79543b2d0f0ae2fe5c379d72cedc0" - version = "v2.1.0" - -[[projects]] - name = "github.com/pmezard/go-difflib" - packages = ["difflib"] - revision = "792786c7400a136282c1664665ae0a8db921c6c2" - version = "v1.0.0" - -[[projects]] - name = "github.com/stretchr/testify" - packages = [ - "assert", - "require" - ] - revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" - version = "v1.2.2" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - inputs-digest = "216b5151a6e9730e048f0b696f7f78bfae2346a4e3d92595fa82d3807dc12be8" - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index 5eda54084..000000000 --- a/Gopkg.toml +++ /dev/null @@ -1,41 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - -[prune] - go-tests = true - unused-packages = true - -[[constraint]] - name = "github.com/go-yaml/yaml" - version = "2.2.1" - -[[constraint]] - name = "github.com/kelseyhightower/envconfig" - version = "1.3.0" - -[[constraint]] - name = "github.com/patrickmn/go-cache" - version = "2.1.0" From 05c2ea4a52a10f5648fcc4199e65ca79fc2e9528 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sun, 8 Nov 2020 16:15:22 +0200 Subject: [PATCH 05/14] Upgraded golang version --- .travis.yml | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d2e4b9447..45c5378d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: go go: - - 1.13.x + - 1.15.x - tip script: diff --git a/go.mod b/go.mod index f160e5bfc..bfd996720 100644 --- a/go.mod +++ b/go.mod @@ -17,4 +17,4 @@ require ( ) -go 1.13 +go 1.15 From 05cadf14d1068ac2a0232525e346eedd282f1af4 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sun, 8 Nov 2020 16:22:28 +0200 Subject: [PATCH 06/14] Updated dependencies --- go.mod | 8 +++----- go.sum | 16 ++++++---------- okta/okta.go | 6 ++---- openapi/generator/templates/okta.go.hbs | 7 +++---- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index bfd996720..e494ff667 100644 --- a/go.mod +++ b/go.mod @@ -3,18 +3,16 @@ module github.com/okta/okta-sdk-golang/v2 require ( github.com/cenkalti/backoff/v4 v4.1.0 github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-yaml/yaml v2.1.0+incompatible github.com/google/go-cmp v0.4.0 // indirect - github.com/jarcoal/httpmock v1.0.5 + github.com/jarcoal/httpmock v1.0.6 github.com/kelseyhightower/envconfig v1.4.0 github.com/kr/pretty v0.1.0 // indirect github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 github.com/stretchr/testify v1.6.1 - golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d // indirect + golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect gopkg.in/square/go-jose.v2 v2.5.1 - gopkg.in/yaml.v2 v2.2.2 // indirect - + gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 ) go 1.15 diff --git a/go.sum b/go.sum index bf97f2fd6..083b2260f 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,13 @@ -github.com/cenkalti/backoff v1.1.0 h1:QnvVp8ikKCDWOsFheytRCoYWYPO/ObCTBGxT19Hc+yE= -github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= github.com/cenkalti/backoff/v4 v4.1.0 h1:c8LkOFQTzuO0WBM/ae5HdGQuZPfPxp7lqBRwQRm4fSc= github.com/cenkalti/backoff/v4 v4.1.0/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-yaml/yaml v2.1.0+incompatible h1:RYi2hDdss1u4YE7GwixGzWwVo47T8UQwnTLB6vQiq+o= -github.com/go-yaml/yaml v2.1.0+incompatible/go.mod h1:w2MrLa16VYP0jy6N7M5kHaCkaLENm+P+Tv+MfurjSw0= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/jarcoal/httpmock v1.0.5 h1:cHtVEcTxRSX4J0je7mWPfc9BpDpqzXSJ5HbymZmyHck= -github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik= +github.com/jarcoal/httpmock v1.0.6 h1:e81vOSexXU3mJuJ4l//geOmKIt+Vkxerk1feQBC8D0g= +github.com/jarcoal/httpmock v1.0.6/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik= github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8= github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -28,8 +24,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= -golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E= +golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -41,7 +37,7 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/square/go-jose.v2 v2.5.1 h1:7odma5RETjNHWJnR32wx8t+Io4djHE1PqxCFx3iiZ2w= gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= -gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/okta/okta.go b/okta/okta.go index d38812ec9..2427d07a1 100644 --- a/okta/okta.go +++ b/okta/okta.go @@ -27,10 +27,9 @@ import ( "path/filepath" "runtime" - "github.com/okta/okta-sdk-golang/v2/okta/cache" - - "github.com/go-yaml/yaml" "github.com/kelseyhightower/envconfig" + "github.com/okta/okta-sdk-golang/v2/okta/cache" + "gopkg.in/yaml.v3" ) const Version = "2.1.0" @@ -151,7 +150,6 @@ func setConfigDefaults(c *config) { WithTestingDisableHttpsCheck(false), WithRequestTimeout(0), WithRateLimitMaxRetries(2), - WithRateLimitMaxBackOff(15), WithAuthorizationMode("SSWS")) for _, confSetter := range conf { diff --git a/openapi/generator/templates/okta.go.hbs b/openapi/generator/templates/okta.go.hbs index 732916648..fa8240f15 100644 --- a/openapi/generator/templates/okta.go.hbs +++ b/openapi/generator/templates/okta.go.hbs @@ -11,10 +11,9 @@ import ( "path/filepath" "runtime" - "github.com/okta/okta-sdk-golang/v2/okta/cache" - - "github.com/go-yaml/yaml" - "github.com/kelseyhightower/envconfig" + "github.com/kelseyhightower/envconfig" + "github.com/okta/okta-sdk-golang/v2/okta/cache" + "gopkg.in/yaml.v3" ) const Version = "2.1.0" From 35054ed8599887472d0c9d0e0e92ebadc77fa4f5 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sun, 8 Nov 2020 20:03:16 +0200 Subject: [PATCH 07/14] Added default value for max backoff duration --- okta/okta.go | 1 + openapi/generator/templates/okta.go.hbs | 1 + 2 files changed, 2 insertions(+) diff --git a/okta/okta.go b/okta/okta.go index 2427d07a1..0a65721f3 100644 --- a/okta/okta.go +++ b/okta/okta.go @@ -149,6 +149,7 @@ func setConfigDefaults(c *config) { WithUserAgentExtra(""), WithTestingDisableHttpsCheck(false), WithRequestTimeout(0), + WithRateLimitMaxBackOff(30), WithRateLimitMaxRetries(2), WithAuthorizationMode("SSWS")) diff --git a/openapi/generator/templates/okta.go.hbs b/openapi/generator/templates/okta.go.hbs index fa8240f15..34bb0cd85 100644 --- a/openapi/generator/templates/okta.go.hbs +++ b/openapi/generator/templates/okta.go.hbs @@ -103,6 +103,7 @@ func setConfigDefaults(c *config) { WithUserAgentExtra(""), WithTestingDisableHttpsCheck(false), WithRequestTimeout(0), + WithRateLimitMaxBackOff(30), WithRateLimitMaxRetries(2), WithAuthorizationMode("SSWS")) From d7c529f0146f83215c7d796fb86fb704604a707e Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Mon, 9 Nov 2020 12:30:48 +0200 Subject: [PATCH 08/14] Fixed spacing --- openapi/generator/templates/okta.go.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi/generator/templates/okta.go.hbs b/openapi/generator/templates/okta.go.hbs index 34bb0cd85..160929037 100644 --- a/openapi/generator/templates/okta.go.hbs +++ b/openapi/generator/templates/okta.go.hbs @@ -103,7 +103,7 @@ func setConfigDefaults(c *config) { WithUserAgentExtra(""), WithTestingDisableHttpsCheck(false), WithRequestTimeout(0), - WithRateLimitMaxBackOff(30), + WithRateLimitMaxBackOff(30), WithRateLimitMaxRetries(2), WithAuthorizationMode("SSWS")) From da46c82da08e76f37c0338818cb9cfbf4b1de335 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Tue, 10 Nov 2020 10:24:45 +0200 Subject: [PATCH 09/14] Added sweeper --- tests/integration/main_test.go | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/integration/main_test.go diff --git a/tests/integration/main_test.go b/tests/integration/main_test.go new file mode 100644 index 000000000..7ce6c8574 --- /dev/null +++ b/tests/integration/main_test.go @@ -0,0 +1,59 @@ +package integration + +import ( + "context" + "fmt" + "log" + "os" + "testing" + + "github.com/okta/okta-sdk-golang/v2/okta" + "github.com/okta/okta-sdk-golang/v2/okta/query" + "github.com/okta/okta-sdk-golang/v2/tests" +) + +func TestMain(m *testing.M) { + err := sweep() + if err != nil { + log.Fatalf("failed to clean up organization before integration tests: %v", err) + } + exitVal := m.Run() + os.Exit(exitVal) +} + +func sweep() error { + ctx, client, err := tests.NewClient(context.Background()) + if err != nil { + return err + } + return sweepUsers(ctx, client) +} + +func sweepUsers(ctx context.Context, client *okta.Client) error { + users, _, err := client.User.ListUsers(ctx, &query.Params{Q: "admin_role"}) + if err != nil { + return err + } + for _, u := range users { + if err := ensureUserDelete(ctx, client, u.Id, u.Status); err != nil { + return err + } + } + return nil +} + +func ensureUserDelete(ctx context.Context, client *okta.Client, id, status string) error { + // only deprovisioned users can be deleted fully from okta + // make two passes on the user if they aren't deprovisioned already to deprovision them first + passes := 2 + if status == "DEPROVISIONED" { + passes = 1 + } + for i := 0; i < passes; i++ { + _, err := client.User.DeactivateOrDeleteUser(ctx, id, nil) + if err != nil { + return fmt.Errorf("failed to deprovision or delete user: %v", err) + } + } + return nil +} From c1181ab5873f465ea9eecde80dc7cecd2abdf9e8 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Tue, 10 Nov 2020 12:18:09 +0200 Subject: [PATCH 10/14] Added comment --- tests/integration/main_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/main_test.go b/tests/integration/main_test.go index 7ce6c8574..a64122f40 100644 --- a/tests/integration/main_test.go +++ b/tests/integration/main_test.go @@ -21,6 +21,7 @@ func TestMain(m *testing.M) { os.Exit(exitVal) } +// sweep the resources before running integration tests func sweep() error { ctx, client, err := tests.NewClient(context.Background()) if err != nil { From a59861d0c212998da1de50cdc538da8a4554b082 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Tue, 10 Nov 2020 13:36:10 +0200 Subject: [PATCH 11/14] Added error checks for integration tests --- tests/integration/admin_roles_test.go | 30 +++++++++----- tests/integration/application_test.go | 39 ++++++++++++------- .../integration/authorization_server_test.go | 18 ++++++--- tests/integration/event_hooks_test.go | 21 ++++++---- tests/integration/factor_test.go | 3 +- tests/integration/feature_test.go | 15 ++++--- tests/integration/group_test.go | 17 +++++--- tests/integration/request_test.go | 3 +- tests/integration/user_test.go | 31 +++++++++------ tests/integration/user_type_test.go | 6 ++- 10 files changed, 121 insertions(+), 62 deletions(-) diff --git a/tests/integration/admin_roles_test.go b/tests/integration/admin_roles_test.go index a53400cb3..1907fe6e1 100644 --- a/tests/integration/admin_roles_test.go +++ b/tests/integration/admin_roles_test.go @@ -28,7 +28,8 @@ import ( ) func Test_can_add_an_admin_role_to_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) p := &okta.PasswordCredential{ Value: "Abcd1234", } @@ -72,7 +73,8 @@ func Test_can_add_an_admin_role_to_user(t *testing.T) { } func Test_can_add_an_admin_role_to_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) gp := &okta.GroupProfile{ Name: "Assign Admin Role To Group", } @@ -103,7 +105,8 @@ func Test_can_add_an_admin_role_to_group(t *testing.T) { } func Test_can_remove_an_admin_role_to_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) p := &okta.PasswordCredential{ Value: "Abcd1234", } @@ -145,7 +148,8 @@ func Test_can_remove_an_admin_role_to_user(t *testing.T) { } func Test_can_remove_an_admin_role_to_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) gp := &okta.GroupProfile{ Name: "Assign Admin Role To Group", } @@ -174,7 +178,8 @@ func Test_can_remove_an_admin_role_to_group(t *testing.T) { } func Test_can_list_roles_assigned_to_a_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) p := &okta.PasswordCredential{ Value: "Abcd1234", } @@ -228,7 +233,8 @@ func Test_can_list_roles_assigned_to_a_user(t *testing.T) { } func Test_can_list_roles_assigned_to_a_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) gp := &okta.GroupProfile{ Name: "Assign Admin Role To Group", } @@ -267,7 +273,8 @@ func Test_can_list_roles_assigned_to_a_group(t *testing.T) { } func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) p := &okta.PasswordCredential{ Value: "Abcd1234", } @@ -320,7 +327,8 @@ func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_user } func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) role := okta.AssignRoleRequest{ Type: "USER_ADMIN", @@ -349,7 +357,8 @@ func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_grou } func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) p := &okta.PasswordCredential{ Value: "Abcd1234", } @@ -414,7 +423,8 @@ func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_use } func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) role := okta.AssignRoleRequest{ Type: "USER_ADMIN", diff --git a/tests/integration/application_test.go b/tests/integration/application_test.go index ddd450eca..74c160281 100644 --- a/tests/integration/application_test.go +++ b/tests/integration/application_test.go @@ -33,7 +33,8 @@ import ( ) func Test_can_get_applicaiton_by_id(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -62,7 +63,8 @@ func Test_can_get_applicaiton_by_id(t *testing.T) { } func Test_can_update_application(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -101,7 +103,8 @@ func Test_can_update_application(t *testing.T) { } func Test_can_create_a_bookmark_application(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) bookmarkApplicationSettingsApplication := okta.NewBookmarkApplicationSettingsApplication() bookmarkApplicationSettingsApplication.RequestIntegration = new(bool) @@ -126,7 +129,8 @@ func Test_can_create_a_bookmark_application(t *testing.T) { } func Test_can_create_a_basic_authentication_application(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -153,7 +157,8 @@ func Test_can_create_a_basic_authentication_application(t *testing.T) { } func Test_list_application_allows_casting_to_correct_type(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -207,7 +212,8 @@ func Test_list_application_allows_casting_to_correct_type(t *testing.T) { } func Test_can_activate_application(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -238,7 +244,8 @@ func Test_can_activate_application(t *testing.T) { } func Test_can_deactivate_application(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -268,7 +275,8 @@ func Test_can_deactivate_application(t *testing.T) { } func Test_can_add_and_remove_application_users(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.htmel" @@ -342,7 +350,8 @@ func Test_can_add_and_remove_application_users(t *testing.T) { } func Test_can_set_application_settings_during_creation(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -369,7 +378,8 @@ func Test_can_set_application_settings_during_creation(t *testing.T) { } func Test_can_set_application_settings_during_update(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" @@ -406,7 +416,8 @@ func Test_can_set_application_settings_during_update(t *testing.T) { } func Test_can_create_csr_for_application(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) application := create_application(t) @@ -440,7 +451,8 @@ func Test_can_create_csr_for_application(t *testing.T) { } func create_application(t *testing.T) *okta.BasicAuthApplication { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication() basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html" basicApplicationSettingsApplication.Url = "https://example.com/auth.html" @@ -458,7 +470,8 @@ func create_application(t *testing.T) *okta.BasicAuthApplication { } func delete_all_apps(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) applicationList, _, err := client.Application.ListApplications(ctx, nil) if err != nil { diff --git a/tests/integration/authorization_server_test.go b/tests/integration/authorization_server_test.go index 2b5a47cfe..d2d77ae70 100644 --- a/tests/integration/authorization_server_test.go +++ b/tests/integration/authorization_server_test.go @@ -29,7 +29,8 @@ import ( ) func Test_can_create_an_authorizaiton_server(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) as := okta.AuthorizationServer{ Name: "Sample Authorizaiton Server - Golang", @@ -47,7 +48,8 @@ func Test_can_create_an_authorizaiton_server(t *testing.T) { } func Test_can_get_an_authorizaiton_server(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) as := okta.AuthorizationServer{ Name: "Sample Authorizaiton Server - Golang", @@ -72,7 +74,8 @@ func Test_can_get_an_authorizaiton_server(t *testing.T) { } func Test_can_update_an_authorizaiton_server(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) as := okta.AuthorizationServer{ Name: "Sample Authorizaiton Server - Golang", @@ -111,7 +114,8 @@ func Test_can_update_an_authorizaiton_server(t *testing.T) { } func Test_can_delete_an_authorizaiton_server(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) as := okta.AuthorizationServer{ Name: "Sample Authorizaiton Server - Golang", @@ -141,7 +145,8 @@ func Test_can_delete_an_authorizaiton_server(t *testing.T) { } func Test_can_list_authorizaiton_servers(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) as := okta.AuthorizationServer{ Name: "Sample Authorizaiton Server - Golang", @@ -170,7 +175,8 @@ func Test_can_list_authorizaiton_servers(t *testing.T) { } func Test_can_activate_an_authorizaiton_server(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) as := okta.AuthorizationServer{ Name: "Sample Authorizaiton Server - Golang", diff --git a/tests/integration/event_hooks_test.go b/tests/integration/event_hooks_test.go index 96997ab9c..405820733 100644 --- a/tests/integration/event_hooks_test.go +++ b/tests/integration/event_hooks_test.go @@ -29,7 +29,8 @@ import ( ) func Test_create_an_event_hook(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) eventHookRequest := createEventHookRequestObject("Create an event hook") @@ -48,7 +49,8 @@ func Test_create_an_event_hook(t *testing.T) { } func Test_get_an_event_hook(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) eventHookRequest := createEventHookRequestObject("get an event hook") @@ -73,7 +75,8 @@ func Test_get_an_event_hook(t *testing.T) { } func Test_update_an_event_hook(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) eventHookRequest := createEventHookRequestObject("Create an event hook") @@ -96,7 +99,8 @@ func Test_update_an_event_hook(t *testing.T) { } func Test_deactivate_and_delete_an_event_hook(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) eventHookRequest := createEventHookRequestObject("deactivate and delete an event hook") @@ -124,7 +128,8 @@ func Test_deactivate_and_delete_an_event_hook(t *testing.T) { } func Test_activate_an_event_hook(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) eventHookRequest := createEventHookRequestObject("activate an event hook") @@ -154,7 +159,8 @@ func Test_activate_an_event_hook(t *testing.T) { } func Test_list_event_hooks(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) eventHookRequest := createEventHookRequestObject("List event hooks") @@ -183,7 +189,8 @@ func Test_list_event_hooks(t *testing.T) { } func Test_verify_an_event_hook(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) eventHookRequest := createEventHookRequestObject("Verify an event hook") diff --git a/tests/integration/factor_test.go b/tests/integration/factor_test.go index b58fbb946..96c83163e 100644 --- a/tests/integration/factor_test.go +++ b/tests/integration/factor_test.go @@ -28,7 +28,8 @@ import ( ) func Test_exercise_factor_lifecycle(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) user, _, err := client.User.GetUser(ctx, "john-factor-lifecycle@example.com") if user != nil { diff --git a/tests/integration/feature_test.go b/tests/integration/feature_test.go index 5362bcccb..33f624384 100644 --- a/tests/integration/feature_test.go +++ b/tests/integration/feature_test.go @@ -28,7 +28,8 @@ import ( ) func Test_can_list_all_features_for_organization(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) features, response, err := client.Feature.ListFeatures(ctx) @@ -50,7 +51,8 @@ func Test_can_list_all_features_for_organization(t *testing.T) { } func Test_can_get_a_feature(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) features, _, err := client.Feature.ListFeatures(ctx) require.NoError(t, err, "listing features must not error") @@ -76,7 +78,8 @@ func Test_can_get_a_feature(t *testing.T) { } func Test_can_get_feature_dependencies(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) features, _, err := client.Feature.ListFeatures(ctx) require.NoError(t, err, "listing features must not error") @@ -93,7 +96,8 @@ func Test_can_get_feature_dependencies(t *testing.T) { } func Test_can_get_feature_dependants(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) features, _, err := client.Feature.ListFeatures(ctx) require.NoError(t, err, "listing features must not error") @@ -110,7 +114,8 @@ func Test_can_get_feature_dependants(t *testing.T) { } func Test_can_update_a_feature_lifecycle(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) features, _, err := client.Feature.ListFeatures(ctx) require.NoError(t, err, "listing features must not error") diff --git a/tests/integration/group_test.go b/tests/integration/group_test.go index 0d4915bf0..696c846ff 100644 --- a/tests/integration/group_test.go +++ b/tests/integration/group_test.go @@ -31,7 +31,8 @@ import ( ) func Test_can_get_a_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a new group → POST /api/v1/groups gp := &okta.GroupProfile{ Name: "Get Test Group", @@ -60,7 +61,8 @@ func Test_can_get_a_group(t *testing.T) { } func Test_can_list_groups(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a new group → POST /api/v1/groups gp := &okta.GroupProfile{ Name: "List Test Group", @@ -89,7 +91,8 @@ func Test_can_list_groups(t *testing.T) { } func Test_can_search_for_a_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a new group → POST /api/v1/groups gp := &okta.GroupProfile{ Name: "Search Test Group", @@ -119,7 +122,8 @@ func Test_can_search_for_a_group(t *testing.T) { } func Test_can_update_a_group(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a new group → POST /api/v1/groups gp := &okta.GroupProfile{ Name: "Update Test Group", @@ -148,7 +152,8 @@ func Test_can_update_a_group(t *testing.T) { } func Test_group_user_operations(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a user with credentials → POST /api/v1/users?activate=false p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -211,7 +216,7 @@ func Test_group_user_operations(t *testing.T) { } func Test_group_rule_operations(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO(), okta.WithCache(false)) + ctx, client, err := tests.NewClient(context.TODO(), okta.WithCache(false)) // Create a user with credentials, activated by default → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", diff --git a/tests/integration/request_test.go b/tests/integration/request_test.go index 5f8b39b87..713b1c9d0 100644 --- a/tests/integration/request_test.go +++ b/tests/integration/request_test.go @@ -42,7 +42,8 @@ func Test_private_key_request_contains_bearer_token(t *testing.T) { } func Test_private_key_request_can_create_a_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO(), okta.WithAuthorizationMode("PrivateKey"), okta.WithScopes(([]string{"okta.users.manage"}))) + ctx, client, err := tests.NewClient(context.TODO(), okta.WithAuthorizationMode("PrivateKey"), okta.WithScopes(([]string{"okta.users.manage"}))) + require.NoError(t, err) p := &okta.PasswordCredential{ Value: "Abcd1234", diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index 773c3b1b6..4168bedd5 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -30,7 +30,8 @@ import ( ) func Test_can_get_a_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create user with credentials → POST /api/v1/users?activate=false p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -118,7 +119,8 @@ func Test_can_activate_a_user(t *testing.T) { } func Test_can_update_user_profile(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create user with credentials → POST /api/v1/users?activate=false p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -164,7 +166,8 @@ func Test_can_update_user_profile(t *testing.T) { } func Test_can_suspend_a_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) //Create user with credentials → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -227,7 +230,8 @@ func Test_can_suspend_a_user(t *testing.T) { } func Test_can_change_users_password(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create user with credentials → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -286,7 +290,8 @@ func Test_can_change_users_password(t *testing.T) { } func Test_can_get_reset_password_link_for_user(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create user with credentials → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -330,7 +335,8 @@ func Test_can_get_reset_password_link_for_user(t *testing.T) { } func Test_can_expire_a_users_password_and_get_a_temp_one(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a user with credentials, activated by default → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -374,7 +380,8 @@ func Test_can_expire_a_users_password_and_get_a_temp_one(t *testing.T) { } func Test_can_change_user_recovery_question(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a user with credentials, activated by default → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -446,7 +453,7 @@ func Test_can_change_user_recovery_question(t *testing.T) { } func Test_can_assign_a_user_to_a_role(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO(), okta.WithCache(false)) + ctx, client, err := tests.NewClient(context.TODO(), okta.WithCache(false)) // Create a user with credentials, activated by default → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -518,7 +525,8 @@ func Test_can_assign_a_user_to_a_role(t *testing.T) { } func Test_user_group_target_role(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) // Create a user with credentials, activated by default → POST /api/v1/users?activate=true p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -602,7 +610,8 @@ func Test_user_group_target_role(t *testing.T) { } func Test_can_get_user_with_cache_enabled(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) p := &okta.PasswordCredential{ Value: "Abcd1234", @@ -641,7 +650,7 @@ func Test_can_get_user_with_cache_enabled(t *testing.T) { } func Test_can_paginate_across_users(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO(), okta.WithCache(false)) + ctx, client, err := tests.NewClient(context.TODO(), okta.WithCache(false)) p := &okta.PasswordCredential{ Value: "Abcd1234", diff --git a/tests/integration/user_type_test.go b/tests/integration/user_type_test.go index 3085785dd..04167edc4 100644 --- a/tests/integration/user_type_test.go +++ b/tests/integration/user_type_test.go @@ -28,7 +28,8 @@ import ( ) func Test_can_create_user_type(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) ut := okta.UserType{ Description: "My Custom User Type", @@ -48,7 +49,8 @@ func Test_can_create_user_type(t *testing.T) { } func Test_can_list_user_types(t *testing.T) { - ctx, client, _ := tests.NewClient(context.TODO()) + ctx, client, err := tests.NewClient(context.TODO()) + require.NoError(t, err) userTypes, response, err := client.UserType.ListUserTypes(ctx) require.NoError(t, err, "creating a user type should not error") From 2a649e85978d38d79aca6af944eceab1158481a7 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Tue, 10 Nov 2020 15:36:55 +0200 Subject: [PATCH 12/14] Added post-sweep, removed redundant code --- okta/requestExecutor.go | 11 +---------- tests/integration/main_test.go | 4 ++++ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/okta/requestExecutor.go b/okta/requestExecutor.go index 949f38780..918032bb5 100644 --- a/okta/requestExecutor.go +++ b/okta/requestExecutor.go @@ -255,7 +255,6 @@ func (re *RequestExecutor) Do(ctx context.Context, req *http.Request, v interfac type oktaBackoff struct { retryCount, maxRetries int32 - startTime int64 backoffDuration time.Duration ctx context.Context err error @@ -283,10 +282,6 @@ func (re *RequestExecutor) doWithRetries(ctx context.Context, req *http.Request) resp *http.Response err error ) - if req.Body != nil { - bodyBytes, _ := ioutil.ReadAll(req.Body) - req.Body = ioutil.NopCloser(bytes.NewBuffer(bodyBytes)) - } if re.config.Okta.Client.RequestTimeout > 0 { var cancel context.CancelFunc ctx, cancel = context.WithTimeout(ctx, time.Second*time.Duration(re.config.Okta.Client.RequestTimeout)) @@ -295,7 +290,6 @@ func (re *RequestExecutor) doWithRetries(ctx context.Context, req *http.Request) bOff := &oktaBackoff{ ctx: ctx, maxRetries: re.config.Okta.Client.RateLimit.MaxRetries, - startTime: time.Now().Unix(), } operation := func() error { resp, err = re.httpClient.Do(req.WithContext(ctx)) @@ -333,10 +327,7 @@ func tooManyRequests(resp *http.Response) bool { func tryDrainBody(body io.ReadCloser) error { defer body.Close() _, err := io.Copy(ioutil.Discard, io.LimitReader(body, 4096)) - if err != nil { - return err - } - return nil + return err } func Get429BackoffTime(resp *http.Response) (int64, error) { diff --git a/tests/integration/main_test.go b/tests/integration/main_test.go index a64122f40..01891f0d9 100644 --- a/tests/integration/main_test.go +++ b/tests/integration/main_test.go @@ -18,6 +18,10 @@ func TestMain(m *testing.M) { log.Fatalf("failed to clean up organization before integration tests: %v", err) } exitVal := m.Run() + err = sweep() + if err != nil { + log.Fatalf("failed to clean up organization after integration tests: %v", err) + } os.Exit(exitVal) } From c1913476cdc2fead2c9ed7a140889b78376dd802 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Wed, 11 Nov 2020 10:49:11 +0200 Subject: [PATCH 13/14] Changed query parameter --- okta/application.go | 2 +- tests/integration/admin_roles_test.go | 10 +++++----- tests/integration/application_test.go | 2 +- tests/integration/factor_test.go | 2 +- tests/integration/group_test.go | 4 ++-- tests/integration/main_test.go | 2 +- tests/integration/request_test.go | 2 +- tests/integration/user_test.go | 26 +++++++++++++------------- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/okta/application.go b/okta/application.go index 71d40f8db..d5732c0f2 100644 --- a/okta/application.go +++ b/okta/application.go @@ -704,7 +704,7 @@ func (m *ApplicationResource) ListApplicationUsers(ctx context.Context, appId st return appUser, resp, nil } -// Assigns an user to an application with [credentials](#application-user-credentials-object) and an app-specific [profile](#application-user-profile-object). Profile mappings defined for the application are first applied before applying any profile properties specified in the request. +// Assigns a user to an application with [credentials](#application-user-credentials-object) and an app-specific [profile](#application-user-profile-object). Profile mappings defined for the application are first applied before applying any profile properties specified in the request. func (m *ApplicationResource) AssignUserToApplication(ctx context.Context, appId string, body AppUser) (*AppUser, *Response, error) { url := fmt.Sprintf("/api/v1/apps/%v/users", appId) diff --git a/tests/integration/admin_roles_test.go b/tests/integration/admin_roles_test.go index 1907fe6e1..f4f98fa92 100644 --- a/tests/integration/admin_roles_test.go +++ b/tests/integration/admin_roles_test.go @@ -47,7 +47,7 @@ func Test_can_add_an_admin_role_to_user(t *testing.T) { } user, _, err := client.User.CreateUser(ctx, *u, nil) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") role := okta.AssignRoleRequest{ Type: "SUPER_ADMIN", } @@ -124,7 +124,7 @@ func Test_can_remove_an_admin_role_to_user(t *testing.T) { } user, _, err := client.User.CreateUser(ctx, *u, nil) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") role := okta.AssignRoleRequest{ Type: "SUPER_ADMIN", } @@ -197,7 +197,7 @@ func Test_can_list_roles_assigned_to_a_user(t *testing.T) { } user, _, err := client.User.CreateUser(ctx, *u, nil) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") role := okta.AssignRoleRequest{ Type: "SUPER_ADMIN", @@ -292,7 +292,7 @@ func Test_can_add_group_targets_for_the_group_administrator_role_given_to_a_user } user, _, err := client.User.CreateUser(ctx, *u, nil) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") role := okta.AssignRoleRequest{ Type: "USER_ADMIN", @@ -376,7 +376,7 @@ func Test_can_list_group_targets_for_the_group_administrator_role_given_to_a_use } user, _, err := client.User.CreateUser(ctx, *u, nil) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") role := okta.AssignRoleRequest{ Type: "USER_ADMIN", diff --git a/tests/integration/application_test.go b/tests/integration/application_test.go index 74c160281..2a63a0a49 100644 --- a/tests/integration/application_test.go +++ b/tests/integration/application_test.go @@ -314,7 +314,7 @@ func Test_can_add_and_remove_application_users(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") appUserPasswordCredentials := okta.NewAppUserPasswordCredential() appUserPasswordCredentials.Value = "abcd1234" diff --git a/tests/integration/factor_test.go b/tests/integration/factor_test.go index 96c83163e..3f970b0d9 100644 --- a/tests/integration/factor_test.go +++ b/tests/integration/factor_test.go @@ -55,7 +55,7 @@ func Test_exercise_factor_lifecycle(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) user, _, err = client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") allowedFactors, _, _ := client.UserFactor.ListSupportedFactors(ctx, user.Id) continueTesting := false diff --git a/tests/integration/group_test.go b/tests/integration/group_test.go index 696c846ff..2f14793c2 100644 --- a/tests/integration/group_test.go +++ b/tests/integration/group_test.go @@ -173,7 +173,7 @@ func Test_group_user_operations(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") assert.IsType(t, &okta.User{}, user) // Create a new group → POST /api/v1/groups @@ -236,7 +236,7 @@ func Test_group_rule_operations(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") assert.IsType(t, &okta.User{}, user) // Create a new group → POST /api/v1/groups diff --git a/tests/integration/main_test.go b/tests/integration/main_test.go index 01891f0d9..77e959538 100644 --- a/tests/integration/main_test.go +++ b/tests/integration/main_test.go @@ -35,7 +35,7 @@ func sweep() error { } func sweepUsers(ctx context.Context, client *okta.Client) error { - users, _, err := client.User.ListUsers(ctx, &query.Params{Q: "admin_role"}) + users, _, err := client.User.ListUsers(ctx, &query.Params{Q:"john-"}) if err != nil { return err } diff --git a/tests/integration/request_test.go b/tests/integration/request_test.go index 713b1c9d0..6b9b723cd 100644 --- a/tests/integration/request_test.go +++ b/tests/integration/request_test.go @@ -64,7 +64,7 @@ func Test_private_key_request_can_create_a_user(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") assert.NotEmpty(t, user.Id, "appears the user was not created") tempProfile := *user.Profile assert.Equal(t, "john-private-key@example.com", tempProfile["email"], "did not get the correct user") diff --git a/tests/integration/user_test.go b/tests/integration/user_test.go index 4168bedd5..3cee61dd6 100644 --- a/tests/integration/user_test.go +++ b/tests/integration/user_test.go @@ -51,7 +51,7 @@ func Test_can_get_a_user(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Get the user by ID → GET /api/v1/users/{{userId}} ubid, _, err := client.User.GetUser(ctx, user.Id) @@ -97,7 +97,7 @@ func Test_can_activate_a_user(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Activate the user → POST /api/v1/users/{{userId}}/lifecycle/activate?sendEmail=false token, _, err := client.User.ActivateUser(ctx, user.Id, query.NewQueryParams(query.WithSendEmail(false))) @@ -140,7 +140,7 @@ func Test_can_update_user_profile(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(false)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Update the user's profile by adding a nickname → PUT /api/v1/users/{{userId}} newProfile := *user.Profile @@ -187,7 +187,7 @@ func Test_can_suspend_a_user(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Suspend the user → POST /api/v1/users/{{userId}}/lifecycle/suspend _, err = client.User.SuspendUser(ctx, user.Id) @@ -251,7 +251,7 @@ func Test_can_change_users_password(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") //Sleep 1 second to make sure time has passed for password chagned timestamps time.Sleep(1 * time.Second) @@ -311,7 +311,7 @@ func Test_can_get_reset_password_link_for_user(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Reset the user password → POST /api/v1/users/{{userId}}/lifecycle/reset_password?sendEmail=false rpt, _, err := client.User.ResetPassword(ctx, user.Id, query.NewQueryParams(query.WithSendEmail(false))) @@ -356,7 +356,7 @@ func Test_can_expire_a_users_password_and_get_a_temp_one(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Expire the user password → POST /api/v1/users/{{userId}}/lifecycle/expire_password?tempPassword=true ep, _, err := client.User.ExpirePasswordAndGetTemporaryPassword(ctx, user.Id) @@ -401,7 +401,7 @@ func Test_can_change_user_recovery_question(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Update the user's recovery question → POST /api/v1/users/{{userId}}/credentials/change_recovery_question nucp := &okta.PasswordCredential{ @@ -473,7 +473,7 @@ func Test_can_assign_a_user_to_a_role(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Add 'USER_ADMIN' role to the user → POST /api/v1/users/{{userId}}/roles (Body → { type: 'USER_ADMIN' }) arr := &okta.AssignRoleRequest{ @@ -546,7 +546,7 @@ func Test_user_group_target_role(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) user, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") // Create a new group → POST /api/v1/groups gp := &okta.GroupProfile{ @@ -631,7 +631,7 @@ func Test_can_get_user_with_cache_enabled(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) createdUser, _, err := client.User.CreateUser(ctx, *u, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") for i := 0; i < 50; i++ { user, resp, err := client.User.GetUser(ctx, "john-test-cache@example.com") @@ -679,9 +679,9 @@ func Test_can_paginate_across_users(t *testing.T) { qp := query.NewQueryParams(query.WithActivate(true)) createdUser1, _, err := client.User.CreateUser(ctx, *u1, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") createdUser2, _, err := client.User.CreateUser(ctx, *u2, qp) - require.NoError(t, err, "Creating an user should not error") + require.NoError(t, err, "Creating a new user should not error") query := query.NewQueryParams(query.WithLimit(1)) user1, resp, err := client.User.ListUsers(ctx, query) From cb34c85d1de0ef1091c9f11aaa0175014c5a6802 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Wed, 11 Nov 2020 19:08:28 +0200 Subject: [PATCH 14/14] Fixed typo in role test --- tests/integration/admin_roles_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/admin_roles_test.go b/tests/integration/admin_roles_test.go index f4f98fa92..105a9b2e0 100644 --- a/tests/integration/admin_roles_test.go +++ b/tests/integration/admin_roles_test.go @@ -203,12 +203,12 @@ func Test_can_list_roles_assigned_to_a_user(t *testing.T) { Type: "SUPER_ADMIN", } - _, response, err := client.User.AssignRoleToUser(ctx, user.Id, role, nil) + _, _, err = client.User.AssignRoleToUser(ctx, user.Id, role, nil) require.NoError(t, err, "adding role to user must not error") roles, response, err := client.User.ListAssignedRolesForUser(ctx, user.Id, nil) - require.NoError(t, err, "listing adnimistrator roles must not error") + require.NoError(t, err, "listing administrator roles must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, []*okta.Role{}, roles, "did not return `[]*okta.Role` as first variable") assert.Equal(t, "GET", response.Response.Request.Method, "did not make a get request") @@ -251,7 +251,7 @@ func Test_can_list_roles_assigned_to_a_group(t *testing.T) { roles, response, err := client.Group.ListGroupAssignedRoles(ctx, group.Id, nil) - require.NoError(t, err, "listing adnimistrator roles must not error") + require.NoError(t, err, "listing administrator roles must not error") require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") require.IsType(t, []*okta.Role{}, roles, "did not return `[]*okta.Role` as first variable") assert.Equal(t, "GET", response.Response.Request.Method, "did not make a get request")