|
| 1 | +package core |
| 2 | + |
| 3 | +import ( |
| 4 | + "encoding/json" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
| 9 | +) |
| 10 | + |
| 11 | +func TestNewServiceProviderConfig(t *testing.T) { |
| 12 | + t.Run("advertises the schemes the caller declares", func(t *testing.T) { |
| 13 | + scheme := NewOAuthBearerToken().AsPrimary() |
| 14 | + |
| 15 | + config := NewServiceProviderConfig("", scheme) |
| 16 | + |
| 17 | + require.Equal(t, []SchemaURI{SchemaServiceProviderConfig}, config.Schemas) |
| 18 | + require.Equal(t, []*AuthenticationScheme{scheme}, config.AuthenticationSchemes) |
| 19 | + }) |
| 20 | + |
| 21 | + t.Run("identifies itself with resource metadata", func(t *testing.T) { |
| 22 | + baseURL := "http://localhost:9999/scim/v2" |
| 23 | + |
| 24 | + config := NewServiceProviderConfig(baseURL) |
| 25 | + |
| 26 | + require.Equal(t, ResourceTypeServiceProviderConfig, config.Meta.ResourceType) |
| 27 | + require.Equal(t, baseURL+EndpointServiceProviderConfig, config.Meta.Location) |
| 28 | + }) |
| 29 | + |
| 30 | + t.Run("supports none of the optional protocol features", func(t *testing.T) { |
| 31 | + config := NewServiceProviderConfig("") |
| 32 | + |
| 33 | + assert.False(t, config.Patch.Supported) |
| 34 | + assert.False(t, config.Bulk.Supported) |
| 35 | + assert.False(t, config.Filter.Supported) |
| 36 | + assert.False(t, config.ChangePassword.Supported) |
| 37 | + assert.False(t, config.Sort.Supported) |
| 38 | + assert.False(t, config.ETag.Supported) |
| 39 | + }) |
| 40 | + |
| 41 | + t.Run("serializes authenticationSchemes as an array", func(t *testing.T) { |
| 42 | + body, err := json.Marshal(NewServiceProviderConfig("")) |
| 43 | + |
| 44 | + require.NoError(t, err) |
| 45 | + require.Contains(t, string(body), `"authenticationSchemes":[]`) |
| 46 | + }) |
| 47 | +} |
| 48 | + |
| 49 | +func TestAuthenticationScheme(t *testing.T) { |
| 50 | + t.Run("NewOAuthBearerToken", func(t *testing.T) { |
| 51 | + scheme := NewOAuthBearerToken() |
| 52 | + |
| 53 | + assert.Equal(t, AuthenticationSchemeOAuthBearerToken, scheme.Type) |
| 54 | + assert.Equal(t, "OAuth Bearer Token", scheme.Name) |
| 55 | + assert.Equal(t, "Authentication scheme using the OAuth Bearer Token Standard", scheme.Description) |
| 56 | + assert.Equal(t, "http://www.rfc-editor.org/info/rfc6750", scheme.SpecURI) |
| 57 | + assert.False(t, scheme.Primary) |
| 58 | + }) |
| 59 | + |
| 60 | + t.Run("AsPrimary marks the scheme primary", func(t *testing.T) { |
| 61 | + scheme := NewOAuthBearerToken() |
| 62 | + |
| 63 | + require.Same(t, scheme, scheme.AsPrimary()) |
| 64 | + assert.True(t, scheme.Primary) |
| 65 | + }) |
| 66 | +} |
0 commit comments