Skip to content

Commit

Permalink
Improve HasPermission call by using org context introspect
Browse files Browse the repository at this point in the history
  • Loading branch information
loafoe committed May 14, 2022
1 parent 8ea5d9b commit 68e399c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions iam/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (c *Client) HasScopes(scopes ...string) bool {

// HasPermissions returns true if all permissions are there for the client
func (c *Client) HasPermissions(orgID string, permissions ...string) bool {
introspect, _, err := c.Introspect()
introspect, _, err := c.Introspect(WithOrgContext(orgID))
if err != nil {
return false
}
Expand All @@ -315,7 +315,7 @@ func (c *Client) HasPermissions(orgID string, permissions ...string) bool {
}
}
if !found {
// Permission is missing to return false
// Permission is missing so return false
return false
}
}
Expand Down
4 changes: 2 additions & 2 deletions iam/introspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestIntrospectWithOrgContext(t *testing.T) {

orgContext := r.URL.Query().Get("org_ctx")

if orgContext != "" {
if orgContext != "" && orgContext != "bogus" {
orgID = orgContext
}

Expand Down Expand Up @@ -217,6 +217,6 @@ func TestIntrospectWithOrgContext(t *testing.T) {
}

assert.True(t, client.HasPermissions(orgID, "SERVICE.SCOPE", "ORGANIZATION.MFA"))
assert.False(t, client.HasPermissions("bogus", "SERVICE.SCOPE"))
assert.Equal(t, 1, len(introspectResponse.Organizations.OrganizationList))
assert.False(t, client.HasPermissions("bogus", "SERVICE.SCOPE"))
}
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package internal

const (
LibraryVersion = "0.63.2"
LibraryVersion = "0.63.3"
)

0 comments on commit 68e399c

Please sign in to comment.