mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-31 01:47:33 +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
34
pkg/hpke/handlers/hpke_public_key_test.go
Normal file
34
pkg/hpke/handlers/hpke_public_key_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package handlers_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/pomerium/pomerium/pkg/hpke"
|
||||
"github.com/pomerium/pomerium/pkg/hpke/handlers"
|
||||
)
|
||||
|
||||
func TestHPKEPublicKeyHandler(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
k1 := hpke.DerivePrivateKey([]byte("TEST"))
|
||||
|
||||
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")
|
||||
handlers.HPKEPublicKeyHandler(k1.PublicKey()).ServeHTTP(w, r)
|
||||
assert.Equal(t, http.StatusNoContent, w.Result().StatusCode)
|
||||
})
|
||||
t.Run("keys", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
r := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
handlers.HPKEPublicKeyHandler(k1.PublicKey()).ServeHTTP(w, r)
|
||||
|
||||
assert.Equal(t, k1.PublicKey().Bytes(), w.Body.Bytes())
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue