Skip to content

Commit

Permalink
fix: validate tuples for non-nil subject
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl authored and aeneasr committed Sep 14, 2022
1 parent 96ff767 commit a22dd19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions internal/relationtuple/transact_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ func (h *handler) createRelation(w http.ResponseWriter, r *http.Request, _ httpr
return
}

if err := rt.Validate(); err != nil {
h.d.Writer().WriteError(w, r, errors.WithStack(herodot.ErrBadRequest.WithError(err.Error())))
return
}

h.d.Logger().WithFields(rt.ToLoggerFields()).Debug("creating relation tuple")

it, err := h.d.Mapper().FromTuple(ctx, &rt)
Expand Down Expand Up @@ -221,6 +226,11 @@ func (h *handler) patchRelationTuples(w http.ResponseWriter, r *http.Request, _
h.d.Writer().WriteError(w, r, herodot.ErrBadRequest.WithError("relation_tuple is missing"))
return
}
if err := d.RelationTuple.Validate(); err != nil {
h.d.Writer().WriteError(w, r, errors.WithStack(herodot.ErrBadRequest.WithError(err.Error())))
return
}

switch d.Action {
case ketoapi.ActionInsert, ketoapi.ActionDelete:
default:
Expand Down
7 changes: 7 additions & 0 deletions ketoapi/public_api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ func (r *RelationTuple) ToLoggerFields() logrus.Fields {
return fields
}

func (r *RelationTuple) Validate() error {
if r.SubjectSet == nil && r.SubjectID == nil {
return ErrNilSubject
}
return nil
}

// swagger:enum ExpandNodeType
type ExpandNodeType TreeNodeType

Expand Down

0 comments on commit a22dd19

Please sign in to comment.