Skip to content

Commit

Permalink
Merge pull request #1721 from okta/guard_config_panic
Browse files Browse the repository at this point in the history
Guard config panic
  • Loading branch information
MikeMondragon-okta authored Sep 13, 2023
2 parents 918083e + beee82b commit 47d7e50
Show file tree
Hide file tree
Showing 12 changed files with 2,239 additions and 411 deletions.
2 changes: 1 addition & 1 deletion examples/okta_group/okta_group.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "okta_group" "test" {
name = "testAcc"
name = "testAcc_replace_with_uuid"
description = "testing, testing"
}
2 changes: 1 addition & 1 deletion examples/okta_group/okta_group_updated.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "okta_group" "test" {
name = "testAccDifferent"
name = "testAcc_Different_replace_with_uuid"
description = "testing, testing"
}
9 changes: 9 additions & 0 deletions okta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"net/url"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -367,6 +368,10 @@ func oktaSDKClient(c *Config) (client *sdk.Client, err error) {
} else {
orgUrl = fmt.Sprintf("https://%v.%v", c.orgName, c.domain)
}
_, err = url.Parse(orgUrl)
if err != nil {
return nil, fmt.Errorf("malformed Okta API URL (org_name+base_url value, or http_proxy value): %+v", err)
}

setters := []sdk.ConfigSetter{
sdk.WithOrgUrl(orgUrl),
Expand Down Expand Up @@ -459,6 +464,10 @@ func oktaV3SDKClient(c *Config) (client *okta.APIClient, err error) {
} else {
orgUrl = fmt.Sprintf("https://%v.%v", c.orgName, c.domain)
}
_, err = url.Parse(orgUrl)
if err != nil {
return nil, fmt.Errorf("malformed Okta API URL (org_name+base_url value, or http_proxy value): %+v", err)
}

setters := []okta.ConfigSetter{
okta.WithOrgUrl(orgUrl),
Expand Down
6 changes: 3 additions & 3 deletions okta/data_source_okta_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func TestAccDataSourceOktaGroup_read(t *testing.T) {
configInvalid := mgr.GetFixtures("datasource_not_found.tf", t)

oktaResourceTest(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProviderFactories: testAccProvidersFactories,
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProtoV5ProviderFactories: testAccMergeProvidersFactories,
Steps: []resource.TestStep{
{
Config: groupCreate,
Expand Down
12 changes: 8 additions & 4 deletions okta/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"path"
"path/filepath"
"reflect"
"regexp"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -148,10 +149,10 @@ func accPreCheck() error {
token := os.Getenv("OKTA_API_TOKEN")
clientID := os.Getenv("OKTA_API_CLIENT_ID")
privateKey := os.Getenv("OKTA_API_PRIVATE_KEY")
privateKeyId := os.Getenv("OKTA_API_PRIVATE_KEY_IE")
privateKeyID := os.Getenv("OKTA_API_PRIVATE_KEY_ID")
scopes := os.Getenv("OKTA_API_SCOPES")
if token == "" && (clientID == "" || scopes == "" || privateKey == "" || privateKeyId == "") {
return errors.New("either OKTA_API_TOKEN or OKTA_API_CLIENT_ID, OKTA_API_SCOPES and OKTA_API_PRIVATE_KEY must be set for acceptance tests")
if token == "" && (clientID == "" || scopes == "" || privateKey == "" || privateKeyID == "") {
return errors.New("either OKTA_API_TOKEN or (OKTA_API_CLIENT_ID and OKTA_API_SCOPES and OKTA_API_PRIVATE_KEY and OKTA_API_PRIVATE_KEY_ID) must be set for acceptance tests")
}
return nil
}
Expand All @@ -163,7 +164,6 @@ func TestProviderValidate(t *testing.T) {
"OKTA_API_CLIENT_ID",
"OKTA_API_PRIVATE_KEY",
"OKTA_API_PRIVATE_KEY_ID",
"OKTA_API_PRIVATE_KEY_IE",
"OKTA_API_SCOPES",
"OKTA_API_TOKEN",
"OKTA_BASE_URL",
Expand Down Expand Up @@ -503,6 +503,10 @@ func newVCRRecorder(mgr *vcrManager, transport http.RoundTripper) (rec *recorder
}
}

// scrub client assertions out of token requests
m := regexp.MustCompile("client_assertion=[^&]+")
i.Request.URL = m.ReplaceAllString(i.Request.URL, "client_assertion=abc123")

// replace admin based hostname before regular variations
// %s/example-admin.okta.com/test-admin.dne-okta.com/
i.Request.Host = strings.ReplaceAll(i.Request.Host, orgAdminHostname, vcrAdminHostname)
Expand Down
15 changes: 9 additions & 6 deletions okta/resource_okta_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ func TestAccResourceOktaGroup_crud(t *testing.T) {
mgr := newFixtureManager(group, t.Name())
config := mgr.GetFixtures("okta_group.tf", t)
updatedConfig := mgr.GetFixtures("okta_group_updated.tf", t)
buildResourceName(mgr.Seed)

oktaResourceTest(t, resource.TestCase{
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProviderFactories: testAccProvidersFactories,
CheckDestroy: checkResourceDestroy(group, doesGroupExist),
PreCheck: testAccPreCheck(t),
ErrorCheck: testAccErrorChecks(t),
ProtoV5ProviderFactories: testAccMergeProvidersFactories,
CheckDestroy: checkResourceDestroy(group, doesGroupExist),
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", "testAcc")),
resource.TestCheckResourceAttr(resourceName, "name", buildResourceNameWithPrefix("testAcc", mgr.Seed)),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "name", "testAccDifferent")),
resource.TestCheckResourceAttr(resourceName, "name", buildResourceNameWithPrefix("testAcc_Different", mgr.Seed)),
),
},
},
})
Expand Down
Loading

0 comments on commit 47d7e50

Please sign in to comment.