From 1e965b6a864d6a7736208eae37327c5f3d225f75 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Thu, 12 Nov 2020 22:21:32 +0200 Subject: [PATCH 1/7] Removed cance function for context --- okta/requestExecutor.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/okta/requestExecutor.go b/okta/requestExecutor.go index 918032bb5..525d17250 100644 --- a/okta/requestExecutor.go +++ b/okta/requestExecutor.go @@ -283,9 +283,7 @@ func (re *RequestExecutor) doWithRetries(ctx context.Context, req *http.Request) err error ) 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() + ctx, _ = context.WithTimeout(ctx, time.Second*time.Duration(re.config.Okta.Client.RequestTimeout)) } bOff := &oktaBackoff{ ctx: ctx, From 038b33dc1123938394d2b8550ca7c53b25a46e8e Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Thu, 12 Nov 2020 22:42:33 +0200 Subject: [PATCH 2/7] Added connection timeout --- okta/okta.go | 2 +- okta/requestExecutor.go | 5 ++++- openapi/generator/templates/okta.go.hbs | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/okta/okta.go b/okta/okta.go index e02453440..359da02c5 100644 --- a/okta/okta.go +++ b/okta/okta.go @@ -142,7 +142,7 @@ func setConfigDefaults(c *config) { var conf []ConfigSetter conf = append(conf, - WithConnectionTimeout(30), + WithConnectionTimeout(60), WithCache(true), WithCacheTtl(300), WithCacheTti(300), diff --git a/okta/requestExecutor.go b/okta/requestExecutor.go index 525d17250..01540f3aa 100644 --- a/okta/requestExecutor.go +++ b/okta/requestExecutor.go @@ -81,7 +81,10 @@ func NewRequestExecutor(httpClient *http.Client, cache cache.Cache, config *conf tr := &http.Transport{ IdleConnTimeout: 30 * time.Second, } - re.httpClient = &http.Client{Transport: tr} + re.httpClient = &http.Client{ + Transport: tr, + Timeout: time.Second * time.Duration(re.config.Okta.Client.ConnectionTimeout), + } } return &re diff --git a/openapi/generator/templates/okta.go.hbs b/openapi/generator/templates/okta.go.hbs index 0ee1f75cd..4451d1795 100644 --- a/openapi/generator/templates/okta.go.hbs +++ b/openapi/generator/templates/okta.go.hbs @@ -96,7 +96,7 @@ func setConfigDefaults(c *config) { var conf []ConfigSetter conf = append(conf, - WithConnectionTimeout(30), + WithConnectionTimeout(60), WithCache(true), WithCacheTtl(300), WithCacheTti(300), From c9266e823e751d3a193fabbc293f78a7fbd84db9 Mon Sep 17 00:00:00 2001 From: Brian Retterer Date: Fri, 13 Nov 2020 09:44:27 -0500 Subject: [PATCH 3/7] Update version number --- CHANGELOG.md | 6 ++++++ okta/okta.go | 2 +- openapi/generator/templates/okta.go.hbs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb9890eb..ea6b41361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ # Changelog Running changelog of releases since `2.0.0-rc.4` +## v2.2.1 +### Bug Fixes +- Update default connection Timeout to `60` seconds (#185) +- Http Client now uses `Timeout` setting for connection timeout (#185) +- SDK no longer cancels context (#185) + ## v2.2.0 ### New Structs - `OpenIdConnectApplicationSettingsClientKeys` diff --git a/okta/okta.go b/okta/okta.go index 359da02c5..a6ea9d918 100644 --- a/okta/okta.go +++ b/okta/okta.go @@ -32,7 +32,7 @@ import ( "gopkg.in/yaml.v3" ) -const Version = "2.2.0" +const Version = "2.2.1" type Client struct { config *config diff --git a/openapi/generator/templates/okta.go.hbs b/openapi/generator/templates/okta.go.hbs index 4451d1795..b2326a139 100644 --- a/openapi/generator/templates/okta.go.hbs +++ b/openapi/generator/templates/okta.go.hbs @@ -16,7 +16,7 @@ import ( "gopkg.in/yaml.v3" ) -const Version = "2.2.0" +const Version = "2.2.1" type Client struct { config *config From f1b42c77a7b7ff45014176cce325d5881b0d04a7 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Fri, 13 Nov 2020 21:08:54 +0200 Subject: [PATCH 4/7] Added user pre delete --- tests/integration/request_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/integration/request_test.go b/tests/integration/request_test.go index 6b9b723cd..9a4984e52 100644 --- a/tests/integration/request_test.go +++ b/tests/integration/request_test.go @@ -45,6 +45,14 @@ func Test_private_key_request_can_create_a_user(t *testing.T) { ctx, client, err := tests.NewClient(context.TODO(), okta.WithAuthorizationMode("PrivateKey"), okta.WithScopes(([]string{"okta.users.manage"}))) require.NoError(t, err) + users, _, err := client.User.ListUsers(ctx, &query.Params{Q:"john-private-key@example.com"}) + require.NoError(t, err, "listing user should not fail") + for _, u := range users { + if err := ensureUserDelete(ctx, client, u.Id, u.Status); err != nil { + require.NoError(t, err, "removing user should fail") + } + } + p := &okta.PasswordCredential{ Value: "Abcd1234", } @@ -64,7 +72,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 a new 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") From a3a4495e1e644ad1ccf919dec1480a84cb8e3ecd Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sat, 14 Nov 2020 12:25:14 +0200 Subject: [PATCH 5/7] Don't run jobs in parallel to avoid integration tests fail --- .travis.yml | 20 ++++++++++++-------- Makefile | 1 - tests/integration/request_test.go | 10 +--------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/.travis.yml b/.travis.yml index 45c5378d3..a24c155cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,14 @@ language: go -go: - - 1.15.x - - tip - -script: - - go mod download - - make test - +jobs: + include: + - stage: test_go_1.13 + go: 1.13.x + script: + - go mod download + - make test + - stage: test_go_tip + go: tip + script: + - go mod download + - make test diff --git a/Makefile b/Makefile index 06f1b153f..d5e2b9881 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,6 @@ pull-spec: cp spec-raw/dist/spec.json openapi/spec.json rm -fr spec-raw - test: make test:all diff --git a/tests/integration/request_test.go b/tests/integration/request_test.go index 9a4984e52..6b9b723cd 100644 --- a/tests/integration/request_test.go +++ b/tests/integration/request_test.go @@ -45,14 +45,6 @@ func Test_private_key_request_can_create_a_user(t *testing.T) { ctx, client, err := tests.NewClient(context.TODO(), okta.WithAuthorizationMode("PrivateKey"), okta.WithScopes(([]string{"okta.users.manage"}))) require.NoError(t, err) - users, _, err := client.User.ListUsers(ctx, &query.Params{Q:"john-private-key@example.com"}) - require.NoError(t, err, "listing user should not fail") - for _, u := range users { - if err := ensureUserDelete(ctx, client, u.Id, u.Status); err != nil { - require.NoError(t, err, "removing user should fail") - } - } - p := &okta.PasswordCredential{ Value: "Abcd1234", } @@ -72,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 a new 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") From c185e4a2fb6385ba6132f3a2884e24e02792a0ff Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sat, 14 Nov 2020 12:37:05 +0200 Subject: [PATCH 6/7] Added group sweeper --- tests/integration/main_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/integration/main_test.go b/tests/integration/main_test.go index 77e959538..710d11402 100644 --- a/tests/integration/main_test.go +++ b/tests/integration/main_test.go @@ -31,11 +31,29 @@ func sweep() error { if err != nil { return err } - return sweepUsers(ctx, client) + err = sweepUsers(ctx, client) + if err != nil { + return err + } + return sweepGroups(ctx, client) +} + +func sweepGroups(ctx context.Context, client *okta.Client) error { + groups, _, err := client.Group.ListGroups(ctx, &query.Params{Q: "Group-Member-Rule"}) + if err != nil { + return err + } + for _, g := range groups { + _, err = client.Group.DeleteGroup(ctx, g.Id) + if err != nil { + return err + } + } + return nil } func sweepUsers(ctx context.Context, client *okta.Client) error { - users, _, err := client.User.ListUsers(ctx, &query.Params{Q:"john-"}) + users, _, err := client.User.ListUsers(ctx, &query.Params{Q: "john-"}) if err != nil { return err } From 5e4721d18c80c9ce162646566339f9393422dda3 Mon Sep 17 00:00:00 2001 From: Bogdan Prodan Date: Sat, 14 Nov 2020 13:13:35 +0200 Subject: [PATCH 7/7] Added group rules sweeper --- tests/integration/main_test.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/integration/main_test.go b/tests/integration/main_test.go index 710d11402..3eae89f85 100644 --- a/tests/integration/main_test.go +++ b/tests/integration/main_test.go @@ -35,7 +35,11 @@ func sweep() error { if err != nil { return err } - return sweepGroups(ctx, client) + err = sweepGroups(ctx, client) + if err != nil { + return err + } + return sweepGroupRules(ctx, client) } func sweepGroups(ctx context.Context, client *okta.Client) error { @@ -52,6 +56,26 @@ func sweepGroups(ctx context.Context, client *okta.Client) error { return nil } +func sweepGroupRules(ctx context.Context, client *okta.Client) error { + groupRules, _, err := client.Group.ListGroupRules(ctx, &query.Params{Q: "Test"}) + if err != nil { + return err + } + for _, g := range groupRules { + if g.Status == "ACTIVE" { + _, err = client.Group.DeactivateGroupRule(ctx, g.Id) + if err != nil { + return err + } + } + _, err = client.Group.DeleteGroupRule(ctx, g.Id) + if err != nil { + return err + } + } + return nil +} + func sweepUsers(ctx context.Context, client *okta.Client) error { users, _, err := client.User.ListUsers(ctx, &query.Params{Q: "john-"}) if err != nil {