Skip to content

Commit bf38e17

Browse files
authored
test(go): the two plan rules NewPlan leaves to the record call are refused there
cipherstash-bot, on PR #1093: NewPlan documents two rules it leaves to the call — every field under one table, no two fields under one label — and no Go test showed the call refusing them. One does now, on an uninitialised guest: both plans build, and EncryptRecords and DecryptRecord each refuse them as ErrEncoding before looking for a cipher. If the guest's refusal ever stops being the caller's input, this is the test that says so. Claude-Session: https://claude.ai/code/session_01V3WFXwax4J3uecpFEJ6yHc
1 parent e0c0a04 commit bf38e17

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

‎languages/golang/stackencrypt/guest_test.go‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,46 @@ func TestGuestRefusesMalformedInputsBeforeState(t *testing.T) {
762762
}
763763
}
764764

765+
// NewPlan leaves two rules to the record call: every field under one table
766+
// (the label's leading segments), and no two fields under one label. The
767+
// guest's lowering refuses both at parse, before it looks for a cipher, as
768+
// the caller's input (ErrEncoding), on the write and on the read.
769+
func TestGuestRefusesAPlanNewPlanLeavesToTheCall(t *testing.T) {
770+
ctx := context.Background()
771+
c := rawInstance(t)
772+
type row struct {
773+
Age uint32
774+
Email string
775+
}
776+
record := EncryptedRecord{
777+
"Age": {Ciphertext: Sealed(fixtureLeaf)},
778+
"Email": {Ciphertext: Sealed(fixtureLeaf)},
779+
}
780+
for name, fields := range map[string][]FieldPlan{
781+
"two tables": {
782+
{Field: "Age", Context: label(t, "users/age").Context()},
783+
{Field: "Email", Context: label(t, "accounts/email").Context()},
784+
},
785+
"one label twice": {
786+
{Field: "Age", Context: label(t, "users/age").Context(), Terms: []TermKind{Equality}},
787+
{Field: "Email", Context: label(t, "users/age").Context(), Terms: []TermKind{Equality}},
788+
},
789+
} {
790+
p, err := NewPlan(fields...)
791+
if err != nil {
792+
t.Fatalf("%s: NewPlan refused it: %v", name, err)
793+
}
794+
_, err = c.DefaultKeyset().EncryptRecords(ctx, []row{{Age: 1, Email: "a@b.c"}}, WithPlan(p))
795+
if !errors.Is(err, ErrEncoding) {
796+
t.Errorf("%s: EncryptRecords err = %v, want ErrEncoding", name, err)
797+
}
798+
var out row
799+
if err := c.DecryptRecord(ctx, record, &out, WithPlan(p)); !errors.Is(err, ErrEncoding) {
800+
t.Errorf("%s: DecryptRecord err = %v, want ErrEncoding", name, err)
801+
}
802+
}
803+
}
804+
765805
// A bad ExtendContext part fails the call for that reason, on the probe and
766806
// on both record directions. TestGuestRefusesMalformedInputsBeforeState
767807
// shows the call never reaches the cipher, but a call that ignored the

0 commit comments

Comments
 (0)