Bug 2162462

Summary: Without correct content-type, some POST endpoints get ISE + undefined method '[]='
Product: Red Hat Satellite Reporter: Lukáš Hellebrandt <lhellebr>
Component: APIAssignee: satellite6-bugs <satellite6-bugs>
Status: NEW --- QA Contact: Satellite QE Team <sat-qe-bz-list>
Severity: low Docs Contact:
Priority: unspecified    
Version: 6.13.0CC: aruzicka
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
production.log none

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