RIPAGlobal / scimitar

A SCIM v2 API endpoint implementation
MIT License
61 stars 43 forks source link

Extending schema not working #122

Closed easym0de closed 4 months ago

easym0de commented 6 months ago

Hi, I'm on 2.7.2.

I've used the readme to extend schema for my integration. I've created a class: Scim::Extensions::UserManagerExtension

class Scim::Extensions::UserManagerExtension < Scimitar::Schema::Base
  def initialize(options = {})
    super(
      name:            'ExtendedUser',
      description:     'Extension for User',
      id:              self.class.id,
      scim_attributes: self.class.scim_attributes
    )
  end

  def self.id
    'urn:ietf:params:scim:schemas:extension:manager:2.0:User'
  end

  def self.scim_attributes
    [
      Scimitar::Schema::Attribute.new(name: 'manager', type: 'string')
    ]
  end
end

and in initializer, i've added:

  Scimitar::Resources::User.extend_schema(Scim::Extensions::UserManagerExtension)

When POST user requests are coming in, I don't see the defined schema. What's even weirder is that urn:ietf:params:scim:schemas:extension:enterprise:2.0:User is showing up even though the ID I defined in my custom schema extension class is different. I also see that in the post request the stuff defined in https://datatracker.ietf.org/doc/html/rfc7643#section-4.3 is included inside the enterprise schema even though I have not added or extended it. For example employeeNumber is coming through.

Is the EnterpriseUserExtension now a default? Is the custom schema extension broken?

pond commented 5 months ago

Sorry for the delay; finally got around to this.

I tried copying your example extension into the Scimitar test suite's dummy app's initializer to see what would show up there. Some tests fail (correctly) because they see an extra schema being described.

The TL;DR here is that the mixin tests were a canary showing that, at least when two extensions were in use, things went ary. So, I'm working on that now; the dummy test app will include a variant of your manager extension in addition to the enterprise extension it already had, with one fix arising so far and more tests to add.

However, if that was the only extension you'd added, then I'd expect at least 2.8.0 to be working. If not, it could depend on your SCIM attributes mapping. I'm also not sure about "I also see that in the post request the stuff defined in ... is included". Included where? The response? It would help to see the associated model's SCIM attribute map, along with the JSON used for a POST request, along with the JSON you see for the POST response.

pond commented 5 months ago

@easym0de

Well, #134 is in review to hopefully address some issues with extension schemas. I doubt the multiple-extensions bug was the one you hit, but POST was definitely shaky and case sensitivity a particular problem.

On attributes: As far as I can make out, you'd only be seeing the likes of employeeNumber returned in the POST response if your underlying resource's SCIM attributes map had entries for those attributes, and they're referenced in a schema extension somewhere. To the best of my recollection (and I just searched the codebase again to make sure, although I might still be wrong...) Scimitar has no enterprise extensions defined out-of-the-box, only Core; the only place you'll see references to enterprise schema attributes is in the test suite.

pond commented 4 months ago

Closing this as I believe it's all fixed up now. See v2.9.0 (Rails 7) and v1.10.0 (Rails 6).