Added catch for missing POST body when posted to profileparameters#7194
Conversation
… and added change into changelog.md
kdamichie
left a comment
There was a problem hiding this comment.
Removed changed traffic-ops-test.conf. Accidentally commited
Added new line to end of file
…com:kdamichie/trafficcontrol into fix_profileparameters_internal_server_error
There was a problem hiding this comment.
The test cases here that claim to have empty bodies actually don't. Note that you can't fix that just by setting RequestBody to nil - nil marshals to null, not an empty request body. Sending an empty request may not be very easy to do using the same format as all the other tests. I don't think there's anything you can put in for RequestBody that will do what you want.
| ClientSession: TOSession, | ||
| RequestBody: []tc.ProfileParameter{{}}, | ||
| Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), | ||
| }, |
There was a problem hiding this comment.
This doesn't actually test the behavior being fixed in this PR. This a list of length 1 (not 0!) whose only element has the default/"zero" values for all of its properties. The result when Go marshals that is, accordingly, an array with one object element.
| ClientSession: TOSession, | ||
| RequestBody: map[string]interface{}{}, | ||
| Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), | ||
| }, |
There was a problem hiding this comment.
This doesn't actually test the behavior being fixed in this PR. Marshalling an empty map appropriately produces an empty object - not an empty request body!
| ClientSession: TOSession, | ||
| RequestBody: map[string]interface{}{}, | ||
| Expectations: utils.CkRequest(utils.HasError(), utils.HasStatus(http.StatusBadRequest)), | ||
| }, |
Actually, I take that back. It's actually fairly easy to create a type that marshals to an empty request body. Examplepackage main
import (
"encoding/json"
"fmt"
)
type emptyJSONTester struct{}
func (emptyJSONTester) MarshalJSON() ([]byte, error) {
return []byte{}, nil
}
func main() {
bts, _ := json.Marshal(emptyJSONTester{})
fmt.Printf("'%s'\n", string(bts))
// Output: ''
} |
srijeet0406
left a comment
There was a problem hiding this comment.
Code looks good. Manual and automated tests pass. Good work! :)
This PR closes #4428
Which Traffic Control components are affected by this PR?
What is the best way to verify this PR?
Make sure all of the tests pass
For manual testing, try to send a POST to the profileparameters with an empty body. The result should be a 400 error.
If this is a bugfix, which Traffic Control versions contained the bug?
-master
PR submission checklist