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
fixes #6696 - API v2 - specify the key in which parameters would be wrapped rather than passing model name #1600
Conversation
@isratrade can we have a test that validates the json output? |
@ohadlevy, this PR deals with json input for PUT and POST. What do you mean by testing the json output? I think all of our functional tests use the root node Ex. post :create, { :host => valid_attrs } The current functional host test ignores |
@ohadlevy, if we change the functional test to - post :create, { :host => valid_attrs }
+ post :create, { valid_attrs } then it will test the wrapping, since the controller uses Host.new(params[:host]) |
@isratrade if you want to test the param wrapping in minitest, you can can set the headers. Here's an example: |
@daviddavis, thanks. I set the headers in PR #1601 |
👍 |
@isratrade should this be "fixes #6674" ? |
@isratrade I also see #6696 open, which looks like a dupe of 6674, could you tidy it up please? |
@@ -285,6 +285,8 @@ def set_api_user | |||
def set_basic_auth(user, password) | |||
login = user.is_a?(User) ? user.login : user | |||
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(login, password) | |||
@request.env['CONTENT_TYPE'] = 'application/json' | |||
@request.env['HTTP_ACCEPT'] = 'application/json' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-committed. Added @request.env['HTTP_ACCEPT']
here as well as password_confirmation
to 'api/v2/users_controller.rb' since api v2 tests pass password_confirmation
@daviddavis, an you please check how this PR would break Katello's products_controller_test |
@isratrade will do. |
@daviddavis, did you find anything here about the katello test failure? |
@isratrade no, I put this on hold while looking into nested params. Let me look into it now. |
The test failure is because now we're sending json for all api requests which is triggering wrap_params and organization_id is a product param so it's not hitting the bad request anymore. Instead, it's continuing on and hitting some dynflow code. I'm tempted to remove the test. |
@daviddavis, good find. So I assume that the katello product tests needs to be updated as all api requests are in json. |
I think this good to merge in Foreman. Any ACK's? |
Here's the fix for Katello. I can open a PR but I'll probably need a BZ#. |
@daviddavis, looks good, but this should be merged in the katello repo. I think you or somebody else can merge it without a BZ number. |
[test] |
Katello/katello#4479 has been merged. |
this can now be merged, now Katello patch has been merged and all tests pass. If there is another ACK, then I'll merge it. |
I agree with @ohadlevy's comment about the need for a test, we should have had it to begin with I guess. A functional test with some unwrapped host parameters and verifying that this results in params[:host] seems right? |
Wrote some tests: |
@daviddavis, it doesn't seem that the tests you show in your gist are testing the |
@isratrade are you sure? They don't pass on develop currently but they do pass on this branch. They aren't directly checking that the |
@isratrade to be clear, each test is sending unwrapped params. It's not clear from the tests but valid_attrs is just an unwrapped hash. |
@daviddavis, I understand that the test is sending unwrapped params, but the test is doing |
@@ -2,7 +2,7 @@ module Api | |||
module V2 | |||
class HostsController < V2::BaseController | |||
|
|||
wrap_parameters Host::Base, :include => (Host::Base.attribute_names + ['image_file', 'is_owned_by', 'overwrite', 'progress_report_id']) | |||
wrap_parameters :host, :include => (Host::Base.attribute_names + ['image_file', 'is_owned_by', 'overwrite', 'progress_report_id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domcleal, I think this PR can be merged to get this fix it in for wrap_parameters :host
so it doesn't resolve to params[:base]'. I will create another PR to add
wrap_parameters` to the other controllers to ensure that unwrap PUT/POST params even though it wont be documented.
…would be wrapped rather than passing model name
This PR had changes to api/v2/compute_resources_controller.rb and api/v2/users_controller.rb but they were moved to PR #1668. This PR only fixes a bug that was introduced in api/v2/hosts_controller.rb that causes incorrect wrapping to |
[test] don't understand failures to 1.8.7 only. |
All tests were passing. It seems like it's an apipie-rails issue with 0.2.3. rails-0.2.3/lib/apipie/validator.rb:178: syntax error, unexpected ')', expecting '='
|
They've been addressed. [test] |
Thanks @isratrade, merged as a2610e9 for Foreman 1.6.0. |
specify
:host
as key rather than passing class nameHost::Base
which was incorrectly resolved toparams[:base]