Skip to content
Draft
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
68 changes: 68 additions & 0 deletions pkg/mcp/resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,74 @@ func (s *ResourcesSuite) TestResourcesScale() {
})
}

func (s *ResourcesSuite) TestResourcesScaleDenied() {
s.Require().NoError(toml.Unmarshal([]byte(`
denied_resources = [
{ group = "apps", version = "v1", kind = "Deployment" },
{ group = "apps", version = "v1", kind = "StatefulSet" }
]
`), s.Cfg), "Expected to parse denied resources config")
s.InitMcpClient()
s.Run("resources_scale get (denied by kind)", func() {
deniedByKind, err := s.CallTool("resources_scale", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"namespace": "default",
"name": "deployment",
})
s.Run("has error", func() {
s.Truef(deniedByKind.IsError, "call tool should fail")
s.Nilf(err, "call tool should not return error object")
})
s.Run("describes denial", func() {
msg := deniedByKind.Content[0].(mcp.TextContent).Text
s.Contains(msg, "resource not allowed:")
expectedMessage := "failed to get/update resource scale:(.+:)? resource not allowed: apps/v1, Kind=Deployment"
s.Regexpf(expectedMessage, msg,
"expected descriptive error '%s', got %v", expectedMessage, deniedByKind.Content[0].(mcp.TextContent).Text)
})
})
s.Run("resources_scale update (denied by kind)", func() {
deniedByKind, err := s.CallTool("resources_scale", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"namespace": "default",
"name": "deployment",
"scale": 5,
})
s.Run("has error", func() {
s.Truef(deniedByKind.IsError, "call tool should fail")
s.Nilf(err, "call tool should not return error object")
})
s.Run("describes denial", func() {
msg := deniedByKind.Content[0].(mcp.TextContent).Text
s.Contains(msg, "resource not allowed:")
expectedMessage := "failed to get/update resource scale:(.+:)? resource not allowed: apps/v1, Kind=Deployment"
s.Regexpf(expectedMessage, msg,
"expected descriptive error '%s', got %v", expectedMessage, deniedByKind.Content[0].(mcp.TextContent).Text)
})
})
s.Run("resources_scale (denied by group)", func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manusa I'm not sure what the difference here with the (denied by group) is vs. the (denied by kind) test case above - as far as I can tell we are not allowing the StatefulSet kind in the config, so this one is also denied by kind?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was fully implemented by Claude. It probably messed up, I'll review better tomorrow.

deniedByGroup, err := s.CallTool("resources_scale", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "StatefulSet",
"namespace": "default",
"name": "nonexistent-statefulset",
})
s.Run("has error", func() {
s.Truef(deniedByGroup.IsError, "call tool should fail")
s.Nilf(err, "call tool should not return error object")
})
s.Run("describes denial", func() {
msg := deniedByGroup.Content[0].(mcp.TextContent).Text
s.Contains(msg, "resource not allowed:")
expectedMessage := "failed to get/update resource scale:(.+:)? resource not allowed: apps/v1, Kind=StatefulSet"
s.Regexpf(expectedMessage, msg,
"expected descriptive error '%s', got %v", expectedMessage, deniedByGroup.Content[0].(mcp.TextContent).Text)
})
})
}

func TestResources(t *testing.T) {
suite.Run(t, new(ResourcesSuite))
}