mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-29 06:29:19 +02:00
## Summary Some test improvements: - disable the race detector on macos, which currently results in a ton of linking errors, and I think doing race detection on linux is sufficient to find stuff - add build tags to the `integration` folder so it's not included by default when running `go test ./...` - remove some unused stuff in the Makefile - change the file `testenv` searches for from `.git` to `go.mod` which allows test caching to work more reliably - remove the test for orphaned connections in postgres. It doesn't actually make sense because we have listener connections in the background. I think it was racy. - fix yarn caching ## Checklist - [ ] reference any related issues - [x] updated unit tests - [x] add appropriate label (`enhancement`, `bug`, `breaking`, `dependencies`, `ci`) - [x] ready for review
86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDashboard(t *testing.T) {
|
|
ctx, clearTimeout := context.WithTimeout(t.Context(), time.Second*30)
|
|
defer clearTimeout()
|
|
|
|
t.Run("user dashboard", func(t *testing.T) {
|
|
testHTTPClient(t, func(t *testing.T, client *http.Client) {
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://authenticate.localhost.pomerium.io/.pomerium/", 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()
|
|
|
|
body, _ := io.ReadAll(res.Body)
|
|
|
|
assert.Equal(t, http.StatusFound, res.StatusCode, "unexpected status code: %s", body)
|
|
})
|
|
})
|
|
t.Run("dashboard strict slash redirect", func(t *testing.T) {
|
|
testHTTPClient(t, func(t *testing.T, client *http.Client) {
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "https://authenticate.localhost.pomerium.io/.pomerium", 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, 3, res.StatusCode/100, "unexpected status code")
|
|
})
|
|
})
|
|
}
|
|
|
|
func TestHealth(t *testing.T) {
|
|
ctx, clearTimeout := context.WithTimeout(t.Context(), time.Second*30)
|
|
defer clearTimeout()
|
|
|
|
pomeriumRoutes := []string{
|
|
"https://authenticate.localhost.pomerium.io",
|
|
"https://httpdetails.localhost.pomerium.io",
|
|
"https://restricted-httpdetails.localhost.pomerium.io",
|
|
}
|
|
endpoints := []string{"healthz", "ping"}
|
|
|
|
for _, route := range pomeriumRoutes {
|
|
for _, endpoint := range endpoints {
|
|
routeToCheck := fmt.Sprintf("%s/%s", route, endpoint)
|
|
t.Run(routeToCheck, func(t *testing.T) {
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, routeToCheck, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
res, err := getClient(t, false).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")
|
|
})
|
|
}
|
|
}
|
|
}
|