|
| 1 | +package m2m |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestM2MScopes(t *testing.T) { |
| 10 | + t.Run("default should be [all-apis]", func(t *testing.T) { |
| 11 | + auth := NewAuthenticator("id", "secret", "staging.cloud.company.com").(*authClient) |
| 12 | + assert.Equal(t, "id", auth.clientID) |
| 13 | + assert.Equal(t, "secret", auth.clientSecret) |
| 14 | + assert.Equal(t, []string{"all-apis"}, auth.scopes) |
| 15 | + |
| 16 | + auth = NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", nil).(*authClient) |
| 17 | + assert.Equal(t, "id", auth.clientID) |
| 18 | + assert.Equal(t, "secret", auth.clientSecret) |
| 19 | + assert.Equal(t, []string{"all-apis"}, auth.scopes) |
| 20 | + |
| 21 | + auth = NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", []string{}).(*authClient) |
| 22 | + assert.Equal(t, "id", auth.clientID) |
| 23 | + assert.Equal(t, "secret", auth.clientSecret) |
| 24 | + assert.Equal(t, []string{"all-apis"}, auth.scopes) |
| 25 | + }) |
| 26 | + |
| 27 | + t.Run("should add all-apis to passed scopes", func(t *testing.T) { |
| 28 | + auth := NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", []string{"my-scope"}).(*authClient) |
| 29 | + assert.Equal(t, "id", auth.clientID) |
| 30 | + assert.Equal(t, "secret", auth.clientSecret) |
| 31 | + assert.Equal(t, []string{"my-scope", "all-apis"}, auth.scopes) |
| 32 | + }) |
| 33 | + |
| 34 | + t.Run("should not add all-apis if already in passed scopes", func(t *testing.T) { |
| 35 | + auth := NewAuthenticatorWithScopes("id", "secret", "staging.cloud.company.com", []string{"all-apis", "my-scope"}).(*authClient) |
| 36 | + assert.Equal(t, "id", auth.clientID) |
| 37 | + assert.Equal(t, "secret", auth.clientSecret) |
| 38 | + assert.Equal(t, []string{"all-apis", "my-scope"}, auth.scopes) |
| 39 | + }) |
| 40 | +} |
0 commit comments