Skip to content

Commit 0d70b12

Browse files
authored
ra: fix unittest for resetting pause limit (#7813)
TestPerformValidation_FailedThenSuccessfulValidationResetsPauseIdentifiersRatelimit checks for a bucket being empty after a reset. However, that bucket is based on an account ID that is shared across multiple test cases. Instead, use a unique account and domain for this test. Fixes #7812
1 parent c39f33e commit 0d70b12

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

ra/ra_test.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ import (
7070
vapb "github.com/letsencrypt/boulder/va/proto"
7171
)
7272

73+
// randomDomain creates a random domain name for testing.
74+
//
75+
// panics if crypto/rand.Rand.Read fails.
76+
func randomDomain() string {
77+
var bytes [4]byte
78+
_, err := rand.Read(bytes[:])
79+
if err != nil {
80+
panic(err)
81+
}
82+
return fmt.Sprintf("%x.example.com", bytes[:])
83+
}
84+
7385
func createPendingAuthorization(t *testing.T, sa sapb.StorageAuthorityClient, domain string, exp time.Time) *corepb.Authorization {
7486
t.Helper()
7587

@@ -928,7 +940,7 @@ func TestPerformValidation_FailedValidationsTriggerPauseIdentifiersRatelimit(t *
928940
ra.txnBuilder = txnBuilder
929941

930942
// We know this is OK because of TestNewAuthorization
931-
domain := "example.net"
943+
domain := randomDomain()
932944
authzPB := createPendingAuthorization(t, sa, domain, fc.Now().Add(12*time.Hour))
933945
mockSA.registrationsForRegID[authzPB.RegistrationID] = Registration
934946
mockSA.authorizationsForRegID[authzPB.RegistrationID] = authzPB
@@ -1042,6 +1054,16 @@ func TestPerformValidation_FailedThenSuccessfulValidationResetsPauseIdentifiersR
10421054
features.Set(features.Config{AutomaticallyPauseZombieClients: true})
10431055
defer features.Reset()
10441056

1057+
// Because we're testing with a real Redis backend, we choose a different account ID
1058+
// than other tests to make we don't get interference from other tests using the same
1059+
// registration ID.
1060+
registration, err := sa.NewRegistration(ctx, &corepb.Registration{
1061+
Key: AccountKeyJSONC,
1062+
InitialIP: parseAndMarshalIP(t, "192.2.2.2"),
1063+
Status: string(core.StatusValid),
1064+
})
1065+
test.AssertNotError(t, err, "Failed to create registration")
1066+
10451067
mockSA := newMockSAPaused(sa)
10461068
ra.SA = mockSA
10471069

@@ -1051,8 +1073,9 @@ func TestPerformValidation_FailedThenSuccessfulValidationResetsPauseIdentifiersR
10511073
ra.txnBuilder = txnBuilder
10521074

10531075
// We know this is OK because of TestNewAuthorization
1054-
domain := "example.net"
1055-
authzPB := createPendingAuthorization(t, sa, "example.net", fc.Now().Add(12*time.Hour))
1076+
domain := randomDomain()
1077+
authzPB := createPendingAuthorization(t, sa, domain, fc.Now().Add(12*time.Hour))
1078+
authzPB.RegistrationID = registration.Id
10561079
mockSA.registrationsForRegID[authzPB.RegistrationID] = Registration
10571080
mockSA.authorizationsForRegID[authzPB.RegistrationID] = authzPB
10581081

@@ -1114,6 +1137,7 @@ func TestPerformValidation_FailedThenSuccessfulValidationResetsPauseIdentifiersR
11141137

11151138
// We know this is OK because of TestNewAuthorization
11161139
authzPB = createPendingAuthorization(t, sa, domain, fc.Now().Add(12*time.Hour))
1140+
authzPB.RegistrationID = registration.Id
11171141

11181142
va.PerformValidationRequestResultReturn = &vapb.ValidationResult{
11191143
Records: []*corepb.ValidationRecord{
@@ -3313,11 +3337,7 @@ func TestFinalizeOrderDisabledChallenge(t *testing.T) {
33133337
_, sa, ra, _, fc, cleanUp := initAuthorities(t)
33143338
defer cleanUp()
33153339

3316-
// Create a random domain
3317-
var bytes [3]byte
3318-
_, err := rand.Read(bytes[:])
3319-
test.AssertNotError(t, err, "creating test domain name")
3320-
domain := fmt.Sprintf("%x.example.com", bytes[:])
3340+
domain := randomDomain()
33213341

33223342
// Create a finalized authorization for that domain
33233343
authzID := createFinalizedAuthorization(

0 commit comments

Comments
 (0)