Skip to content

Commit

Permalink
fix check printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Geal committed Feb 18, 2022
1 parent 84eda43 commit a8e87f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions datalog/datalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,28 @@ func (d SymbolDebugger) Rule(r Rule) string {

var expressionsStart string
if len(expressions) > 0 {
expressionsStart = " @ "
expressionsStart = ", "
}

return fmt.Sprintf("*%s <- %s%s%s", head, strings.Join(preds, ", "), expressionsStart, strings.Join(expressions, ", "))
return fmt.Sprintf("%s <- %s%s%s", head, strings.Join(preds, ", "), expressionsStart, strings.Join(expressions, ", "))
}

func (d SymbolDebugger) CheckQuery(r Rule) string {
preds := make([]string, len(r.Body))
for i, p := range r.Body {
preds[i] = d.Predicate(p)
}
expressions := make([]string, len(r.Expressions))
for i, e := range r.Expressions {
expressions[i] = d.Expression(e)
}

var expressionsStart string
if len(expressions) > 0 {
expressionsStart = ", "
}

return fmt.Sprintf("%s%s%s", strings.Join(preds, ", "), expressionsStart, strings.Join(expressions, ", "))
}

func (d SymbolDebugger) Expression(e Expression) string {
Expand All @@ -687,9 +705,9 @@ func (d SymbolDebugger) Expression(e Expression) string {
func (d SymbolDebugger) Check(c Check) string {
queries := make([]string, len(c.Queries))
for i, q := range c.Queries {
queries[i] = d.Rule(q)
queries[i] = d.CheckQuery(q)
}
return strings.Join(queries, " || ")
return fmt.Sprintf("check if %s", strings.Join(queries, " or "))
}

func (d SymbolDebugger) World(w *World) string {
Expand Down
2 changes: 1 addition & 1 deletion samples/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestSample8_ScopedChecks(t *testing.T) {

verifier.AddPolicy(biscuit.DefaultAllowPolicy)
res:= verifier.Verify()
require.Equal(t, errors.New("biscuit: verification failed: failed to verify block #1 check #0: *check if resource($0), operation(#read), right($0, #read)"), res)
require.Equal(t, errors.New("biscuit: verification failed: failed to verify block #1 check #0: check if resource($0), operation(#read), right($0, #read)"), res)
})
}
}
Expand Down

0 comments on commit a8e87f7

Please sign in to comment.