Red Hat Bugzilla – Bug 1122257
Receive HTTP 500 after issuing HTTP POST with non-JSON request body
Last modified: 2016-07-27 04:43:08 EDT
Description of problem: Issuing an HTTP POST request to (thus far) absolutely any URL results in an HTTP 500 error. This occurs when credentials are not supplied with the request. Version-Release number of selected component (if applicable): * apr-util-ldap-1.3.9-3.el6_0.1.x86_64 * candlepin-0.9.21-1.el6.noarch * candlepin-selinux-0.9.21-1.el6.noarch * candlepin-tomcat6-0.9.21-1.el6.noarch * elasticsearch-0.90.10-4.el6.noarch * foreman-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * foreman-compute-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * foreman-gce-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * foreman-libvirt-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * foreman-ovirt-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * foreman-postgresql-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * foreman-proxy-1.6.0-0.develop.201407211449git2cba606.el6.noarch * foreman-release-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * foreman-selinux-1.6.0-0.develop.201406261522git5532684.el6.noarch * foreman-vmware-1.6.0-0.develop.201407211519git93f6f75.el6.noarch * katello-1.5.0-14.201407211524gitddbde13.el6.noarch * katello-ca-1.0-1.noarch * katello-certs-tools-1.5.2-1.git.1.edab2c4.el6.noarch * katello-installer-0.0.19-1.201407162131gitb142720.el6.noarch * katello-repos-1.5.1-1.git.14.0868bd1.el6.noarch * openldap-2.4.23-31.el6.x86_64 * pulp-katello-0.3-3.el6.noarch * pulp-nodes-common-2.4.0-0.24.beta.el6.noarch * pulp-nodes-parent-2.4.0-0.24.beta.el6.noarch * pulp-puppet-plugins-2.4.0-0.24.beta.el6.noarch * pulp-puppet-tools-2.4.0-0.24.beta.el6.noarch * pulp-rpm-plugins-2.4.0-0.24.beta.el6.noarch * pulp-selinux-2.4.0-0.24.beta.el6.noarch * pulp-server-2.4.0-0.24.beta.el6.noarch * python-ldap-2.3.10-1.el6.x86_64 * ruby193-rubygem-net-ldap-0.3.1-2.el6.noarch * ruby193-rubygem-runcible-1.1.0-1.el6.noarch How reproducible: 100% Steps to Reproduce: 1. Issue an HTTP POST request to any URL, and do not provide credentials. 2. Examine the status code of the response. 3. See an HTTP 500. :( Actual results: HTTP 500 Expected results: HTTP 401 Additional info: Relevant test code can be seen here: https://github.com/omaciel/robottelo/blob/master/tests/foreman/api/test_multiple_paths.py#L130-L154 Pull request #1068 will cause the code to move. If it is accepted, you can find the test code here instead: https://github.com/omaciel/robottelo/blob/master/tests/foreman/api/test_multiple_paths.py#L96-L120
Since this issue was entered in Red Hat Bugzilla, the release flag has been set to ? to ensure that it is properly evaluated for this release.
Please provide foreman-debug, I cannot reproduce this.
Here's the error which appears in /var/log/foreman/production.log. I'll attach foreman-debug shortly. NoMethodError (undefined method `each' for nil:NilClass): lib/middleware/catch_json_parse_errors.rb:9:in `call' NoMethodError (undefined method `each' for nil:NilClass): lib/middleware/catch_json_parse_errors.rb:9:in `call' NoMethodError (undefined method `each' for nil:NilClass): lib/middleware/catch_json_parse_errors.rb:9:in `call' NoMethodError (undefined method `each' for nil:NilClass): lib/middleware/catch_json_parse_errors.rb:9:in `call' (over and over and over again)
I've uploaded a file named "foreman-debug-308di.tar.xz" using foreman-debug.
Thanks, I managed to reproduce it with robotello against EL6. Here's a simplified reproducer: curl -d "null" -H "Content-type: application/json" http://foreman.example.com/api/v2/hosts
Created redmine issue http://projects.theforeman.org/issues/6774 from this bug
Nice job filing the redmine issue. I didn't know about the malformed JSON bug.
I don't believe that the title of this bug accurately reflects what's going on. How about "Receive HTTP 500 after issuing unauthorized POST request"?
Whether the request is authorised or not seems to make no difference. The issue was in the parsing of the request body, which in the test case was the string "null" (not valid JSON).
Ahaa. I've just double-checked my test code, and what you've said makes sense. I'll change back the bug title.
Moving to POST since upstream bug http://projects.theforeman.org/issues/6774 has been closed ------------- Tom Caspy Applied in changeset commit:44dbdbc3b5d9bba1a3e81825abc4430a7f99d753.
Upstream bug assigned to tcaspy@redhat.com
Verified in upstream. Submitted a POST to api/v2/locations/ with an improperly formatted body. Received: { "error": { "message": "Unable to authenticate user " } }
Version information: RELEASE: Red Hat Enterprise Linux Server release 7.1 (Maipo) FOREMAN: 1.11.0-develop RUBY: ruby 2.0.0p598 (2014-11-13) [x86_64-linux] PUPPET: 3.8.4
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2016:1500