pomerium/internal/handlers/well_known_pomerium_test.go
Caleb Doxsey 1dee325b72
authorize: move sign out and jwks urls to route, update issuer for JWT (#4046)
* authorize: move sign out and jwks urls to route, update issuer for JWT

* fix test
2023-03-08 12:40:15 -07:00

35 lines
1.1 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", "GET")
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, `{
"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())
})
}