Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Write better test for group assignment and fix user 404 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumew committed Oct 31, 2019
1 parent a062ada commit acedf59
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
22 changes: 22 additions & 0 deletions examples/okta_app_group_assignment/updated.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
resource okta_app_oauth test {
label = "testAcc_replace_with_uuid"
type = "web"
grant_types = ["implicit", "authorization_code"]
redirect_uris = ["http://d.com/"]
response_types = ["code", "token", "id_token"]
issuer_mode = "ORG_URL"

lifecycle {
ignore_changes = ["users", "groups"]
}
}

resource okta_group test {
name = "testAcc_replace_with_uuid"
}

resource okta_app_group_assignment test {
app_id = "${okta_app_oauth.test.id}"
group_id = "${okta_group.test.id}"
priority = 1
}
8 changes: 6 additions & 2 deletions okta/resource_okta_app_group_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ func resourceAppGroupAssignment() *schema.Resource {

func resourceAppGroupAssignmentExists(d *schema.ResourceData, m interface{}) (bool, error) {
client := getOktaClientFromMetadata(m)
g, _, err := client.Application.GetApplicationGroupAssignment(
_, resp, err := client.Application.GetApplicationGroupAssignment(
d.Get("app_id").(string),
d.Get("group_id").(string),
nil,
)

return g != nil, err
if is404(resp.StatusCode) {
return false, nil
}

return err == nil, err
}

func getAppGroupAssignment(d *schema.ResourceData) okta.ApplicationGroupAssignment {
Expand Down
10 changes: 10 additions & 0 deletions okta/resource_okta_app_group_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func TestAccAppGroupAssignment_crud(t *testing.T) {
resourceName := fmt.Sprintf("%s.test", appGroupAssignment)
mgr := newFixtureManager(appGroupAssignment)
config := mgr.GetFixtures("basic.tf", ri, t)
updatedConfig := mgr.GetFixtures("updated.tf", ri, t)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -29,6 +30,15 @@ func TestAccAppGroupAssignment_crud(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "profile", "{}"),
),
},
{
Config: updatedConfig,
Check: resource.ComposeTestCheckFunc(
ensureAppGroupAssignmentExists(resourceName),
resource.TestCheckResourceAttrSet(resourceName, "app_id"),
resource.TestCheckResourceAttrSet(resourceName, "group_id"),
resource.TestCheckResourceAttr(resourceName, "profile", "{}"),
),
},
},
})
}
Expand Down
9 changes: 2 additions & 7 deletions okta/resource_okta_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"log"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -469,13 +468,9 @@ func resourceUserExists(d *schema.ResourceData, m interface{}) (bool, error) {

_, resp, err := client.User.GetUser(d.Id())

if err != nil {
return false, fmt.Errorf("[ERROR] Error Getting User from Okta: %v", err)
}

if strings.Contains(resp.Response.Status, "404") {
if is404(resp.StatusCode) {
return false, nil
}

return true, nil
return err == nil, err
}

0 comments on commit acedf59

Please sign in to comment.