Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package middleware
|
|
|
|
import "testing"
|
|
|
|
func TestSanitizeBody(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
in string
|
|
want string
|
|
}{
|
|
{
|
|
name: "camelCase apiKey",
|
|
in: `{"modelName":"gpt-5.2","apiKey":"sk-secret-123","provider":"azure_openai"}`,
|
|
want: `{"modelName":"gpt-5.2","apiKey":"***","provider":"azure_openai"}`,
|
|
},
|
|
{
|
|
name: "snake_case api_key",
|
|
in: `{"api_key":"sk-secret-123"}`,
|
|
want: `{"api_key":"***"}`,
|
|
},
|
|
{
|
|
name: "PascalCase APIKey",
|
|
in: `{"APIKey":"sk-secret-123"}`,
|
|
want: `{"APIKey":"***"}`,
|
|
},
|
|
{
|
|
name: "secretKey camelCase",
|
|
in: `{"secretKey":"abc","accessKeyId":"id"}`,
|
|
want: `{"secretKey":"***","accessKeyId":"id"}`,
|
|
},
|
|
{
|
|
name: "refreshToken / accessToken camelCase",
|
|
in: `{"refreshToken":"rt","accessToken":"at"}`,
|
|
want: `{"refreshToken":"***","accessToken":"***"}`,
|
|
},
|
|
{
|
|
name: "password and token preserved as masked",
|
|
in: `{"password":"p","token":"t"}`,
|
|
want: `{"password":"***","token":"***"}`,
|
|
},
|
|
{
|
|
name: "snake_case new_password and old_password",
|
|
in: `{"email":"alice@example.com","new_password":"FreshPass9","old_password":"OldPass9"}`,
|
|
want: `{"email":"alice@example.com","new_password":"***","old_password":"***"}`,
|
|
},
|
|
{
|
|
name: "extra whitespace around colon",
|
|
in: `{"apiKey" : "leak"}`,
|
|
want: `{"apiKey":"***"}`,
|
|
},
|
|
{
|
|
name: "non sensitive fields untouched",
|
|
in: `{"baseUrl":"https://example.com","modelName":"gpt"}`,
|
|
want: `{"baseUrl":"https://example.com","modelName":"gpt"}`,
|
|
},
|
|
{
|
|
name: "OAuth authorization response fields",
|
|
in: `{"authorization_url":"https://idp.example/authorize?state=secret","authorization_attempt":"secret-state"}`,
|
|
want: `{"authorization_url":"***","authorization_attempt":"***"}`,
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := sanitizeBody(tc.in)
|
|
if got != tc.want {
|
|
t.Errorf("sanitizeBody(%q)\n got: %s\nwant: %s", tc.in, got, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSanitizeQuery(t *testing.T) {
|
|
got := sanitizeQuery("code=secret-code&state=secret-state&next=%2Fsettings&state=second")
|
|
want := "code=%2A%2A%2A&next=%2Fsettings&state=%2A%2A%2A"
|
|
if got != want {
|
|
t.Fatalf("sanitizeQuery() = %q, want %q", got, want)
|
|
}
|
|
}
|