fix(memory): refuse a credential written out in prose (#2069)
A note saying "the deploy token is 1234567890abcdef" was neither redacted nor refused, because the credential check only recognised a value after a colon or an equals sign. The copula now counts as the separator, so a credential written out in a sentence is refused the way an assignment is. The version read is scoped to the organisation as every other note read is, so a note id from another organisation answers nothing, and the doc comments on Forget and Revoke describe the order the code actually commits in. The deletion-recording schema constant had no consumer and is removed.
This commit is contained in:
7 files changed
+135
-31
No files matched your search
@@ -95,8 +95,19 @@ func (f *noteFake) Owned(_ context.Context, orgID, owner, class string, _ int) (
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (f *noteFake) Correct(_ context.Context, _, _ string, _ uuid.UUID, _ string) (store.Note, bool, error) {
|
||||
return store.Note{}, false, f.fail
|
||||
// Correct mirrors the statement store.Correct runs: only the owner's own note
|
||||
// of that id is corrected.
|
||||
func (f *noteFake) Correct(_ context.Context, _, owner string, id uuid.UUID, text string) (store.Note, bool, error) {
|
||||
if f.fail != nil {
|
||||
return store.Note{}, false, f.fail
|
||||
}
|
||||
for i, n := range f.added {
|
||||
if n.ID == id && n.OwnerID == owner && n.Scope == string(ScopePerson) {
|
||||
f.added[i].Text = text
|
||||
return f.added[i], true, nil
|
||||
}
|
||||
}
|
||||
return store.Note{}, false, nil
|
||||
}
|
||||
|
||||
func (f *noteFake) SetDisabled(_ context.Context, _, owner string, id uuid.UUID, disabled bool) (bool, error) {
|
||||
@@ -156,7 +167,7 @@ func (f *noteFake) Publish(_ context.Context, _ string, id uuid.UUID, _ string)
|
||||
return store.Note{}, false, nil
|
||||
}
|
||||
|
||||
func (f *noteFake) Versions(context.Context, uuid.UUID) ([]store.Version, error) {
|
||||
func (f *noteFake) Versions(context.Context, string, uuid.UUID) ([]store.Version, error) {
|
||||
return nil, f.fail
|
||||
}
|
||||
|
||||
@@ -269,8 +280,9 @@ func TestRememberRedactsASecretShapedValue(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestNotesReadsForTheActingPerson guards the read boundary: a turn reads the
|
||||
// facts of the person it serves, plus the ones published to the org, and never
|
||||
// another person's note or a proposal nobody has published.
|
||||
// facts of the person it serves plus the ones published to the org, and nothing
|
||||
// else. The store also holds another person's note, an unpublished proposal and
|
||||
// a note in no scope at all, none of which either read may return.
|
||||
func TestNotesReadsForTheActingPerson(t *testing.T) {
|
||||
notes := ¬eFake{}
|
||||
m := newNotes(t, notes, &deletionFake{})
|
||||
@@ -286,10 +298,16 @@ func TestNotesReadsForTheActingPerson(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
proposal, err := m.Propose(t.Context(), "bob", "a fact nobody has published")
|
||||
if err != nil {
|
||||
if _, err := m.Propose(t.Context(), "bob", "a fact nobody has published"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// A row no writer in this package produces, so the only thing standing
|
||||
// between it and a reader is the scope filter itself.
|
||||
scopeless := store.Note{
|
||||
ID: uuid.New(), Class: string(ClassDurableFact), State: string(StatePublished),
|
||||
OwnerID: "alice", Purpose: purposeChat, Text: "a note in no scope",
|
||||
}
|
||||
notes.added = append(notes.added, scopeless)
|
||||
cases := []struct {
|
||||
name string
|
||||
owner string
|
||||
@@ -314,9 +332,6 @@ func TestNotesReadsForTheActingPerson(t *testing.T) {
|
||||
if !slices.Equal(ids, want) {
|
||||
t.Fatalf("%s read %v, want %v", tc.owner, ids, want)
|
||||
}
|
||||
if slices.Contains(ids, proposal.ID.String()) {
|
||||
t.Fatalf("%s read the unpublished proposal %s", tc.owner, proposal.ID)
|
||||
}
|
||||
})
|
||||
}
|
||||
if _, err := m.Notes(t.Context(), "", ClassDurableFact); !errors.Is(err, ErrInvalidNote) {
|
||||
|
||||
Reference in new issue
Block a user