Skip to content

Commit

Permalink
Raise bad request when current_group is specified on edit
Browse files Browse the repository at this point in the history
Editing of a current_group is allowed only on on the set_current_group action.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1549086
  • Loading branch information
Jillian Tullo committed Feb 27, 2018
1 parent 8fa320d commit d2e8ea4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Api
class UsersController < BaseController
INVALID_USER_ATTRS = %w(id href current_group_id settings).freeze # Cannot update other people's settings
INVALID_SELF_USER_ATTRS = %w(id href current_group_id).freeze
INVALID_USER_ATTRS = %w(id href current_group_id settings current_group).freeze # Cannot update other people's settings
INVALID_SELF_USER_ATTRS = %w(id href current_group_id current_group).freeze
EDITABLE_ATTRS = %w(password email settings).freeze

include Subcollections::Tags
Expand Down
21 changes: 21 additions & 0 deletions spec/requests/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,27 @@
expect(user1.reload.miq_groups).to match_array([group2, group3])
end

it "does not allow edits of current_user" do
api_basic_authorize collection_action_identifier(:users, :edit)

request = {
"action" => "edit",
"resources" => [{
"href" => api_user_url(nil, user1),
"current_group" => {}
}]
}
post(api_users_url, :params => request)

expected = {
'error' => a_hash_including(
'message' => "Invalid attribute(s) current_group specified for a user"
)
}
expect(response).to have_http_status(:bad_request)
expect(response.parsed_body).to include(expected)
end

it "does not allow setting of empty miq_groups" do
api_basic_authorize collection_action_identifier(:users, :edit)

Expand Down

0 comments on commit d2e8ea4

Please sign in to comment.