Skip to content

Commit a33c4ba

Browse files
committed
test(golang): store the query profile's score in the live PostgreSQL test
QueryProfile gained a sealed Score field, and the live test's table had no column for it, so decrypting a fetched row failed on a missing ciphertext. The table stores the score and its ORE term, and the rows read back carry both. Claude-Session: https://claude.ai/code/session_01BZhkvKLpNtKuzj3HCfMXoL
1 parent a0ca6a7 commit a33c4ba

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

‎languages/golang/encrypt/postgres_test.go‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ func TestQueriesRunAgainstPostgres(t *testing.T) {
6161
age_eq bytea NOT NULL,
6262
age_ore bytea NOT NULL,
6363
name bytea NOT NULL,
64-
name_match bytea NOT NULL
64+
name_match bytea NOT NULL,
65+
score bytea NOT NULL,
66+
score_ore bytea NOT NULL
6567
)`,
6668
matchPositions,
6769
} {
@@ -74,7 +76,7 @@ func TestQueriesRunAgainstPostgres(t *testing.T) {
7476
var people []testusers.QueryProfile
7577
for i, v := range f.Verify.Values {
7678
if v != nil {
77-
people = append(people, testusers.QueryProfile{Email: "p" + string(rune('a'+i)) + "@example.com", Age: uint32(20 + i), Name: *v})
79+
people = append(people, testusers.QueryProfile{Email: "p" + string(rune('a'+i)) + "@example.com", Age: uint32(20 + i), Name: *v, Score: float64(i) - 1.5})
7880
}
7981
}
8082
encrypted, err := testusers.EncryptQueryProfile(ctx, cipher, people)
@@ -83,8 +85,8 @@ func TestQueriesRunAgainstPostgres(t *testing.T) {
8385
}
8486
for i, e := range encrypted {
8587
if _, err := conn.ExecContext(ctx,
86-
`INSERT INTO profiles VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`,
87-
i, e.Email.Ciphertext, e.Email.Equality, e.Age.Ciphertext, e.Age.Equality, e.Age.Ore, e.Name.Ciphertext, e.Name.Match,
88+
`INSERT INTO profiles VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`,
89+
i, e.Email.Ciphertext, e.Email.Equality, e.Age.Ciphertext, e.Age.Equality, e.Age.Ore, e.Name.Ciphertext, e.Name.Match, e.Score.Ciphertext, e.Score.Ore,
8890
); err != nil {
8991
t.Fatal(err)
9092
}
@@ -121,7 +123,7 @@ func TestQueriesRunAgainstPostgres(t *testing.T) {
121123
t.Fatal("a field declared with tags has no expected token count, so with no histogram the limit is unbounded")
122124
}
123125
result, err := conn.QueryContext(ctx, `
124-
SELECT id, email, email_eq, age, age_eq, age_ore, name, name_match FROM profiles
126+
SELECT id, email, email_eq, age, age_eq, age_ore, name, name_match, score, score_ore FROM profiles
125127
WHERE pg_temp.match_positions(name_match) @> pg_temp.match_positions($1)
126128
ORDER BY id LIMIT $2`, q, limit.FetchOr(50))
127129
if err != nil {
@@ -134,7 +136,7 @@ func TestQueriesRunAgainstPostgres(t *testing.T) {
134136
var fetched []testusers.EncryptedQueryProfile
135137
for result.Next() {
136138
var e testusers.EncryptedQueryProfile
137-
if err := result.Scan(&id, &e.Email.Ciphertext, &e.Email.Equality, &e.Age.Ciphertext, &e.Age.Equality, &e.Age.Ore, &e.Name.Ciphertext, &e.Name.Match); err != nil {
139+
if err := result.Scan(&id, &e.Email.Ciphertext, &e.Email.Equality, &e.Age.Ciphertext, &e.Age.Equality, &e.Age.Ore, &e.Name.Ciphertext, &e.Name.Match, &e.Score.Ciphertext, &e.Score.Ore); err != nil {
138140
t.Fatal(err)
139141
}
140142
ids = append(ids, id)

0 commit comments

Comments
 (0)