Skip to content

[quality] test: add 62 unit tests for gitops SSE + MCP security helpers#19565

Open
clubanderson wants to merge 2 commits into
mainfrom
quality/test-gitops-helpers
Open

[quality] test: add 62 unit tests for gitops SSE + MCP security helpers#19565
clubanderson wants to merge 2 commits into
mainfrom
quality/test-gitops-helpers

Conversation

@clubanderson

@clubanderson clubanderson commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Test Improvement

Adds 62 unit tests across two new test files for previously untested pure helper functions:

pkg/api/handlers/gitops/helpers_test.go (34 tests)

Function Tests Security
indexOf 10
replaceAll 9
jsonMarshal 6
writeSSEEvent 9 SSE frame injection prevention (#7050)

pkg/api/handlers/mcp/resources_helpers_test.go (28 tests)

Function Tests Security
validateToolName 10 Tool-call authorization (#7495)
classifyComponent 9
parseWarningEventsLimit 11 Input validation

Security coverage added

  • SSE injection prevention — validates newline/CR stripping prevents frame injection
  • Tool-call authorization — validates allowlist enforcement blocks unauthorized MCP tool calls

Related Issues

Fixes #19564


Filed by quality agent (hold-gated mode). Human review required.

…prevention (#7050)

Adds helpers_test.go with tests for:
- indexOf: 10 tests covering found/not-found/edge cases
- replaceAll: 9 tests covering multi-replace and empty inputs
- jsonMarshal: 6 tests covering types, no-trailing-newline, errors
- writeSSEEvent: 9 tests verifying SSE frame injection prevention

Security-relevant: validates that newline/CR stripping in writeSSEEvent
prevents SSE frame injection attacks (issue #7050).

Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 25, 2026 02:44
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 25, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify

netlify Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit 803c98b
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a3c96b51c73520008a7c7da

@clubanderson clubanderson added hold Blocked — do not touch quality testing and removed dco-signoff: yes Indicates the PR's author has signed the DCO. labels Jun 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@github-actions

Copy link
Copy Markdown
Contributor

🐝 Hi @clubanderson! I'm kubestellar-hive[bot], an automation bot for this repo.

Trusted users — org members and contributors with write access — can mention @kubestellar-hive in a comment to trigger repo automation.
On issues, that mention queues an automated fix attempt. On pull requests, it records extra context for existing automation.
This is not an interactive Q&A bot, so mentions should be treated as requests for automation rather than a conversation.

Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies.

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 25, 2026
Tests validateToolName (security #7495), classifyComponent, and
parseWarningEventsLimit — all previously untested pure functions.

Signed-off-by: Copilot <223556219+Copilot@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Jun 25, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds unit tests for the pure helper functions in pkg/api/handlers/gitops/helpers.go, including security-relevant coverage for writeSSEEvent’s newline/CR stripping intended to prevent SSE frame injection (referenced in #7050 / #19564).

Changes:

  • Add table-driven tests for indexOf, replaceAll, and jsonMarshal edge cases.
  • Add security-focused tests for writeSSEEvent formatting and event-name sanitization to prevent SSE injection.

Comment on lines +59 to +70
{"empty old string causes infinite loop guard", "abc", "", "x", "abc"},
{"replace in middle", "foo-bar-baz", "-", "_", "foo_bar_baz"},
{"adjacent replacements", "aabb", "ab", "x", "axb"},
{"whole string is match", "xx", "xx", "y", "y"},
{"empty string input", "", "a", "b", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Skip the empty-old-string case if it would loop
if tt.old == "" {
t.Skip("empty old string edge case - implementation-dependent")
}
Comment on lines +191 to +201
check: func(t *testing.T, output string) {
if indexOf(output, "event: connected\n") == -1 {
t.Errorf("missing event line, got: %q", output)
}
if indexOf(output, "data: ") == -1 {
t.Errorf("missing data line, got: %q", output)
}
// SSE events end with double newline
if output[len(output)-2:] != "\n\n" {
t.Errorf("event should end with \\n\\n, got: %q", output[len(output)-4:])
}
Comment on lines +248 to +255
check: func(t *testing.T, output string) {
dataIdx := indexOf(output, "data: ")
if dataIdx == -1 {
t.Fatal("no data: prefix found")
}
dataStr := output[dataIdx+6:]
dataStr = dataStr[:indexOf(dataStr, "\n")]
var m map[string]interface{}
Comment on lines +205 to +212
name: "newline stripped from event name - SSE injection prevention",
eventName: "evil\nevent",
data: map[string]string{"x": "y"},
check: func(t *testing.T, output string) {
if indexOf(output, "event: evilevent\n") == -1 {
t.Errorf("newline not stripped from event name, got: %q", output)
}
},
@clubanderson clubanderson changed the title [quality] test: add 34 unit tests for gitops SSE helpers — injection prevention (#7050) [quality] test: add 62 unit tests for gitops SSE + MCP security helpers Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. hold Blocked — do not touch quality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. testing tier/1-lightweight

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[quality] pkg/api/handlers/gitops helpers.go lacks tests for SSE injection prevention (#7050)

2 participants