2024-12-17 19:28:00 +08:00
|
|
|
package resource
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2025-01-21 17:06:55 +08:00
|
|
|
|
|
|
|
|
claims "github.com/grafana/authlib/types"
|
|
|
|
|
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
2024-12-17 19:28:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
}
|