github.com/letsencrypt/boulder@v0.20251208.0/test/integration/wfe_test.go (about) 1 //go:build integration 2 3 package integration 4 5 import ( 6 "io" 7 "net/http" 8 "testing" 9 "time" 10 11 "github.com/letsencrypt/boulder/core" 12 "github.com/letsencrypt/boulder/test" 13 ) 14 15 // TestWFECORS is a small integration test that checks that the 16 // Access-Control-Allow-Origin header is returned for a GET request to the 17 // directory endpoint that has an Origin request header of "*". 18 func TestWFECORS(t *testing.T) { 19 // Construct a GET request with an Origin header to sollicit an 20 // Access-Control-Allow-Origin response header. 21 getReq, _ := http.NewRequest("GET", "http://boulder.service.consul:4001/directory", nil) 22 getReq.Header.Set("Origin", "*") 23 24 // Performing the GET should return status 200. 25 client := &http.Client{} 26 resp, err := client.Do(getReq) 27 test.AssertNotError(t, err, "GET directory") 28 test.AssertEquals(t, resp.StatusCode, http.StatusOK) 29 30 // We expect that the response has the correct Access-Control-Allow-Origin 31 // header. 32 corsAllowOrigin := resp.Header.Get("Access-Control-Allow-Origin") 33 test.AssertEquals(t, corsAllowOrigin, "*") 34 } 35 36 // TestWFEHTTPMetrics verifies that the measured_http metrics we collect 37 // for boulder-wfe and boulder-wfe2 are being properly collected. In order 38 // to initialize the prometheus metrics we make a call to the /directory 39 // endpoint before checking the /metrics endpoint. 40 func TestWFEHTTPMetrics(t *testing.T) { 41 // Check boulder-wfe2 42 resp, err := http.Get("http://boulder.service.consul:4001/directory") 43 test.AssertNotError(t, err, "GET boulder-wfe2 directory") 44 test.AssertEquals(t, resp.StatusCode, http.StatusOK) 45 resp.Body.Close() 46 47 resp, err = http.Get("http://boulder.service.consul:8013/metrics") 48 test.AssertNotError(t, err, "GET boulder-wfe2 metrics") 49 test.AssertEquals(t, resp.StatusCode, http.StatusOK) 50 body, err := io.ReadAll(resp.Body) 51 test.AssertNotError(t, err, "Reading boulder-wfe2 metrics response") 52 test.AssertContains(t, string(body), `response_time_count{code="200",endpoint="/directory",method="GET"}`) 53 resp.Body.Close() 54 } 55 56 // TestWFEHealthz checks to make sure that the /health endpoint returns 200 OK, 57 // retrying in case overrides take a moment to load. 58 func TestWFEHealthz(t *testing.T) { 59 retries := 0 60 var status int 61 for retries < 5 { 62 time.Sleep(core.RetryBackoff(retries, time.Millisecond*2, time.Millisecond*50, 2)) 63 resp, err := http.Get("http://boulder.service.consul:4001/healthz") 64 test.AssertNotError(t, err, "GET boulder-wfe2 healthz") 65 status = resp.StatusCode 66 resp.Body.Close() 67 if status == http.StatusOK { 68 break 69 } 70 retries++ 71 } 72 test.AssertEquals(t, status, http.StatusOK) 73 }