Files
grafana/pkg/services/apiserver/service_test.go
Tania 67a952c34e Implement OFREP compatible feature flag service (#105632)
* Add ofrep pkg

* api server: Use namespace from request in case user is not authenticated

* Add handlers to ofrep api builder

* Add NewOpenFeatureService to initialize mt apiserver

* allow specifying CA and insecure

* Compare namespace with eval ctx stackID

* Organize ofrep package

* Implement AllowedV0Alpha1Resources

* Revert folderimpl changes

* Handle default namespace

* Fix extracting stack id from eval ctx

* Add more logs

* Update pkg/registry/apis/ofrep/register.go

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Update pkg/registry/apis/ofrep/register.go

Co-authored-by: Dave Henderson <dave.henderson@grafana.com>

* Apply review feedback

* Replace contexthandler with types

* Fix identifying authed request

* Refactor checks in the handlers

* Remove anonymous from isAuthenticatedRequest check

---------

Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com>
Co-authored-by: Gabriel Mabille <gabriel.mabille@grafana.com>
Co-authored-by: Charandas Batra <charandas.batra@grafana.com>
Co-authored-by: Dave Henderson <dave.henderson@grafana.com>
2025-06-27 18:30:38 +02:00

52 lines
1.2 KiB
Go

package apiserver
import (
"testing"
"github.com/grafana/grafana/pkg/services/user"
"github.com/stretchr/testify/require"
)
func Test_useNamespaceFromPath(t *testing.T) {
tests := []struct {
name string
path string
expNs string
}{
{
name: "no namespace in path",
path: "/apis/folder.grafana.app/",
expNs: "",
},
{
name: "namespace in path",
path: "/apis/folder.grafana.app/v1alpha1/namespaces/stacks-11/folders",
expNs: "stacks-11",
},
{
name: "invalid namespace in path",
path: "/apis/folder.grafana.app/v1alpha1/namespaces/invalid/folders",
expNs: "invalid",
},
{
name: "org namespace in path",
path: "/apis/folder.grafana.app/v1alpha1/namespaces/org-123/folders",
expNs: "org-123",
},
{
name: "default namespace in path",
path: "/apis/folder.grafana.app/v1alpha1/namespaces/default/folders",
expNs: "default",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
user := &user.SignedInUser{}
useNamespaceFromPath(tt.path, user)
if user.Namespace != tt.expNs {
require.Equal(t, tt.expNs, user.Namespace, "expected namespace to be %s, got %s", tt.expNs, user.Namespace)
}
})
}
}