Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise bad request when current_group is specified on edit #329

Merged
merged 1 commit into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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