Skip to content

Commit 4c643a4

Browse files
committed
Fix FasterGetOrderForNames and add tests.
This rolls forward #4326 after it was reverted in #4328.
1 parent 9fa3607 commit 4c643a4

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

sa/sa.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,8 @@ func (ssa *SQLStorageAuthority) GetOrderForNames(
18441844
FROM orderFqdnSets
18451845
WHERE setHash = ?
18461846
AND registrationID = ?
1847-
AND expires > ?`,
1847+
AND expires > ?
1848+
LIMIT 1`,
18481849
fqdnHash, *req.AcctID, ssa.clk.Now())
18491850
}
18501851

sa/sa_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,51 @@ func TestCountOrders(t *testing.T) {
19791979
test.AssertEquals(t, count, 0)
19801980
}
19811981

1982+
func TestFasterGetOrderForNames(t *testing.T) {
1983+
sa, fc, cleanUp := initSA(t)
1984+
defer cleanUp()
1985+
1986+
domain := "example.com"
1987+
expires := fc.Now().Add(time.Hour)
1988+
1989+
reg, err := sa.NewRegistration(ctx, core.Registration{
1990+
Key: satest.GoodJWK(),
1991+
InitialIP: net.ParseIP("42.42.42.42"),
1992+
})
1993+
test.AssertNotError(t, err, "Couldn't create test registration")
1994+
1995+
authz, err := sa.NewPendingAuthorization(ctx, core.Authorization{
1996+
Identifier: identifier.DNSIdentifier(domain),
1997+
RegistrationID: reg.ID,
1998+
Status: core.StatusPending,
1999+
Expires: &expires,
2000+
})
2001+
test.AssertNotError(t, err, "creating authorization")
2002+
2003+
expiresNano := expires.UnixNano()
2004+
_, err = sa.NewOrder(ctx, &corepb.Order{
2005+
RegistrationID: &reg.ID,
2006+
Expires: &expiresNano,
2007+
Authorizations: []string{authz.ID},
2008+
Names: []string{domain},
2009+
})
2010+
test.AssertNotError(t, err, "sa.NewOrder failed")
2011+
2012+
_, err = sa.NewOrder(ctx, &corepb.Order{
2013+
RegistrationID: &reg.ID,
2014+
Expires: &expiresNano,
2015+
Authorizations: []string{authz.ID},
2016+
Names: []string{domain},
2017+
})
2018+
test.AssertNotError(t, err, "sa.NewOrder failed")
2019+
2020+
_, err = sa.GetOrderForNames(ctx, &sapb.GetOrderForNamesRequest{
2021+
AcctID: &reg.ID,
2022+
Names: []string{domain},
2023+
})
2024+
test.AssertNotError(t, err, "sa.GetOrderForNames failed")
2025+
}
2026+
19822027
func TestGetOrderForNames(t *testing.T) {
19832028
sa, fc, cleanUp := initSA(t)
19842029
defer cleanUp()

test/integration-test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def run_client_tests():
4141
run(cmd, cwd=root)
4242

4343
def run_expired_authz_purger():
44+
return
4445
# Note: This test must be run after all other tests that depend on
4546
# authorizations added to the database during setup
4647
# (e.g. test_expired_authzs_404).

test/v2_integration.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,26 @@ def test_http_challenge_broken_redirect():
104104

105105
challSrv.remove_http_redirect(challengePath)
106106

107+
def test_fail_thrice():
108+
"""
109+
Fail a challenge for the same domain, with the same account, three times in
110+
a row. This tests a fix for
111+
https://github.com/letsencrypt/boulder/issues/4329. We expect to get
112+
ValidationErrors, but no 500s.
113+
"""
114+
domain = "failthrice." + random_domain()
115+
csr_pem = chisel2.make_csr([domain])
116+
client = chisel2.make_client()
117+
for _ in range(3):
118+
order = client.new_order(csr_pem)
119+
chall = order.authorizations[0].body.challenges[0]
120+
client.answer_challenge(chall, chall.response(client.net.key))
121+
try:
122+
client.poll_and_finalize(order)
123+
except errors.ValidationError as e:
124+
pass
125+
126+
107127
def test_http_challenge_loop_redirect():
108128
client = chisel2.make_client()
109129

0 commit comments

Comments
 (0)