Skip to content

Commit 59bab8b

Browse files
authored
Make core.Registration.CreatedAt a *time.Time (letsencrypt#5422)
* Make core.Registration.CreatedAt a *time.time Fixes: letsencrypt#5421
1 parent b01be46 commit 59bab8b

File tree

10 files changed

+32
-20
lines changed

10 files changed

+32
-20
lines changed

core/objects.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ type Registration struct {
137137
InitialIP net.IP `json:"initialIp"`
138138

139139
// CreatedAt is the time the registration was created.
140-
CreatedAt time.Time `json:"createdAt"`
140+
CreatedAt *time.Time `json:"createdAt,omitempty"`
141141

142142
Status AcmeStatus `json:"status"`
143143
}

grpc/pb-marshalling.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,18 @@ func RegistrationToPB(reg core.Registration) (*corepb.Registration, error) {
229229
if reg.Contact != nil {
230230
contacts = *reg.Contact
231231
}
232+
var createdAt int64
233+
if reg.CreatedAt != nil {
234+
createdAt = reg.CreatedAt.UTC().UnixNano()
235+
}
232236
return &corepb.Registration{
233237
Id: reg.ID,
234238
Key: keyBytes,
235239
Contact: contacts,
236240
ContactsPresent: contactsPresent,
237241
Agreement: reg.Agreement,
238242
InitialIP: ipBytes,
239-
CreatedAt: reg.CreatedAt.UnixNano(),
243+
CreatedAt: createdAt,
240244
Status: string(reg.Status),
241245
}, nil
242246
}
@@ -252,6 +256,11 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) {
252256
if err != nil {
253257
return core.Registration{}, err
254258
}
259+
var createdAt *time.Time
260+
if pb.CreatedAt != 0 {
261+
c := time.Unix(0, pb.CreatedAt).UTC()
262+
createdAt = &c
263+
}
255264
var contacts *[]string
256265
if pb.ContactsPresent {
257266
if len(pb.Contact) != 0 {
@@ -272,7 +281,7 @@ func PbToRegistration(pb *corepb.Registration) (core.Registration, error) {
272281
Contact: contacts,
273282
Agreement: pb.Agreement,
274283
InitialIP: initialIP,
275-
CreatedAt: time.Unix(0, pb.CreatedAt),
284+
CreatedAt: createdAt,
276285
Status: core.AcmeStatus(pb.Status),
277286
}, nil
278287
}
@@ -322,7 +331,7 @@ func PBToAuthz(pb *corepb.Authorization) (core.Authorization, error) {
322331
}
323332

324333
func newRegistrationValid(reg *corepb.Registration) bool {
325-
return !(len(reg.Key) == 0 || len(reg.InitialIP) == 0 || reg.CreatedAt == 0)
334+
return !(len(reg.Key) == 0 || len(reg.InitialIP) == 0)
326335
}
327336

328337
func registrationValid(reg *corepb.Registration) bool {

grpc/pb-marshalling_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,14 @@ func TestRegistration(t *testing.T) {
159159
}
160160
`), &key)
161161
test.AssertNotError(t, err, "Could not unmarshal testing key")
162+
createdAt := time.Now().Round(0).UTC()
162163
inReg := core.Registration{
163164
ID: 1,
164165
Key: &key,
165166
Contact: &contacts,
166167
Agreement: "yup",
167168
InitialIP: net.ParseIP("1.1.1.1"),
168-
CreatedAt: time.Now().Round(0),
169+
CreatedAt: &createdAt,
169170
Status: core.StatusValid,
170171
}
171172
pbReg, err := RegistrationToPB(inReg)

mocks/mocks.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ func (sa *StorageAuthority) GetRegistration(_ context.Context, id int64) (core.R
138138
}
139139

140140
goodReg.InitialIP = net.ParseIP("5.6.7.8")
141-
goodReg.CreatedAt = time.Date(2003, 9, 27, 0, 0, 0, 0, time.UTC)
141+
createdAt := time.Date(2003, 9, 27, 0, 0, 0, 0, time.UTC)
142+
goodReg.CreatedAt = &createdAt
142143
return goodReg, nil
143144
}
144145

sa/model.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,19 @@ func registrationToModel(r *core.Registration) (*regModel, error) {
202202
if r.Contact == nil {
203203
r.Contact = &[]string{}
204204
}
205+
var createdAt time.Time
206+
if r.CreatedAt != nil {
207+
createdAt = *r.CreatedAt
208+
}
209+
205210
rm := regModel{
206211
ID: r.ID,
207212
Key: key,
208213
KeySHA256: sha,
209214
Contact: *r.Contact,
210215
Agreement: r.Agreement,
211216
InitialIP: []byte(r.InitialIP.To16()),
212-
CreatedAt: r.CreatedAt,
217+
CreatedAt: createdAt,
213218
Status: string(r.Status),
214219
}
215220

@@ -241,7 +246,7 @@ func modelToRegistration(reg *regModel) (core.Registration, error) {
241246
Contact: contact,
242247
Agreement: reg.Agreement,
243248
InitialIP: net.IP(reg.InitialIP),
244-
CreatedAt: reg.CreatedAt,
249+
CreatedAt: &reg.CreatedAt,
245250
Status: core.AcmeStatus(reg.Status),
246251
}
247252

sa/sa.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,8 @@ func (ssa *SQLStorageAuthority) GetCertificateStatus(ctx context.Context, serial
338338

339339
// NewRegistration stores a new Registration
340340
func (ssa *SQLStorageAuthority) NewRegistration(ctx context.Context, reg core.Registration) (core.Registration, error) {
341-
reg.CreatedAt = ssa.clk.Now()
341+
createdAt := ssa.clk.Now()
342+
reg.CreatedAt = &createdAt
342343
rm, err := registrationToModel(&reg)
343344
if err != nil {
344345
return reg, err

sa/sa_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,16 @@ func TestAddRegistration(t *testing.T) {
137137
dbReg, err := sa.GetRegistration(ctx, reg.ID)
138138
test.AssertNotError(t, err, fmt.Sprintf("Couldn't get registration with ID %v", reg.ID))
139139

140+
createdAt := clk.Now()
140141
expectedReg := core.Registration{
141142
ID: reg.ID,
142143
Key: jwk,
143144
InitialIP: net.ParseIP("43.34.43.34"),
144-
CreatedAt: clk.Now(),
145+
CreatedAt: &createdAt,
145146
}
146147
test.AssertEquals(t, dbReg.ID, expectedReg.ID)
147148
test.Assert(t, core.KeyDigestEquals(dbReg.Key, expectedReg.Key), "Stored key != expected")
149+
test.AssertDeepEquals(t, expectedReg.CreatedAt, dbReg.CreatedAt)
148150

149151
newReg := core.Registration{
150152
ID: reg.ID,

sa/satest/satest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ func GoodJWK() *jose.JSONWebKey {
4141
func CreateWorkingRegistration(t *testing.T, sa core.StorageAdder) core.Registration {
4242
contact := "mailto:foo@example.com"
4343
contacts := &[]string{contact}
44+
createdAt := time.Date(2003, 5, 10, 0, 0, 0, 0, time.UTC)
4445
reg, err := sa.NewRegistration(context.Background(), core.Registration{
4546
Key: GoodJWK(),
4647
Contact: contacts,
4748
InitialIP: net.ParseIP("88.77.66.11"),
48-
CreatedAt: time.Date(2003, 5, 10, 0, 0, 0, 0, time.UTC),
49+
CreatedAt: &createdAt,
4950
Status: core.StatusValid,
5051
})
5152
if err != nil {

wfe/wfe_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,7 +2537,6 @@ func TestDeactivateRegistration(t *testing.T) {
25372537
],
25382538
"agreement": "http://example.invalid/terms",
25392539
"initialIp": "",
2540-
"createdAt": "0001-01-01T00:00:00Z",
25412540
"status": "deactivated"
25422541
}`)
25432542

@@ -2558,7 +2557,6 @@ func TestDeactivateRegistration(t *testing.T) {
25582557
],
25592558
"agreement": "http://example.invalid/terms",
25602559
"initialIp": "",
2561-
"createdAt": "0001-01-01T00:00:00Z",
25622560
"status": "deactivated"
25632561
}`)
25642562

@@ -2648,7 +2646,6 @@ func TestKeyRollover(t *testing.T) {
26482646
],
26492647
"agreement": "http://example.invalid/terms",
26502648
"initialIp": "",
2651-
"createdAt": "0001-01-01T00:00:00Z",
26522649
"status": "valid"
26532650
}`,
26542651
},

