mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? Add `file://` URI support to `jwtKeyProvider.keySourceURIs`, so JWKS can be loaded directly from disk without running an HTTP server. ## Why? Easier to test JWT key provider locally, when you don't need to spin up a sidecar HTTP server. ## How did you test it? - [X] built - [X] run locally and tested manually - [ ] covered by existing tests - [X] added new unit test(s) - [ ] added new functional test(s) ## Potential risks Safe, as this is an additive change and http.Get would have failed on file:// schema with `unsupported protocol scheme "file"`.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package authorization
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.temporal.io/server/common/log"
|
|
)
|
|
|
|
func TestOpenURI_FileScheme(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "test.json")
|
|
require.NoError(t, os.WriteFile(path, []byte(`{"keys":[]}`), 0644))
|
|
|
|
provider := &defaultTokenKeyProvider{logger: log.NewNoopLogger()}
|
|
|
|
r, err := provider.openURI("file://" + path)
|
|
require.NoError(t, err)
|
|
require.NoError(t, r.Close())
|
|
}
|
|
|
|
func TestOpenURI_FileScheme_Localhost(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "test.json")
|
|
require.NoError(t, os.WriteFile(path, []byte(`{"keys":[]}`), 0644))
|
|
|
|
provider := &defaultTokenKeyProvider{logger: log.NewNoopLogger()}
|
|
|
|
r, err := provider.openURI("file://localhost" + path)
|
|
require.NoError(t, err)
|
|
require.NoError(t, r.Close())
|
|
}
|
|
|
|
func TestOpenURI_FileScheme_RemoteHost(t *testing.T) {
|
|
provider := &defaultTokenKeyProvider{logger: log.NewNoopLogger()}
|
|
|
|
_, err := provider.openURI("file://remotehost/tmp/test.json")
|
|
require.ErrorContains(t, err, "remote host")
|
|
}
|
|
|
|
func TestOpenURI_FileScheme_NotFound(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "nonexistent.json")
|
|
|
|
provider := &defaultTokenKeyProvider{logger: log.NewNoopLogger()}
|
|
|
|
_, err := provider.openURI("file://" + path)
|
|
require.Error(t, err)
|
|
}
|