All checks were successful
Check / check (pull_request) Successful in 3m22s
Bump golangci-lint from v2.10.1 to v2.12.2 in the Dockerfile lint stage (tag+digest pin) and script/bootstrap release-archive pins (linux amd64/arm64 sha256s). Replace .golangci.yml with the canonical v2-layout config so linter settings (lll 88, funlen 80/50, cyclop 15, dupl 100) actually apply. Fix all findings surfaced by the new linter and config: - noctx: use httptest.NewRequestWithContext in all tests - gosec G710/G703: route app redirects through a path-escaping redirectToApp helper; annotate internal log path usage - goconst: introduce shared constants for template/JSON keys and repeated test literals - lll: wrap lines to the 88-column limit - dupl: extract shared helpers (generic findAllByAppID in models, deleteAppResource in handlers, parsePush in webhook payloads, table-driven/helper-based test dedup) - nolintlint: drop nolint directives made obsolete by the new limits Record the change in TODO.md; make check is green.
85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
package handlers_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"sneak.berlin/go/upaas/internal/handlers"
|
|
)
|
|
|
|
func TestSanitizeLogs(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "plain text unchanged",
|
|
input: "hello world\n",
|
|
expected: "hello world\n",
|
|
},
|
|
{
|
|
name: "strips ANSI color codes",
|
|
input: "\x1b[31mERROR\x1b[0m: something failed\n",
|
|
expected: "ERROR: something failed\n",
|
|
},
|
|
{
|
|
name: "strips OSC sequences",
|
|
input: "\x1b]0;window title\x07normal text\n",
|
|
expected: "normal text\n",
|
|
},
|
|
{
|
|
name: "strips null bytes",
|
|
input: "hello\x00world\n",
|
|
expected: "helloworld\n",
|
|
},
|
|
{
|
|
name: "strips bell characters",
|
|
input: "alert\x07here\n",
|
|
expected: "alerthere\n",
|
|
},
|
|
{
|
|
name: "preserves tabs",
|
|
input: "field1\tfield2\tfield3\n",
|
|
expected: "field1\tfield2\tfield3\n",
|
|
},
|
|
{
|
|
name: "preserves carriage returns",
|
|
input: "line1\r\nline2\r\n",
|
|
expected: "line1\r\nline2\r\n",
|
|
},
|
|
{
|
|
name: "strips mixed escape sequences",
|
|
input: "\x1b[32m2024-01-01\x1b[0m \x1b[1mINFO\x1b[0m starting\x00\n",
|
|
expected: "2024-01-01 INFO starting\n",
|
|
},
|
|
{
|
|
name: "empty string",
|
|
input: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "only control characters",
|
|
input: "\x00\x01\x02\x03",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "cursor movement sequences stripped",
|
|
input: "\x1b[2J\x1b[H\x1b[3Atext\n",
|
|
expected: "text\n",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got := handlers.SanitizeLogs(tt.input)
|
|
if got != tt.expected {
|
|
t.Errorf("SanitizeLogs(%q) = %q, want %q", tt.input, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|