Verify Path params that fall into the string bucket are supplied (#17032)

This commit is contained in:
Ian Cubbon
2023-11-12 20:02:33 -07:00
committed by GitHub
parent ec3c484ce9
commit c9f7af752f
7 changed files with 52 additions and 0 deletions

View File

@@ -76,6 +76,10 @@ func (c *StoreAPIController) Routes() Routes {
// DeleteOrder - Delete purchase order by ID
func (c *StoreAPIController) DeleteOrder(w http.ResponseWriter, r *http.Request) {
orderIdParam := chi.URLParam(r, "orderId")
if orderIdParam == "" {
c.errorHandler(w, r, &RequiredError{"orderId"}, nil)
return
}
result, err := c.service.DeleteOrder(r.Context(), orderIdParam)
// If an error occurred, encode the error with the status code
if err != nil {

View File

@@ -174,6 +174,10 @@ func (c *UserAPIController) CreateUsersWithListInput(w http.ResponseWriter, r *h
func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
usernameParam := chi.URLParam(r, "username")
if usernameParam == "" {
c.errorHandler(w, r, &RequiredError{"username"}, nil)
return
}
booleanTestParam, err := parseBoolParameter(
query.Get("boolean_test"),
WithParse[bool](parseBool),
@@ -195,6 +199,10 @@ func (c *UserAPIController) DeleteUser(w http.ResponseWriter, r *http.Request) {
// GetUserByName - Get user by user name
func (c *UserAPIController) GetUserByName(w http.ResponseWriter, r *http.Request) {
usernameParam := chi.URLParam(r, "username")
if usernameParam == "" {
c.errorHandler(w, r, &RequiredError{"username"}, nil)
return
}
result, err := c.service.GetUserByName(r.Context(), usernameParam)
// If an error occurred, encode the error with the status code
if err != nil {
@@ -243,6 +251,10 @@ func (c *UserAPIController) LogoutUser(w http.ResponseWriter, r *http.Request) {
// UpdateUser - Updated user
func (c *UserAPIController) UpdateUser(w http.ResponseWriter, r *http.Request) {
usernameParam := chi.URLParam(r, "username")
if usernameParam == "" {
c.errorHandler(w, r, &RequiredError{"username"}, nil)
return
}
userParam := User{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()