Compare commits
3 commits
1ef8cb17d9
...
f8aaa2a039
Author | SHA1 | Date | |
---|---|---|---|
f8aaa2a039 | |||
69fff8cfa5 | |||
61e62d07d6 |
3 changed files with 104 additions and 5 deletions
|
@ -16,6 +16,11 @@ Discourse::Application.routes.draw {
|
|||
get 'Groups', to: 'groups#index'
|
||||
get 'Groups/:id', to: 'groups#show'
|
||||
post 'Groups', to: 'groups#create'
|
||||
put 'Groups/:id', to: 'groups#replace'
|
||||
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
|
||||
}
|
||||
|
|
|
@ -50,9 +50,6 @@ after_initialize do
|
|||
id: :id,
|
||||
userName: :username,
|
||||
displayName: :name,
|
||||
name: {
|
||||
formatted: :name
|
||||
},
|
||||
emails: [
|
||||
{
|
||||
match: "type",
|
||||
|
@ -126,7 +123,7 @@ after_initialize do
|
|||
},
|
||||
find_with: -> (scim_list_entry) {
|
||||
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
|
||||
when 'user'
|
||||
|
@ -134,7 +131,9 @@ after_initialize do
|
|||
when 'group'
|
||||
Group.find_by_id(id)
|
||||
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
|
||||
}
|
||||
]
|
||||
|
|
95
spec/integration/users_spec.rb
Normal file
95
spec/integration/users_spec.rb
Normal 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
|
Loading…
Reference in a new issue