Description of problem: In bug 1659899, it was found that providing an invalid "towhat" value in the payload while creating a policy via the API would result in an unclear error message. The received message is the default error message for a failed Rails inclusion validation: "Towhat is not included in the list" This message can mistakenly be interpreted to mean "towhat" was not included in the payload, when it's actually referring to the inclusion list it's being validated against. We should clarify the messaging to specify the list of valid "towhat" values, following established patterns throughout other models. How reproducible: Always, with an invalid "towhat" value. Steps to Reproduce: 1. Send a create Policies request via the API Request: POST /api/policies Query: { "action": "create", "resources": [{ "name": "test_policy_cNUnZ", "conditions_ids": ["3", "4"], "towhat": "invalidtowhat", "policy_contents": [{ "event_id": 2, "actions": [{ "opts": { "qualifier": "failure" }, "action_id": 1 }] }], "mode": "compliance", "description": "Test Policy cNUnZ" } ] } Actual results: Response: { "error": { "kind": "bad_request", "message": "Could not create the new policy - Validation failed: MiqPolicy: Towhat is not included in the list", "klass": "Api::BadRequestError" } } Expected results: Response: { "error": { "kind": "bad_request", "message": "Could not create the new policy - Validation failed: MiqPolicy: Towhat should be one of ContainerGroup, ContainerImage, ContainerNode, ContainerProject, ContainerReplicator, ExtManagementSystem, Host, PhysicalServer, Vm", "klass": "Api::BadRequestError" } } Additional info: Active Record Inclusion Validations: https://guides.rubyonrails.org/active_record_validations.html#inclusion
Upstream PR: https://github.com/ManageIQ/manageiq/pull/18338
Upstream PR merged. Commit message: - Explicitly set the inclusion whitelist as part of the error message when creating a policy with an invalid 'towhat' value to clarify the expectation, particularly when creating via the API. - Modify supportive spec which tests the validity of the policy record.
FIXED. Verified on 5.11.0.2.20190430174828_0e34dea,
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-2019:4199