Bug 1129769

Summary: Satellite 6 API throws invalid error messages for non-json requests
Product: Red Hat Satellite 6 Reporter: sthirugn <sthirugn>
Component: APIAssignee: Bryan Kearney <bkearney>
Status: CLOSED CURRENTRELEASE QA Contact: sthirugn <sthirugn>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.0.3CC: dcleal, jmontleo, sthirugn
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/6446
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-09-11 12:19:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description sthirugn@redhat.com 2014-08-13 15:34:57 UTC
Description of problem:
Satellite6 API currently supports only json input content-type.  So it should throw '415 Unsupported Media Type' error for non-json requests

Version-Release number of selected component (if applicable):
GA Snap 4 - Satellite-6.0.4-RHEL-6-20140806.0

* apr-util-ldap-1.3.9-3.el6_0.1.x86_64
* candlepin-0.9.19-1.el6_5.noarch
* candlepin-scl-1-5.el6_4.noarch
* candlepin-scl-quartz-2.1.5-5.el6_4.noarch
* candlepin-scl-rhino-1.7R3-1.el6_4.noarch
* candlepin-scl-runtime-1-5.el6_4.noarch
* candlepin-selinux-0.9.19-1.el6_5.noarch
* candlepin-tomcat6-0.9.19-1.el6_5.noarch
* elasticsearch-0.90.10-4.el6sat.noarch
* foreman-1.6.0.38-1.el6sat.noarch
* foreman-compute-1.6.0.38-1.el6sat.noarch
* foreman-gce-1.6.0.38-1.el6sat.noarch
* foreman-libvirt-1.6.0.38-1.el6sat.noarch
* foreman-ovirt-1.6.0.38-1.el6sat.noarch
* foreman-postgresql-1.6.0.38-1.el6sat.noarch
* foreman-proxy-1.6.0.23-1.el6sat.noarch
* foreman-selinux-1.6.0.4-1.el6sat.noarch
* foreman-vmware-1.6.0.38-1.el6sat.noarch
* katello-1.5.0-28.el6sat.noarch
* katello-ca-1.0-1.noarch
* katello-certs-tools-1.5.6-1.el6sat.noarch
* katello-installer-0.0.57-1.el6sat.noarch
* openldap-2.4.23-34.el6_5.1.x86_64
* pulp-katello-0.3-3.el6sat.noarch
* pulp-nodes-common-2.4.0-0.30.beta.el6sat.noarch
* pulp-nodes-parent-2.4.0-0.30.beta.el6sat.noarch
* pulp-puppet-plugins-2.4.0-0.30.beta.el6sat.noarch
* pulp-puppet-tools-2.4.0-0.30.beta.el6sat.noarch
* pulp-rpm-plugins-2.4.0-0.30.beta.el6sat.noarch
* pulp-selinux-2.4.0-0.30.beta.el6sat.noarch
* pulp-server-2.4.0-0.30.beta.el6sat.noarch
* python-ldap-2.3.10-1.el6.x86_64
* ruby193-rubygem-net-ldap-0.3.1-3.el6sat.noarch
* ruby193-rubygem-runcible-1.1.0-2.el6sat.noarch
* sssd-ldap-1.11.5.1-3.el6.x86_64

How reproducible:
Always

Steps to Reproduce:
Example:
Attempt to create an organization with content-types:
- application/json (passed)
- application/xml (failed) 
- text/plain (failed)
(see below for details)

1. Content-Type: application/json - Success! PASS
curl -X POST -H "Accept:application/json" -H "Content-Type: application/json" -u admin:changeme --insecure -d '{"name":"testorgapi"}' https://host/katello/api/v2/organizations
Success!

2. Content-Type: application/xml - Failed
# curl -X POST -H "Accept:application/xml" -H "Content-Type: application/xml" -u admin:changeme --insecure -d '<name>testorgapi</name>' https://host/katello/api/v2/organizations
{
  "error": {"id":null,"errors":{"name":["can't be blank","can't be blank","cannot be blank"],"title":["can't be blank"],"label":["can't be blank","can't be blank","can't be blank"]},"full_messages":["Name can't be blank","Name can't be blank","Name cannot be blank","Title can't be blank","Label can't be blank","Label can't be blank","Label can't be blank"]}

3. Content-Type: text/plain - Failed
#curl -X POST -H "Accept:application/xml" -H "Content-Type: text/plain" -u admin:changeme --insecure -d 'name=testorgapi' https://host/katello/api/v2/organizations
{
  "error": {"id":null,"errors":{"name":["can't be blank","can't be blank","cannot be blank"],"title":["can't be blank"],"label":["can't be blank","can't be blank","can't be blank"]},"full_messages":["Name can't be blank","Name can't be blank","Name cannot be blank","Title can't be blank","Label can't be blank","Label can't be blank","Label can't be blank"]}

Actual results:
Satellite 6 API does not validate the content-type and assumes everything as json input so the error message is weird as I have shown above

Expected results:
Satellite 6 API should valid content-type and throw "415 - Unsupported Media Type" error if the input content-type is not json.


Additional info:

Comment 1 sthirugn@redhat.com 2014-08-13 15:39:10 UTC
foreman issue - http://projects.theforeman.org/issues/6446

Comment 2 David Davis 2014-08-13 15:39:43 UTC
Not sure how the foreman guys want to handle this but it was solved in this issue:

http://projects.theforeman.org/issues/6446

Here's the PR:

https://github.com/theforeman/foreman/pull/1622

Comment 4 Bryan Kearney 2014-08-13 15:56:36 UTC
Connecting redmine issue http://projects.theforeman.org/issues/6446 from this bug

Comment 5 Bryan Kearney 2014-08-13 16:04:53 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/6446 has been closed
-------------
David Davis
Applied in changeset commit:50ebc024bd5b13b490c41f2b3e5e0c489e7f892b.

Comment 8 sthirugn@redhat.com 2014-08-20 19:37:19 UTC
Verified.

# curl -X POST -H "Accept:application/json" -H "Content-Type: application/json" -u admin:changeme --insecure -d '{"name":"testorgapi123"}' https://host/katello/api/v2/organizations

<success>

# curl -X POST -H "Accept:application/json" -H "Content-Type: application/xml" -u admin:changeme --insecure -d '<name>testorgapi1234</name>' https://host/katello/api/v2/organizations
{
  "error": {"message":"'Content-Type: application/xml' is unsupported in API v2 for POST and PUT requests. Please use 'Content-Type: application/json'."}
}

# curl -X POST -H "Accept:application/json" -H "Content-Type: text/plain" -u admin:changeme --insecure -d 'name=testorgapi1234' https://host/katello/api/v2/organizations
{
  "error": {"message":"'Content-Type: text/plain' is unsupported in API v2 for POST and PUT requests. Please use 'Content-Type: application/json'."}

Version Tested:
GA Snap 6 - Satellite-6.0.4-RHEL-6-20140820.1

* apr-util-ldap-1.3.9-3.el6_0.1.x86_64
* candlepin-0.9.23-1.el6_5.noarch
* candlepin-common-1.0.1-1.el6_5.noarch
* candlepin-scl-1-5.el6_4.noarch
* candlepin-scl-quartz-2.1.5-5.el6_4.noarch
* candlepin-scl-rhino-1.7R3-1.el6_4.noarch
* candlepin-scl-runtime-1-5.el6_4.noarch
* candlepin-selinux-0.9.23-1.el6_5.noarch
* candlepin-tomcat6-0.9.23-1.el6_5.noarch
* elasticsearch-0.90.10-6.el6sat.noarch
* foreman-1.6.0.41-1.el6sat.noarch
* foreman-compute-1.6.0.41-1.el6sat.noarch
* foreman-gce-1.6.0.41-1.el6sat.noarch
* foreman-libvirt-1.6.0.41-1.el6sat.noarch
* foreman-ovirt-1.6.0.41-1.el6sat.noarch
* foreman-postgresql-1.6.0.41-1.el6sat.noarch
* foreman-proxy-1.6.0.29-1.el6sat.noarch
* foreman-selinux-1.6.0.7-1.el6sat.noarch
* foreman-vmware-1.6.0.41-1.el6sat.noarch
* katello-1.5.0-29.el6sat.noarch
* katello-ca-1.0-1.noarch
* katello-certs-tools-1.5.6-1.el6sat.noarch
* katello-installer-0.0.60-1.el6sat.noarch
* openldap-2.4.23-34.el6_5.1.x86_64
* openldap-devel-2.4.23-34.el6_5.1.x86_64
* pulp-katello-0.3-3.el6sat.noarch
* pulp-nodes-common-2.4.0-0.30.beta.el6sat.noarch
* pulp-nodes-parent-2.4.0-0.30.beta.el6sat.noarch
* pulp-puppet-plugins-2.4.0-0.30.beta.el6sat.noarch
* pulp-puppet-tools-2.4.0-0.30.beta.el6sat.noarch
* pulp-rpm-plugins-2.4.0-0.30.beta.el6sat.noarch
* pulp-selinux-2.4.0-0.30.beta.el6sat.noarch
* pulp-server-2.4.0-0.30.beta.el6sat.noarch
* python-ldap-2.3.10-1.el6.x86_64
* ruby193-rubygem-net-ldap-0.3.1-3.el6sat.noarch
* ruby193-rubygem-runcible-1.1.0-2.el6sat.noarch

Comment 9 Bryan Kearney 2014-09-11 12:19:24 UTC
This was delivered with Satellite 6.0 which was released on 10 September 2014.