Feat: Add JWKS rotation API endpoint (#4463)

Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
This commit is contained in:
Dan Nicholls
2025-05-10 21:44:02 +10:00
committed by GitHub
parent defee1eed9
commit 7360981aa7
6 changed files with 191 additions and 25 deletions

View File

@@ -11,6 +11,7 @@ import (
"testing"
"time"
"github.com/bluenviron/mediamtx/internal/auth"
"github.com/bluenviron/mediamtx/internal/conf"
"github.com/bluenviron/mediamtx/internal/logger"
"github.com/bluenviron/mediamtx/internal/test"
@@ -718,3 +719,41 @@ func TestRecordingsDeleteSegment(t *testing.T) {
defer res.Body.Close()
require.Equal(t, http.StatusOK, res.StatusCode)
}
func TestAuthJWKSRefresh(t *testing.T) {
ok := false
api := API{
Address: "localhost:9997",
ReadTimeout: conf.Duration(10 * time.Second),
AuthManager: &test.AuthManager{
AuthenticateImpl: func(_ *auth.Request) error {
return nil
},
RefreshJWTJWKSImpl: func() {
ok = true
},
},
Parent: &testParent{},
}
err := api.Initialize()
require.NoError(t, err)
defer api.Close()
tr := &http.Transport{}
defer tr.CloseIdleConnections()
hc := &http.Client{Transport: tr}
u, err := url.Parse("http://localhost:9997/v3/auth/jwks/refresh")
require.NoError(t, err)
req, err := http.NewRequest(http.MethodPost, u.String(), nil)
require.NoError(t, err)
res, err := hc.Do(req)
require.NoError(t, err)
defer res.Body.Close()
require.Equal(t, http.StatusOK, res.StatusCode)
require.True(t, ok)
}