-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated m2m authenticator to use "all-apis" scope. Added a new constructor function for m2m authenticator that allows client to pass in additional scopes. Signed-off-by: Raymond Cypher <raymond.cypher@databricks.com>
- Loading branch information
Showing
5 changed files
with
65 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package m2m | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestM2MScopes(t *testing.T) { | ||
t.Run("default should be [all-apis]", func(t *testing.T) { | ||
auth := NewAuthenticator("id", "secret", "staging.cloud.company.com").(*authClient) | ||
assert.Equal(t, "id", auth.clientID) | ||
assert.Equal(t, "secret", auth.clientSecret) | ||
assert.Equal(t, []string{"all-apis"}, auth.scopes) | ||
|
||
auth = NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", nil).(*authClient) | ||
assert.Equal(t, "id", auth.clientID) | ||
assert.Equal(t, "secret", auth.clientSecret) | ||
assert.Equal(t, []string{"all-apis"}, auth.scopes) | ||
|
||
auth = NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", []string{}).(*authClient) | ||
assert.Equal(t, "id", auth.clientID) | ||
assert.Equal(t, "secret", auth.clientSecret) | ||
assert.Equal(t, []string{"all-apis"}, auth.scopes) | ||
}) | ||
|
||
t.Run("should add all-apis to passed scopes", func(t *testing.T) { | ||
auth := NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", []string{"my-scope"}).(*authClient) | ||
assert.Equal(t, "id", auth.clientID) | ||
assert.Equal(t, "secret", auth.clientSecret) | ||
assert.Equal(t, []string{"my-scope", "all-apis"}, auth.scopes) | ||
}) | ||
|
||
t.Run("should not add all-apis if already in passed scopes", func(t *testing.T) { | ||
auth := NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", []string{"all-apis", "my-scope"}).(*authClient) | ||
assert.Equal(t, "id", auth.clientID) | ||
assert.Equal(t, "secret", auth.clientSecret) | ||
assert.Equal(t, []string{"all-apis", "my-scope"}, auth.scopes) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters