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