mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-29 02:16:28 +02:00
move hpke public key handler out of internal (#4065)
This commit is contained in:
parent
6e39ebc189
commit
ccf15f8f3d
6 changed files with 15 additions and 9 deletions
|
@ -20,8 +20,8 @@ import (
|
||||||
"github.com/pomerium/pomerium/authorize/internal/store"
|
"github.com/pomerium/pomerium/authorize/internal/store"
|
||||||
"github.com/pomerium/pomerium/config"
|
"github.com/pomerium/pomerium/config"
|
||||||
"github.com/pomerium/pomerium/internal/atomicutil"
|
"github.com/pomerium/pomerium/internal/atomicutil"
|
||||||
"github.com/pomerium/pomerium/internal/handlers"
|
|
||||||
"github.com/pomerium/pomerium/internal/testutil"
|
"github.com/pomerium/pomerium/internal/testutil"
|
||||||
|
hpke_handlers "github.com/pomerium/pomerium/pkg/hpke/handlers"
|
||||||
"github.com/pomerium/pomerium/pkg/policy/criteria"
|
"github.com/pomerium/pomerium/pkg/policy/criteria"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func TestAuthorize_handleResult(t *testing.T) {
|
||||||
hpkePrivateKey, err := opt.GetHPKEPrivateKey()
|
hpkePrivateKey, err := opt.GetHPKEPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
authnSrv := httptest.NewServer(handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()))
|
authnSrv := httptest.NewServer(hpke_handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()))
|
||||||
t.Cleanup(authnSrv.Close)
|
t.Cleanup(authnSrv.Close)
|
||||||
opt.AuthenticateURLString = authnSrv.URL
|
opt.AuthenticateURLString = authnSrv.URL
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ func TestRequireLogin(t *testing.T) {
|
||||||
hpkePrivateKey, err := opt.GetHPKEPrivateKey()
|
hpkePrivateKey, err := opt.GetHPKEPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
authnSrv := httptest.NewServer(handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()))
|
authnSrv := httptest.NewServer(hpke_handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()))
|
||||||
t.Cleanup(authnSrv.Close)
|
t.Cleanup(authnSrv.Close)
|
||||||
opt.AuthenticateURLString = authnSrv.URL
|
opt.AuthenticateURLString = authnSrv.URL
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/pomerium/pomerium/internal/telemetry"
|
"github.com/pomerium/pomerium/internal/telemetry"
|
||||||
"github.com/pomerium/pomerium/internal/telemetry/requestid"
|
"github.com/pomerium/pomerium/internal/telemetry/requestid"
|
||||||
"github.com/pomerium/pomerium/internal/urlutil"
|
"github.com/pomerium/pomerium/internal/urlutil"
|
||||||
|
hpke_handlers "github.com/pomerium/pomerium/pkg/hpke/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (srv *Server) addHTTPMiddleware(root *mux.Router, cfg *config.Config) {
|
func (srv *Server) addHTTPMiddleware(root *mux.Router, cfg *config.Config) {
|
||||||
|
@ -70,6 +71,6 @@ func (srv *Server) mountCommonEndpoints(root *mux.Router, cfg *config.Config) er
|
||||||
root.Handle("/.well-known/pomerium", handlers.WellKnownPomerium(authenticateURL))
|
root.Handle("/.well-known/pomerium", handlers.WellKnownPomerium(authenticateURL))
|
||||||
root.Handle("/.well-known/pomerium/", handlers.WellKnownPomerium(authenticateURL))
|
root.Handle("/.well-known/pomerium/", handlers.WellKnownPomerium(authenticateURL))
|
||||||
root.Path("/.well-known/pomerium/jwks.json").Methods(http.MethodGet).Handler(handlers.JWKSHandler(signingKey))
|
root.Path("/.well-known/pomerium/jwks.json").Methods(http.MethodGet).Handler(handlers.JWKSHandler(signingKey))
|
||||||
root.Path(urlutil.HPKEPublicKeyPath).Methods(http.MethodGet).Handler(handlers.HPKEPublicKeyHandler(hpkePublicKey))
|
root.Path(urlutil.HPKEPublicKeyPath).Methods(http.MethodGet).Handler(hpke_handlers.HPKEPublicKeyHandler(hpkePublicKey))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Package handlers provides http handlers for HPKE.
|
||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -11,9 +12,13 @@ import (
|
||||||
"github.com/rs/cors"
|
"github.com/rs/cors"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/internal/httputil"
|
"github.com/pomerium/pomerium/internal/httputil"
|
||||||
|
"github.com/pomerium/pomerium/internal/urlutil"
|
||||||
"github.com/pomerium/pomerium/pkg/hpke"
|
"github.com/pomerium/pomerium/pkg/hpke"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HPKEPublicKeyPath is the path to the HPKE public key.
|
||||||
|
const HPKEPublicKeyPath = urlutil.HPKEPublicKeyPath
|
||||||
|
|
||||||
// HPKEPublicKeyHandler returns a handler which returns the HPKE public key.
|
// HPKEPublicKeyHandler returns a handler which returns the HPKE public key.
|
||||||
func HPKEPublicKeyHandler(publicKey *hpke.PublicKey) http.Handler {
|
func HPKEPublicKeyHandler(publicKey *hpke.PublicKey) http.Handler {
|
||||||
return cors.AllowAll().Handler(httputil.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
return cors.AllowAll().Handler(httputil.HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
|
|
@ -7,8 +7,8 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/internal/handlers"
|
|
||||||
"github.com/pomerium/pomerium/pkg/hpke"
|
"github.com/pomerium/pomerium/pkg/hpke"
|
||||||
|
"github.com/pomerium/pomerium/pkg/hpke/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHPKEPublicKeyHandler(t *testing.T) {
|
func TestHPKEPublicKeyHandler(t *testing.T) {
|
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/internal/handlers"
|
|
||||||
"github.com/pomerium/pomerium/pkg/hpke"
|
"github.com/pomerium/pomerium/pkg/hpke"
|
||||||
|
hpke_handlers "github.com/pomerium/pomerium/pkg/hpke/handlers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFetchPublicKeyFromJWKS(t *testing.T) {
|
func TestFetchPublicKeyFromJWKS(t *testing.T) {
|
||||||
|
@ -24,7 +24,7 @@ func TestFetchPublicKeyFromJWKS(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()).ServeHTTP(w, r)
|
hpke_handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()).ServeHTTP(w, r)
|
||||||
}))
|
}))
|
||||||
t.Cleanup(srv.Close)
|
t.Cleanup(srv.Close)
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/config"
|
"github.com/pomerium/pomerium/config"
|
||||||
"github.com/pomerium/pomerium/internal/handlers"
|
hpke_handlers "github.com/pomerium/pomerium/pkg/hpke/handlers"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,7 @@ func testOptions(t *testing.T) *config.Options {
|
||||||
hpkePrivateKey, err := opts.GetHPKEPrivateKey()
|
hpkePrivateKey, err := opts.GetHPKEPrivateKey()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
authnSrv := httptest.NewServer(handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()))
|
authnSrv := httptest.NewServer(hpke_handlers.HPKEPublicKeyHandler(hpkePrivateKey.PublicKey()))
|
||||||
t.Cleanup(authnSrv.Close)
|
t.Cleanup(authnSrv.Close)
|
||||||
opts.AuthenticateURLString = authnSrv.URL
|
opts.AuthenticateURLString = authnSrv.URL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue