Bug 2162462 - Without correct content-type, some POST endpoints get ISE + undefined method '[]='
Summary: Without correct content-type, some POST endpoints get ISE + undefined method ...
Keywords:
Status: NEW
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: API
Version: 6.13.0
Hardware: Unspecified
OS: Unspecified
unspecified
low
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Satellite QE Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-01-19 16:30 UTC by Lukáš Hellebrandt
Modified: 2023-08-14 09:16 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
production.log (12.72 KB, text/plain)
2023-01-19 16:30 UTC, Lukáš Hellebrandt
no flags Details

Description Lukáš Hellebrandt 2023-01-19 16:30:21 UTC
Created attachment 1939182 [details]
production.log

Description of problem:
When trying to `curl -X POST` to some endpoints, e.g. `/api/hosts` or `/api/users`, without specifying `-H "Content-Type: application/json"`, the call fails with 500 ISE and this backtrace:

```
2023-01-19T10:59:00 [I|app|59252892] Backtrace for 'Action failed' error (NoMethodError): undefined method `[]=' for nil:NilClass
 59252892 | /usr/share/foreman/app/controllers/api/base_controller.rb:277:in `block in assign_lone_taxonomies'
 59252892 | /usr/share/foreman/app/controllers/api/base_controller.rb:266:in `each'
 59252892 | /usr/share/foreman/app/controllers/api/base_controller.rb:266:in `assign_lone_taxonomies'
 59252892 | /usr/share/gems/gems/activesupport-6.1.7/lib/active_support/callbacks.rb:427:in `block in make_lambda'
[...]
```

Version-Release number of selected component (if applicable):
Reproduced on Sat 6.13 snap 4.0 and 7.0, Sat 6.12 snap 16.0 and Sat 6.10.5 snap 2.0 => Doesn't seem like a regression

How reproducible:
Deterministic

Steps to Reproduce:
1. # curl -uadmin:changeme -X POST https://$(hostname)/api/users -d '{"name": "test2"}'

Actual results:
{
  "error": {"message":"Internal Server Error: the server was unable to finish the request. This may be caused by unavailability of some required service, incorrect API call or a server-side bug. There may be more information in the server's logs."}
}

Expected results:
{
  "error": {"message":"Media type in 'Content-Type: application/x-www-form-urlencoded' is unsupported in API v2 for POST and PUT requests. Please use 'Content-Type: application/json'."}
}

Additional info:
Full traceback attached


Note You need to log in before you can comment on or make changes to this bug.