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

Conversation

abellotti
Copy link
Member

Enhanced API to catch Settings validation errors and reporting accordingly to the client via a BadRequestError.

@abellotti
Copy link
Member Author

Marking as WIP for now, tests will fail until we update/sync up with @Fryguy's magic settings fix.

it "updates to settings return a BadRequestError upon failed validation" 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"}})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other server settings specs are in spec/requests/servers_spec.rb - would it make sense for this to live there too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starting going that way, but then realizing I'm really testing a settings update handling that's generic to all and it didn't make sense to duplicate for servers, zone, region, so I put that here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but you're hitting a different endpoint to the one suggested by this file. Does it work if you hit the api_settings_url? If not, perhaps consider a shared example to eliminate duplication?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh good point, I'll move it the proper file.

@@ -117,7 +117,7 @@ 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)
resource_update_settings(resource, @req.json_body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not opposed to extracting a method here, but I think its name should reflect the responsibilit(y|ies) of the new method - here's it's to try an update and raise on a validation error. I'm having a hard time trying to find a succinct way to say that, so maybe inline for now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't crazy about have the begin/rescue inside the when block, (you never know when rubocop starts complaining about complexity 😉 ) so I created the separate method. I can go either way really. up to you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poke @imtayadeway any preference ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my preference is for in-line 👍

@abellotti abellotti force-pushed the catch_settings_config_errors branch from 20f1c5c to 4f64cec Compare April 4, 2018 13:18
@miq-bot
Copy link
Member

miq-bot commented Apr 4, 2018

Checked commits abellotti/manageiq-api@f21df07~...4f64cec with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@abellotti abellotti changed the title [WIP] Enhanced API to catch Settings validation errors Enhanced API to catch Settings validation errors Apr 4, 2018
@abellotti abellotti removed the wip label Apr 4, 2018
@abellotti
Copy link
Member Author

@Fryguy PR updated following ManageIQ/manageiq#17247 Thanks!!

@abellotti
Copy link
Member Author

PATCH /api/servers/1/settings

{
  "authentication" : { "bind_timeout" : 123 }
}

now gives us:

{
  "error": {
    "kind": "bad_request",
    "message": "Settings validation failed - authentication-mode: authentication mode, nil, is invalid. Should be one of: amazon, ldap, ldaps, httpd, database, none",
    "klass": "Api::BadRequestError"
  }
}

@abellotti
Copy link
Member Author

poke @imtayadeway

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. I would prefer a spec for zones and regions, since the fact that they have a common pathway is an implementation detail to an integration test, but that's more of a nit. 👍

@Fryguy Fryguy merged commit 82d558f into ManageIQ:master Apr 9, 2018
@Fryguy Fryguy added this to the Sprint 83 Ending Apr 9, 2018 milestone Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants