...

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

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

     1  //go:build integration
     2  
     3  package integration
     4  
     5  import (
     6  	"io"
     7  	"net/http"
     8  	"testing"
     9  
    10  	"github.com/letsencrypt/boulder/test"
    11  )
    12  
    13  // TestWFECORS is a small integration test that checks that the
    14  // Access-Control-Allow-Origin header is returned for a GET request to the
    15  // directory endpoint that has an Origin request header of "*".
    16  func TestWFECORS(t *testing.T) {
    17  	// Construct a GET request with an Origin header to sollicit an
    18  	// Access-Control-Allow-Origin response header.
    19  	getReq, _ := http.NewRequest("GET", "http://boulder.service.consul:4001/directory", nil)
    20  	getReq.Header.Set("Origin", "*")
    21  
    22  	// Performing the GET should return status 200.
    23  	client := &http.Client{}
    24  	resp, err := client.Do(getReq)
    25  	test.AssertNotError(t, err, "GET directory")
    26  	test.AssertEquals(t, resp.StatusCode, http.StatusOK)
    27  
    28  	// We expect that the response has the correct Access-Control-Allow-Origin
    29  	// header.
    30  	corsAllowOrigin := resp.Header.Get("Access-Control-Allow-Origin")
    31  	test.AssertEquals(t, corsAllowOrigin, "*")
    32  }
    33  
    34  // TestWFEHTTPMetrics verifies that the measured_http metrics we collect
    35  // for boulder-wfe and boulder-wfe2 are being properly collected. In order
    36  // to initialize the prometheus metrics we make a call to the /directory
    37  // endpoint before checking the /metrics endpoint.
    38  func TestWFEHTTPMetrics(t *testing.T) {
    39  	// Check boulder-wfe2
    40  	resp, err := http.Get("http://boulder.service.consul:4001/directory")
    41  	test.AssertNotError(t, err, "GET boulder-wfe2 directory")
    42  	test.AssertEquals(t, resp.StatusCode, http.StatusOK)
    43  	resp.Body.Close()
    44  
    45  	resp, err = http.Get("http://boulder.service.consul:8013/metrics")
    46  	test.AssertNotError(t, err, "GET boulder-wfe2 metrics")
    47  	test.AssertEquals(t, resp.StatusCode, http.StatusOK)
    48  	body, err := io.ReadAll(resp.Body)
    49  	test.AssertNotError(t, err, "Reading boulder-wfe2 metrics response")
    50  	test.AssertContains(t, string(body), `response_time_count{code="200",endpoint="/directory",method="GET"}`)
    51  	resp.Body.Close()
    52  }
    53  

View as plain text