wfe2/wfe_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,6 @@ func TestNewECDSAAccount(t *testing.T) {
13091309
"y": "S8rR-0dWa8nAcw1fbunF_ajS3PQZ-QwLps-2adgLgPk"
13101310
},
13111311
"initialIp": "",
1312-
"createdAt": "0001-01-01T00:00:00Z",
13131312
"status": ""
13141313
}`)
13151314
test.AssertEquals(t, responseWriter.Header().Get("Location"), "http://localhost/acme/acct/3")
@@ -1491,7 +1490,6 @@ func TestNewAccount(t *testing.T) {
14911490
"mailto:person@mail.com"
14921491
],
14931492
"initialIp": "",
1494-
"createdAt": "0001-01-01T00:00:00Z",
14951493
"status": "valid"
14961494
}`)
14971495
}
@@ -2325,7 +2323,6 @@ func TestDeactivateAccount(t *testing.T) {
23252323
"mailto:person@mail.com"
23262324
],
23272325
"initialIp": "",
2328-
"createdAt": "0001-01-01T00:00:00Z",
23292326
"status": "deactivated"
23302327
}`)
23312328

@@ -2346,7 +2343,6 @@ func TestDeactivateAccount(t *testing.T) {
23462343
"mailto:person@mail.com"
23472344
],
23482345
"initialIp": "",
2349-
"createdAt": "0001-01-01T00:00:00Z",
23502346
"status": "deactivated"
23512347
}`)
23522348

@@ -2419,7 +2415,7 @@ func TestNewOrder(t *testing.T) {
24192415
{
24202416
"type": "dns",
24212417
"value": "not-example.com"
2422-
}
2418+
}
24232419
]
24242420
}`
24252421

@@ -2745,7 +2741,6 @@ func TestKeyRollover(t *testing.T) {
27452741
"mailto:person@mail.com"
27462742
],
27472743
"initialIp": "",
2748-
"createdAt": "0001-01-01T00:00:00Z",
27492744
"status": "valid"
27502745
}`,
27512746
NewKey: newKeyPriv,

0 commit comments

Comments
 (0)