envoy: verify helathcheck enpoints (#725)

* envoy: verify helathcheck enpoints
Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2020-05-19 08:35:19 -07:00 committed by GitHub
parent ca499ac9be
commit c85b12a137
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"net/http"
"testing"
"time"
@ -54,24 +55,35 @@ func TestHealth(t *testing.T) {
ctx := mainCtx
ctx, clearTimeout := context.WithTimeout(ctx, time.Second*30)
defer clearTimeout()
for _, endpoint := range []string{"healthz", "ping"} {
endpoint := endpoint
t.Run(endpoint, func(t *testing.T) {
client := testcluster.NewHTTPClient()
req, err := http.NewRequestWithContext(ctx, "GET", "https://restricted-httpdetails.localhost.pomerium.io/"+endpoint, nil)
if err != nil {
t.Fatal(err)
}
res, err := client.Do(req)
if !assert.NoError(t, err, "unexpected http error") {
return
}
defer res.Body.Close()
assert.Equal(t, http.StatusOK, res.StatusCode, "unexpected status code")
})
pomeriumRoutes := []string{
"https://authenticate.localhost.pomerium.io",
"https://forward-authenticate.localhost.pomerium.io",
"https://httpdetails.localhost.pomerium.io",
"https://restricted-httpdetails.localhost.pomerium.io",
}
endpoints := []string{"healthz", "ping"}
for _, route := range pomeriumRoutes {
route := route
for _, endpoint := range endpoints {
endpoint := endpoint
routeToCheck := fmt.Sprintf("%s/%s", route, endpoint)
t.Run(routeToCheck, func(t *testing.T) {
client := testcluster.NewHTTPClient()
req, err := http.NewRequestWithContext(ctx, "GET", routeToCheck, nil)
if err != nil {
t.Fatal(err)
}
res, err := client.Do(req)
if !assert.NoError(t, err, "unexpected http error") {
return
}
defer res.Body.Close()
assert.Equal(t, http.StatusOK, res.StatusCode, "unexpected status code")
})
}
}
}