Skip to content

Commit 4dcb267

Browse files
authored
sa: Fix modelToOrder to populate V2Authorizations from Authzs column (#8514)
In 978877a35 ("Store authzIDs directly in order table"), the modelToOrder function was updated to decode the new Authzs protobuf column, but the decoded values were never assigned to the order's V2Authorizations field. This caused the StoreAuthzsInOrders feature to not work correctly for reads. The bug meant that even with StoreAuthzsInOrders enabled: 1. Reads always fell back to querying the orderToAuthz2 table 2. The Authzs blob was parsed but the result was discarded 3. Eventually dropping orderToAuthz2 would break all order reads The fix assigns the decoded authz IDs to V2Authorizations, allowing orders with the new column populated to skip the fallback query. Also adds TestModelToOrderAuthzs to verify the fix and prevent regression.
1 parent 16cfacd commit 4dcb267

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

sa/model.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,14 @@ func modelToOrder(om *orderModel) (*corepb.Order, error) {
364364
if om.Replaces != nil {
365365
replaces = *om.Replaces
366366
}
367+
var v2Authorizations []int64
367368
if len(om.Authzs) > 0 {
368369
var decodedAuthzs sapb.Authzs
369370
err := proto.Unmarshal(om.Authzs, &decodedAuthzs)
370371
if err != nil {
371372
return nil, err
372373
}
374+
v2Authorizations = decodedAuthzs.AuthzIDs
373375
}
374376
order := &corepb.Order{
375377
Id: om.ID,
@@ -380,6 +382,7 @@ func modelToOrder(om *orderModel) (*corepb.Order, error) {
380382
BeganProcessing: om.BeganProcessing,
381383
CertificateProfileName: profile,
382384
Replaces: replaces,
385+
V2Authorizations: v2Authorizations,
383386
}
384387
if len(om.Error) > 0 {
385388
var problem corepb.ProblemDetails

sa/model_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ import (
1111
"fmt"
1212
"math/big"
1313
"net/netip"
14+
"slices"
1415
"testing"
1516
"time"
1617

1718
"github.com/jmhodges/clock"
19+
"google.golang.org/protobuf/proto"
1820
"google.golang.org/protobuf/types/known/timestamppb"
1921

2022
"github.com/letsencrypt/boulder/db"
2123
"github.com/letsencrypt/boulder/grpc"
2224
"github.com/letsencrypt/boulder/identifier"
2325
"github.com/letsencrypt/boulder/probs"
26+
sapb "github.com/letsencrypt/boulder/sa/proto"
2427
"github.com/letsencrypt/boulder/test/vars"
2528

2629
"github.com/letsencrypt/boulder/core"
@@ -223,6 +226,42 @@ func TestModelToOrderBadJSON(t *testing.T) {
223226
test.AssertEquals(t, string(badJSONErr.json), string(badJSON))
224227
}
225228

229+
// TestModelToOrderAuthzs tests that the Authzs field is properly decoded and
230+
// assigned to V2Authorizations.
231+
func TestModelToOrderAuthzs(t *testing.T) {
232+
expectedAuthzIDs := []int64{1, 2, 3, 42}
233+
encodedAuthzs, err := proto.Marshal(&sapb.Authzs{AuthzIDs: expectedAuthzIDs})
234+
test.AssertNotError(t, err, "failed to marshal authzs")
235+
236+
testCases := []struct {
237+
name string
238+
model *orderModel
239+
expectedAuthzIDs []int64
240+
}{
241+
{
242+
name: "with authzs",
243+
model: &orderModel{Authzs: encodedAuthzs},
244+
expectedAuthzIDs: expectedAuthzIDs,
245+
},
246+
{
247+
name: "without authzs",
248+
model: &orderModel{},
249+
expectedAuthzIDs: nil,
250+
},
251+
}
252+
for _, tc := range testCases {
253+
t.Run(tc.name, func(t *testing.T) {
254+
order, err := modelToOrder(tc.model)
255+
if err != nil {
256+
t.Fatalf("modelToOrder(%v) = %s, want success", tc.model, err)
257+
}
258+
if !slices.Equal(order.V2Authorizations, tc.expectedAuthzIDs) {
259+
t.Errorf("modelToOrder(%v) = %v, want %v", tc.model, order.V2Authorizations, tc.expectedAuthzIDs)
260+
}
261+
})
262+
}
263+
}
264+
226265
// TestPopulateAttemptedFieldsBadJSON tests that populating a challenge from an
227266
// authz2 model with an invalid validation error or an invalid validation record
228267
// produces the expected bad JSON error.

0 commit comments

Comments
 (0)