Skip to content

Commit f052d47

Browse files
committed
serve all core schemas
1 parent a56d676 commit f052d47

3 files changed

Lines changed: 174 additions & 4 deletions

File tree

handlers_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -762,18 +762,21 @@ func TestServerSchemasEndpoint(t *testing.T) {
762762
var response listResponse
763763
assertUnmarshalNoError(t, json.Unmarshal(rr.Body.Bytes(), &response))
764764

765-
expectedLen := 3
765+
expectedLen := 6
766766
assertEqual(t, expectedLen, response.TotalResults)
767767
assertLen(t, response.Resources, expectedLen)
768768

769-
resourceIDs := make([]string, 3)
769+
resourceIDs := make([]string, 6)
770770
for i, resource := range response.Resources {
771771
resourceType, ok := resource.(map[string]interface{})
772772
assertTypeOk(t, ok, "object")
773773
resourceIDs[i] = resourceType["id"].(string)
774774
}
775775

776776
assertEqualStrings(t, []string{
777+
"urn:ietf:params:scim:schemas:core:2.0:Schema",
778+
"urn:ietf:params:scim:schemas:core:2.0:ResourceType",
779+
"urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig",
777780
"urn:ietf:params:scim:schemas:core:2.0:User",
778781
"urn:ietf:params:scim:schemas:extension:enterprise:2.0:User",
779782
"urn:ietf:params:scim:schemas:core:2.0:Group",
@@ -798,7 +801,7 @@ func TestServerSchemasEndpointFilter(t *testing.T) {
798801
var response listResponse
799802
assertUnmarshalNoError(t, json.Unmarshal(rr.Body.Bytes(), &response))
800803
assertLen(t, response.Resources, 1)
801-
assertEqual(t, 3, response.TotalResults)
804+
assertEqual(t, 6, response.TotalResults)
802805
}
803806

804807
func TestServerServiceProviderConfigHandler(t *testing.T) {

schema/schemas.go

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,160 @@ func ResourceTypeSchema() Schema {
685685
Name: optional.NewString("Resource Type"),
686686
}
687687
}
688+
689+
// ServiceProviderConfig returns the Resource Type Schema.
690+
// RFC: https://tools.ietf.org/html/rfc7643#section-5
691+
func ServiceProviderConfigSchema() Schema {
692+
return Schema{
693+
Attributes: []CoreAttribute{
694+
SimpleCoreAttribute(SimpleStringParams(StringParams{
695+
Description: optional.NewString("An HTTP-addressable URL pointing to the service provider's human-consumable help documentation."),
696+
Mutability: AttributeMutabilityReadOnly(),
697+
Name: "documentationUri",
698+
Required: false,
699+
})),
700+
ComplexCoreAttribute(ComplexParams{
701+
Description: optional.NewString("A complex type that specifies PATCH configuration options."),
702+
Mutability: AttributeMutabilityReadOnly(),
703+
Name: "patch",
704+
Required: true,
705+
SubAttributes: []SimpleParams{
706+
SimpleBooleanParams(BooleanParams{
707+
Description: optional.NewString("A Boolean value specifying whether or not the operation is supported."),
708+
Mutability: AttributeMutabilityReadOnly(),
709+
Name: "supported",
710+
Required: true,
711+
}),
712+
},
713+
}),
714+
ComplexCoreAttribute(ComplexParams{
715+
Description: optional.NewString("A complex type that specifies bulk configuration options."),
716+
Mutability: AttributeMutabilityReadOnly(),
717+
Name: "bulk",
718+
Required: true,
719+
SubAttributes: []SimpleParams{
720+
SimpleBooleanParams(BooleanParams{
721+
Description: optional.NewString("A Boolean value specifying whether or not the operation is supported."),
722+
Mutability: AttributeMutabilityReadOnly(),
723+
Name: "supported",
724+
Required: true,
725+
}),
726+
SimpleNumberParams(NumberParams{
727+
Description: optional.NewString("An integer value specifying the maximum number of operations."),
728+
Mutability: AttributeMutabilityReadOnly(),
729+
Name: "maxOperations",
730+
Required: true,
731+
}),
732+
SimpleNumberParams(NumberParams{
733+
Description: optional.NewString("An integer value specifying the maximum payload size in bytes."),
734+
Mutability: AttributeMutabilityReadOnly(),
735+
Name: "maxPayloadSize",
736+
Required: true,
737+
}),
738+
},
739+
}),
740+
ComplexCoreAttribute(ComplexParams{
741+
Description: optional.NewString("A complex type that specifies FILTER options."),
742+
Mutability: AttributeMutabilityReadOnly(),
743+
Name: "filter",
744+
Required: true,
745+
SubAttributes: []SimpleParams{
746+
SimpleBooleanParams(BooleanParams{
747+
Description: optional.NewString("A Boolean value specifying whether or not the operation is supported."),
748+
Mutability: AttributeMutabilityReadOnly(),
749+
Name: "supported",
750+
Required: true,
751+
}),
752+
SimpleNumberParams(NumberParams{
753+
Description: optional.NewString("An integer value specifying the maximum number of resources returned in a response."),
754+
Mutability: AttributeMutabilityReadOnly(),
755+
Name: "maxResults",
756+
Required: true,
757+
}),
758+
},
759+
}),
760+
ComplexCoreAttribute(ComplexParams{
761+
Description: optional.NewString("A complex type that specifies configuration options related to changing a password."),
762+
Mutability: AttributeMutabilityReadOnly(),
763+
Name: "changePassword",
764+
Required: true,
765+
SubAttributes: []SimpleParams{
766+
SimpleBooleanParams(BooleanParams{
767+
Description: optional.NewString("A Boolean value specifying whether or not the operation is supported."),
768+
Mutability: AttributeMutabilityReadOnly(),
769+
Name: "supported",
770+
Required: true,
771+
}),
772+
},
773+
}),
774+
ComplexCoreAttribute(ComplexParams{
775+
Description: optional.NewString("A complex type that specifies Sort configuration options."),
776+
Mutability: AttributeMutabilityReadOnly(),
777+
Name: "sort",
778+
Required: true,
779+
SubAttributes: []SimpleParams{
780+
SimpleBooleanParams(BooleanParams{
781+
Description: optional.NewString("A Boolean value specifying whether or not the operation is supported."),
782+
Mutability: AttributeMutabilityReadOnly(),
783+
Name: "supported",
784+
Required: true,
785+
}),
786+
},
787+
}),
788+
ComplexCoreAttribute(ComplexParams{
789+
Description: optional.NewString("A complex type that specifies ETag configuration options."),
790+
Mutability: AttributeMutabilityReadOnly(),
791+
Name: "etag",
792+
Required: true,
793+
SubAttributes: []SimpleParams{
794+
SimpleBooleanParams(BooleanParams{
795+
Description: optional.NewString("A Boolean value specifying whether or not the operation is supported."),
796+
Mutability: AttributeMutabilityReadOnly(),
797+
Name: "supported",
798+
Required: true,
799+
}),
800+
},
801+
}),
802+
ComplexCoreAttribute(ComplexParams{
803+
Description: optional.NewString("A complex type that specifies ETag configuration options."),
804+
Mutability: AttributeMutabilityReadOnly(),
805+
Name: "authenticationSchemes",
806+
Required: true,
807+
MultiValued: true,
808+
SubAttributes: []SimpleParams{
809+
SimpleStringParams(StringParams{
810+
Description: optional.NewString("The authentication scheme. This specification defines the values 'oauth', 'oauth2', 'oauthbearertoken', 'httpbasic', and 'httpdigest'."),
811+
Mutability: AttributeMutabilityReadOnly(),
812+
Name: "type",
813+
Required: true,
814+
}),
815+
SimpleStringParams(StringParams{
816+
Description: optional.NewString("The common authentication scheme name, e.g., HTTP Basic."),
817+
Mutability: AttributeMutabilityReadOnly(),
818+
Name: "name",
819+
Required: true,
820+
}),
821+
SimpleStringParams(StringParams{
822+
Description: optional.NewString("A description of the authentication scheme."),
823+
Mutability: AttributeMutabilityReadOnly(),
824+
Name: "description",
825+
Required: true,
826+
}),
827+
SimpleStringParams(StringParams{
828+
Description: optional.NewString("An HTTP-addressable URL pointing to the authentication scheme's specification."),
829+
Mutability: AttributeMutabilityReadOnly(),
830+
Name: "specUri",
831+
}),
832+
SimpleStringParams(StringParams{
833+
Description: optional.NewString("An HTTP-addressable URL pointing to the authentication scheme's usage documentation."),
834+
Mutability: AttributeMutabilityReadOnly(),
835+
Name: "documentationUri",
836+
}),
837+
},
838+
}),
839+
},
840+
Description: optional.NewString("SCIM provides a schema for representing the service provider's configuration."),
841+
ID: "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig",
842+
Name: optional.NewString("Service Provider Config"),
843+
}
844+
}

server.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
132132

133133
// getSchema extracts the schemas from the resources types defined in the server with given id.
134134
func (s Server) getSchema(id string) schema.Schema {
135+
switch id {
136+
case "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig":
137+
return schema.ServiceProviderConfigSchema()
138+
case "urn:ietf:params:scim:schemas:core:2.0:ResourceType":
139+
return schema.ResourceTypeSchema()
140+
case "urn:ietf:params:scim:schemas:core:2.0:Schema":
141+
return schema.Definition()
142+
}
135143
for _, resourceType := range s.ResourceTypes {
136144
if resourceType.Schema.ID == id {
137145
return resourceType.Schema
@@ -148,7 +156,9 @@ func (s Server) getSchema(id string) schema.Schema {
148156
// getSchemas extracts all the schemas from the resources types defined in the server. Duplicate IDs will be ignored.
149157
func (s Server) getSchemas() []schema.Schema {
150158
ids := make([]string, 0)
151-
schemas := make([]schema.Schema, 0)
159+
schemas := []schema.Schema{
160+
schema.Definition(), schema.ResourceTypeSchema(), schema.ServiceProviderConfigSchema(),
161+
}
152162
for _, resourceType := range s.ResourceTypes {
153163
if !contains(ids, resourceType.Schema.ID) {
154164
schemas = append(schemas, resourceType.Schema)

0 commit comments

Comments
 (0)