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

Enhanced API to catch Settings validation errors #356

Merged
merged 2 commits into from
Apr 9, 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
6 changes: 5 additions & 1 deletion app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def settings
case @req.method
when :patch
raise ForbiddenError, "You are not authorized to edit settings." unless super_admin?
resource.add_settings_for_resource(@req.json_body)
begin
resource.add_settings_for_resource(@req.json_body)
rescue Vmdb::Settings::ConfigurationInvalid => err
raise BadRequestError, "Settings validation failed - #{err}"
end
when :delete
raise ForbiddenError, "You are not authorized to remove settings." unless super_admin?
resource.remove_settings_path_for_resource(*@req.json_body)
Expand Down
16 changes: 16 additions & 0 deletions spec/requests/servers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@
expect(response).to have_http_status(:unauthorized)
end

it "returns a bad_request to an update if the settings validation failed" do
api_basic_authorize(:user => super_admin.userid, :password => super_admin.password)

patch(api_server_settings_url(nil, server), :params => {:authentication => {:mode => "bogus_auth_mode"}})

expected = {
'error' => a_hash_including(
'kind' => 'bad_request',
'message' => a_string_including('Settings validation failed - ')
)
}

expect(response).to have_http_status(:bad_request)
expect(response.parsed_body).to include(expected)
end

context "with an existing settings change" do
before do
server.add_settings_for_resource("api" => {"authentication_timeout" => "7331.minutes"})
Expand Down