Fix bad-key-revoker select (#4806)

Adds a missing LIMIT, and adds a test case that catches the previous problem.
This commit is contained in:
Roland Bracewell Shoemaker 2020-05-07 13:05:20 -07:00 committed by GitHub
parent 97390560a3
commit 087e91934d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -69,7 +69,10 @@ func (bkr *badKeyRevoker) selectUncheckedKey() (uncheckedBlockedKey, error) {
var row uncheckedBlockedKey
err := bkr.dbMap.SelectOne(
&row,
"SELECT keyHash, revokedBy FROM blockedKeys WHERE extantCertificatesChecked = false",
`SELECT keyHash, revokedBy
FROM blockedKeys
WHERE extantCertificatesChecked = false
LIMIT 1`,
)
return row, err
}

View File

@ -59,12 +59,13 @@ func TestSelectUncheckedRows(t *testing.T) {
bkr := &badKeyRevoker{dbMap: dbMap}
hashA, hashB := randHash(t), randHash(t)
hashA, hashB, hashC := randHash(t), randHash(t), randHash(t)
insertBlockedRow(t, dbMap, hashA, 1, true)
row, err := bkr.selectUncheckedKey()
test.AssertError(t, err, "selectUncheckedKey didn't fail with no rows to process")
test.Assert(t, db.IsNoRows(err), "returned error is not sql.ErrNoRows")
insertBlockedRow(t, dbMap, hashB, 1, false)
insertBlockedRow(t, dbMap, hashC, 1, false)
row, err = bkr.selectUncheckedKey()
test.AssertNotError(t, err, "selectUncheckKey failed")
test.AssertByteEquals(t, row.KeyHash, hashB)