Compare commits

..

3 commits

3 changed files with 104 additions and 5 deletions

View file

@ -16,6 +16,11 @@ Discourse::Application.routes.draw {
get 'Groups', to: 'groups#index' get 'Groups', to: 'groups#index'
get 'Groups/:id', to: 'groups#show' get 'Groups/:id', to: 'groups#show'
post 'Groups', to: 'groups#create' post 'Groups', to: 'groups#create'
put 'Groups/:id', to: 'groups#replace'
patch 'Groups/:id', to: 'groups#update' patch 'Groups/:id', to: 'groups#update'
delete 'Groups/:id', to: 'groups#destroy'
# TODO: Add catchall that sends a not available
#get '*unmatched_route', to: 'application#raise_not_found!'
end end
} }

View file

@ -50,9 +50,6 @@ after_initialize do
id: :id, id: :id,
userName: :username, userName: :username,
displayName: :name, displayName: :name,
name: {
formatted: :name
},
emails: [ emails: [
{ {
match: "type", match: "type",
@ -126,7 +123,7 @@ after_initialize do
}, },
find_with: -> (scim_list_entry) { find_with: -> (scim_list_entry) {
id = scim_list_entry['value'] id = scim_list_entry['value']
type = scim_list_entry['type' ] || 'User' # Some online examples omit 'type' and believe 'User' will be assumed type = scim_list_entry['type' ] || 'User'
case type.downcase case type.downcase
when 'user' when 'user'
@ -134,7 +131,9 @@ after_initialize do
when 'group' when 'group'
Group.find_by_id(id) Group.find_by_id(id)
else else
raise Scimitar::InvalidSyntaxError.new("Unrecognised type #{type.inspect}") # TODO: Decide what to do here, I added User to be able to use scim-tester
User.find_by_id(id)
# raise Scimitar::InvalidSyntaxError.new("Unrecognised type #{type.inspect}")
end end
} }
] ]

View file

@ -0,0 +1,95 @@
# frozen_string_literal: true
describe "User SCIM endpoint" do
before do
SiteSetting.chat_enabled = true
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:everyone]
end
fab!(:admin)
let(:scim_api_key) do
key = ApiKey.create!
ApiKeyScope.create!(resource: "scim", action: "access_scim_endpoints", api_key_id: key.id)
key
end
def create_user
post "/scim_v2/Users",
headers: {
"Authorization" => "Bearer " + scim_api_key.key,
"Content-Type" => "application/scim+json"
},
params: {
schemas: [
"urn:ietf:params:scim:schemas:core:2.0:User"
],
userName: "testUser",
displayName: "Test User",
emails: [
{
value: "testuser@example.com",
type: "work"
},
],
active: true
},
as: :json
end
it "can create a user" do
expect {
create_user
}.to change { User.count }.by(1)
expect(response.status).to eq(201)
end
it "can query a user" do
create_user
response_content = JSON.parse(response.body)
get "/scim_v2/Users/#{response_content["id"]}",
headers: {
"Authorization" => "Bearer " + scim_api_key.key,
"Content-Type" => "application/scim+json"
},
as: :json
expect(response.status).to eq(200)
response_content = JSON.parse(response.body)
expect(response_content["displayName"]).to eq("Test User")
end
it "can modify a user" do
create_user
response_content = JSON.parse(response.body)
patch "/scim_v2/Users/#{response_content["id"]}",
headers: {
"Authorization" => "Bearer " + scim_api_key.key,
"Content-Type" => "application/scim+json"
},
params: {
schemas: [
"urn:ietf:params:scim:schemas:core:2.0:PatchOp"
],
Operations: [
{
op: "replace",
value: {
displayName: "Changed Name"
}
}
]
},
as: :json
expect(response.status).to eq(200)
get "/scim_v2/Users/#{response_content["id"]}",
headers: {
"Authorization" => "Bearer " + scim_api_key.key,
"Content-Type" => "application/scim+json"
},
as: :json
expect(response.status).to eq(200)
response_content = JSON.parse(response.body)
expect(response_content["displayName"]).to eq("Changed Name")
end
end