...

Source file src/github.com/letsencrypt/boulder/test/integration/authz_test.go

Documentation: github.com/letsencrypt/boulder/test/integration

     1  //go:build integration
     2  
     3  package integration
     4  
     5  import (
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/letsencrypt/boulder/test"
    10  )
    11  
    12  const (
    13  	// validAuthorizationLifetime is the expected valid authorization lifetime. It
    14  	// should match the value in the RA config's "authorizationLifetimeDays"
    15  	// configuration field.
    16  	validAuthorizationLifetime = 30
    17  )
    18  
    19  // TestValidAuthzExpires checks that a valid authorization has the expected
    20  // expires time.
    21  func TestValidAuthzExpires(t *testing.T) {
    22  	t.Parallel()
    23  	c, err := makeClient()
    24  	test.AssertNotError(t, err, "makeClient failed")
    25  
    26  	// Issue for a random domain
    27  	domains := []string{random_domain()}
    28  	result, err := authAndIssue(c, nil, domains, true)
    29  	// There should be no error
    30  	test.AssertNotError(t, err, "authAndIssue failed")
    31  	// The order should be valid
    32  	test.AssertEquals(t, result.Order.Status, "valid")
    33  	// There should be one authorization URL
    34  	test.AssertEquals(t, len(result.Order.Authorizations), 1)
    35  
    36  	// Fetching the authz by URL shouldn't fail
    37  	authzURL := result.Order.Authorizations[0]
    38  	authzOb, err := c.FetchAuthorization(c.Account, authzURL)
    39  	test.AssertNotError(t, err, "FetchAuthorization failed")
    40  
    41  	// The authz should be valid and for the correct identifier
    42  	test.AssertEquals(t, authzOb.Status, "valid")
    43  	test.AssertEquals(t, authzOb.Identifier.Value, domains[0])
    44  
    45  	// The authz should have the expected expiry date, plus or minus a minute
    46  	expectedExpiresMin := time.Now().AddDate(0, 0, validAuthorizationLifetime).Add(-time.Minute)
    47  	expectedExpiresMax := expectedExpiresMin.Add(2 * time.Minute)
    48  	actualExpires := authzOb.Expires
    49  	if actualExpires.Before(expectedExpiresMin) || actualExpires.After(expectedExpiresMax) {
    50  		t.Errorf("Wrong expiry. Got %s, expected it to be between %s and %s",
    51  			actualExpires, expectedExpiresMin, expectedExpiresMax)
    52  	}
    53  }
    54  

View as plain text