Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Commit

Permalink
Add validation checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmorn committed Jan 31, 2019
1 parent 820918b commit 682f734
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions remote/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func makePoliciesBlockHandler(s *store.SourceStore) http.HandlerFunc {
writeError(w, err, http.StatusBadRequest)
return
}
if payload.SourceID == "" {
writeError(w, fmt.Errorf("validation error: source_id cannot be empty"), http.StatusBadRequest)
return
}

p := store.NewBlockPolicy(payload.Issuer, payload.SourceID)
p.Reason = payload.Reason
handlePolicy(s, p, w, r)
Expand Down Expand Up @@ -123,6 +128,14 @@ func makePoliciesReserveHandler(s *store.SourceStore) http.HandlerFunc {
writeError(w, err, http.StatusBadRequest)
return
}
if payload.SourceID == "" {
writeError(w, fmt.Errorf("validation error: source_id cannot be empty"), http.StatusBadRequest)
return
}
if payload.Target == "" {
writeError(w, fmt.Errorf("validation error: target cannot be empty"), http.StatusBadRequest)
return
}

p := store.NewReservedPolicy(payload.Issuer, payload.SourceID, payload.Target)
p.Reason = payload.Reason
Expand All @@ -138,6 +151,15 @@ func makePoliciesAvoidHandler(s *store.SourceStore) http.HandlerFunc {
writeError(w, err, http.StatusBadRequest)
return
}
if payload.SourceID == "" {
writeError(w, fmt.Errorf("validation error: source_id cannot be empty"), http.StatusBadRequest)
return
}
if payload.Target == "" {
writeError(w, fmt.Errorf("validation error: target cannot be empty"), http.StatusBadRequest)
return
}


p := store.NewAvoidPolicy(payload.Issuer, payload.SourceID, payload.Target)
p.Reason = payload.Reason
Expand Down

0 comments on commit 682f734

Please sign in to comment.