The binding is read back from a jsonb column with a space after every colon, so an unchanged approved action failed the byte comparison and never ran.
This commit is contained in:
2 files changed
+24
No files matched your search
@@ -158,6 +158,9 @@ func recorded(a store.Action) (Binding, string) {
|
||||
if sum, err := stored.Digest(); err != nil || sum != a.BindingDigest {
|
||||
return Binding{}, "its binding is incomplete or was altered"
|
||||
}
|
||||
// The binding comes back from a jsonb column reformatted, so its input is
|
||||
// canonicalised again before it is compared byte for byte.
|
||||
stored.Input = connectors.Canonical(stored.Input)
|
||||
return stored, ""
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json/jsontext"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -236,6 +237,16 @@ func newApprovalFixture(t *testing.T) *approvalFixture {
|
||||
return f
|
||||
}
|
||||
|
||||
// reformatted returns raw with the whitespace jsonb puts back on output.
|
||||
func reformatted(t *testing.T, raw []byte) []byte {
|
||||
t.Helper()
|
||||
v := jsontext.Value(slices.Clone(raw))
|
||||
if err := v.Indent(jsontext.WithIndent(" ")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// TestRunApprovedRunsOnlyWhatWasApprovedAndOnlyOnce guards the dispatch-time
|
||||
// recheck: an approval is discarded, and nothing runs, when the owner has lost
|
||||
// access, when the target, effect, arguments or approvers changed, when the
|
||||
@@ -249,6 +260,16 @@ func TestRunApprovedRunsOnlyWhatWasApprovedAndOnlyOnce(t *testing.T) {
|
||||
wantDiscard string
|
||||
}{
|
||||
{name: "an action that still matches runs", wantRuns: 1},
|
||||
{
|
||||
// Postgres stores both columns as jsonb and hands them back
|
||||
// reformatted, with a space after every colon.
|
||||
name: "an action read back from jsonb still runs",
|
||||
change: func(f *approvalFixture) {
|
||||
f.action.Binding = reformatted(t, f.action.Binding)
|
||||
f.action.Decision = reformatted(t, f.action.Decision)
|
||||
},
|
||||
wantRuns: 1,
|
||||
},
|
||||
{
|
||||
name: "the owner's access revoked while pending",
|
||||
change: func(f *approvalFixture) { f.d.People = fakePeople{alice: person(alice, governance.RoleViewer)} },
|
||||
|
||||
Reference in new issue
Block a user