-
Notifications
You must be signed in to change notification settings - Fork 342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added catch for missing POST body when posted to profileparameters #7194
Added catch for missing POST body when posted to profileparameters #7194
Conversation
… and added change into changelog.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
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: ''
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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