Skip to content

Commit

Permalink
Fix flaky test failure from the inexorable forward march of time (#7090)
Browse files Browse the repository at this point in the history
People assume that time is a strict progression of cause to effect, but
actually, from a nonlinear, non-subjective viewpoint, it's more like a
big ball of wibbly-wobbly, timey-wimey... stuff.
  • Loading branch information
aarongable authored Sep 18, 2023
1 parent 3b880e1 commit 6ce2ee3
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions precert/corr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func derFromPEMFile(filename string) ([]byte, error) {
}

func TestMismatches(t *testing.T) {
now := time.Now()

issuerKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -128,8 +130,8 @@ func TestMismatches(t *testing.T) {

precertTemplate := x509.Certificate{
SerialNumber: big.NewInt(3141592653589793238),
NotBefore: time.Now(),
NotAfter: time.Now().Add(24 * time.Hour),
NotBefore: now,
NotAfter: now.Add(24 * time.Hour),
DNSNames: []string{"example.com"},
ExtraExtensions: []pkix.Extension{
{
Expand All @@ -150,8 +152,8 @@ func TestMismatches(t *testing.T) {
t.Helper()
finalCertTemplate := &x509.Certificate{
SerialNumber: big.NewInt(3141592653589793238),
NotBefore: time.Now(),
NotAfter: time.Now().Add(24 * time.Hour),
NotBefore: now,
NotAfter: now.Add(24 * time.Hour),
DNSNames: []string{"example.com"},
ExtraExtensions: []pkix.Extension{
{
Expand Down Expand Up @@ -183,8 +185,8 @@ func TestMismatches(t *testing.T) {
// not in the same position
precertTemplate2 := x509.Certificate{
SerialNumber: big.NewInt(3141592653589793238),
NotBefore: time.Now(),
NotAfter: time.Now().Add(24 * time.Hour),
NotBefore: now,
NotAfter: now.Add(24 * time.Hour),
DNSNames: []string{"example.com"},
ExtraExtensions: []pkix.Extension{
{
Expand Down Expand Up @@ -262,7 +264,7 @@ func TestMismatches(t *testing.T) {

// Expect failure with mismatched NotBefore
finalCertDER = makeFinalCert(func(c *x509.Certificate) {
c.NotBefore = time.Now().Add(24 * time.Hour)
c.NotBefore = now.Add(24 * time.Hour)
})

err = Correspond(precertDER, finalCertDER)
Expand All @@ -272,7 +274,7 @@ func TestMismatches(t *testing.T) {

// Expect failure with mismatched NotAfter
finalCertDER = makeFinalCert(func(c *x509.Certificate) {
c.NotAfter = time.Now().Add(48 * time.Hour)
c.NotAfter = now.Add(48 * time.Hour)
})
err = Correspond(precertDER, finalCertDER)
if err == nil {
Expand Down

0 comments on commit 6ce2ee3

Please sign in to comment.