Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 0 additions & 149 deletions cmd/thv-operator/controllers/mcpserver_authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,155 +18,6 @@ import (
"github.com/stacklok/toolhive/pkg/container/kubernetes"
)

func TestGenerateAuthzArgs(t *testing.T) {
t.Parallel()

scheme := runtime.NewScheme()
require.NoError(t, mcpv1alpha1.AddToScheme(scheme))
require.NoError(t, corev1.AddToScheme(scheme))

tests := []struct {
name string
mcpServer *mcpv1alpha1.MCPServer
configMaps []corev1.ConfigMap
expectedArgs []string
}{
{
name: "no authz config",
mcpServer: &mcpv1alpha1.MCPServer{
ObjectMeta: metav1.ObjectMeta{
Name: "test-server",
Namespace: "test-namespace",
},
Spec: mcpv1alpha1.MCPServerSpec{
Image: "test-image",
},
},
expectedArgs: nil,
},
{
name: "configmap authz config",
mcpServer: &mcpv1alpha1.MCPServer{
ObjectMeta: metav1.ObjectMeta{
Name: "test-server",
Namespace: "test-namespace",
},
Spec: mcpv1alpha1.MCPServerSpec{
Image: "test-image",
AuthzConfig: &mcpv1alpha1.AuthzConfigRef{
Type: mcpv1alpha1.AuthzConfigTypeConfigMap,
ConfigMap: &mcpv1alpha1.ConfigMapAuthzRef{
Name: "test-authz-config",
Key: "authz.json",
},
},
},
},
configMaps: []corev1.ConfigMap{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-authz-config",
Namespace: "test-namespace",
},
Data: map[string]string{
"authz.json": `{
"version": "1.0",
"type": "cedarv1",
"cedar": {
"policies": ["permit(principal, action == Action::\"call_tool\", resource == Tool::\"weather\");"],
"entities_json": "[]"
}
}`,
},
},
},
expectedArgs: []string{"--authz-config=/etc/toolhive/authz/authz.json"},
},
{
name: "inline authz config",
mcpServer: &mcpv1alpha1.MCPServer{
ObjectMeta: metav1.ObjectMeta{
Name: "test-server",
Namespace: "test-namespace",
},
Spec: mcpv1alpha1.MCPServerSpec{
Image: "test-image",
AuthzConfig: &mcpv1alpha1.AuthzConfigRef{
Type: mcpv1alpha1.AuthzConfigTypeInline,
Inline: &mcpv1alpha1.InlineAuthzConfig{
Policies: []string{
`permit(principal, action == Action::"call_tool", resource == Tool::"weather");`,
`permit(principal, action == Action::"get_prompt", resource == Prompt::"greeting");`,
},
EntitiesJSON: "[]",
},
},
},
},
expectedArgs: []string{"--authz-config=/etc/toolhive/authz/authz.json"},
},
{
name: "configmap authz config with default key",
mcpServer: &mcpv1alpha1.MCPServer{
ObjectMeta: metav1.ObjectMeta{
Name: "test-server",
Namespace: "test-namespace",
},
Spec: mcpv1alpha1.MCPServerSpec{
Image: "test-image",
AuthzConfig: &mcpv1alpha1.AuthzConfigRef{
Type: mcpv1alpha1.AuthzConfigTypeConfigMap,
ConfigMap: &mcpv1alpha1.ConfigMapAuthzRef{
Name: "test-authz-config",
// Key not specified, should default to "authz.json"
},
},
},
},
configMaps: []corev1.ConfigMap{
{
ObjectMeta: metav1.ObjectMeta{
Name: "test-authz-config",
Namespace: "test-namespace",
},
Data: map[string]string{
"authz.json": `{
"version": "1.0",
"type": "cedarv1",
"cedar": {
"policies": ["permit(principal, action, resource);"],
"entities_json": "[]"
}
}`,
},
},
},
expectedArgs: []string{"--authz-config=/etc/toolhive/authz/authz.json"},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

// Create fake client with ConfigMaps
objects := []runtime.Object{tt.mcpServer}
for i := range tt.configMaps {
objects = append(objects, &tt.configMaps[i])
}
fakeClient := fake.NewClientBuilder().
WithScheme(scheme).
WithRuntimeObjects(objects...).
Build()

reconciler := newTestMCPServerReconciler(fakeClient, scheme, kubernetes.PlatformKubernetes)

args := reconciler.generateAuthzArgs(tt.mcpServer)
assert.Equal(t, tt.expectedArgs, args)
})
}
}

func TestEnsureAuthzConfigMap(t *testing.T) {
t.Parallel()

Expand Down
Loading
Loading