pomerium/internal/handlers/well_known_pomerium_test.go
Joe Kralicky 5464cda90e
Add an 'issuer' field to the /.well-known/pomerium endpoint (#5344)
The field contains the route's base uri, including the https:// scheme
and ending with a trailing slash.
2024-10-25 13:07:57 -04:00

36 lines
1.2 KiB
Go

package handlers
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestWellKnownPomeriumHandler(t *testing.T) {
t.Parallel()
t.Run("cors", func(t *testing.T) {
authenticateURL, _ := url.Parse("https://authenticate.example.com")
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodOptions, "/", nil)
r.Header.Set("Origin", authenticateURL.String())
r.Header.Set("Access-Control-Request-Method", http.MethodGet)
WellKnownPomerium(authenticateURL).ServeHTTP(w, r)
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
})
t.Run("links", func(t *testing.T) {
authenticateURL, _ := url.Parse("https://authenticate.example.com")
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "https://route.example.com", nil)
WellKnownPomerium(authenticateURL).ServeHTTP(w, r)
assert.JSONEq(t, `{
"issuer": "https://route.example.com/",
"authentication_callback_endpoint": "https://authenticate.example.com/oauth2/callback",
"frontchannel_logout_uri": "https://route.example.com/.pomerium/sign_out",
"jwks_uri": "https://route.example.com/.well-known/pomerium/jwks.json"
}`, w.Body.String())
})
}