[auth] make id-token optional (#97831)
make idtoken optional enure there is always an identity in the context fix: update token fix: now it should work fix: now it should work
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package resource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/authlib/claims"
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIDTokenExtractor(t *testing.T) {
|
||||
t.Run("should return an error when no claims found", func(t *testing.T) {
|
||||
token, err := idTokenExtractor(context.Background())
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, token)
|
||||
})
|
||||
t.Run("should return an empty token for static requester of type service account as grafana admin ", func(t *testing.T) {
|
||||
ctx := identity.WithRequester(context.Background(), &identity.StaticRequester{
|
||||
Type: claims.TypeServiceAccount,
|
||||
IsGrafanaAdmin: true,
|
||||
})
|
||||
token, err := idTokenExtractor(ctx)
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, token)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user