proxy: add userinfo and webauthn endpoints (#3755)

* proxy: add userinfo and webauthn endpoints

* use TLD for RP id

* use EffectiveTLDPlusOne

* upgrade webauthn

* fix test

* Update internal/handlers/jwks.go

Co-authored-by: bobby <1544881+desimone@users.noreply.github.com>

Co-authored-by: bobby <1544881+desimone@users.noreply.github.com>
This commit is contained in:
Caleb Doxsey 2022-11-22 10:26:35 -07:00 committed by GitHub
parent 81053ac8ef
commit c1a522cd82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 498 additions and 216 deletions

View file

@ -5,42 +5,11 @@ import (
"math"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
)
func TestHealthCheck(t *testing.T) {
t.Parallel()
tests := []struct {
name string
method string
wantStatus int
}{
{"good - Get", http.MethodGet, http.StatusOK},
{"good - Head", http.MethodHead, http.StatusOK},
{"bad - Options", http.MethodOptions, http.StatusMethodNotAllowed},
{"bad - Put", http.MethodPut, http.StatusMethodNotAllowed},
{"bad - Post", http.MethodPost, http.StatusMethodNotAllowed},
{"bad - route miss", http.MethodGet, http.StatusOK},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := httptest.NewRequest(tt.method, "/", nil)
w := httptest.NewRecorder()
HealthCheck(w, r)
if w.Code != tt.wantStatus {
t.Errorf("code differs. got %d want %d body: %s", w.Code, tt.wantStatus, w.Body.String())
}
})
}
}
func TestRedirect(t *testing.T) {
t.Parallel()
tests := []struct {
@ -150,30 +119,3 @@ func TestRenderJSON(t *testing.T) {
})
}
}
func TestJWKSHandler(t *testing.T) {
t.Parallel()
t.Run("cors", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodOptions, "/", nil)
r.Header.Set("Origin", "https://www.example.com")
r.Header.Set("Access-Control-Request-Method", "GET")
JWKSHandler("").ServeHTTP(w, r)
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
})
}
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")
WellKnownPomeriumHandler(authenticateURL).ServeHTTP(w, r)
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
})
}