Compare commits

..

No commits in common. "f8aaa2a039e432a44a445d3daecd645870c286d4" and "1ef8cb17d90fd244572d78a406c8036b66ffdb56" have entirely different histories.

3 changed files with 5 additions and 104 deletions

View file

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

View file

@ -1,95 +0,0 @@
# 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