mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 08:36:13 +00:00
fix(ci): gate http-client tests on mock readiness; address semgrep findings (refs #451)
The integration suite flaked in CI: with three `go run` mocks now compiling concurrently, the spotify/amazon mocks weren't listening within the fixed `sleep 10`, so the registration requests at the start of the suite hit a connection-refused and the "Account exists" assertions (and the cascading amazon oauth token test) failed. Locally it passed because the mock builds were warm. Replace the fixed sleep with real readiness gating: - Add a /healthz endpoint to the spotify, amazon and tunein mocks. - Give all four CI services (the three mocks + soundtouch-service) a compose healthcheck (busybox wget; all images are alpine-based), and make the service depend_on the mocks being service_healthy. - `docker compose up -d --build --wait` blocks until everything is healthy, so the JetBrains client only runs against a fully-ready stack. Also clear the two semgrep advisories on the new TuneIn mock: - cmd/mock-*: annotate the intentional plaintext ListenAndServe with nosemgrep (throwaway loopback/CI test servers, never production). - pkg/testutils/tunein: sanitize the query-supplied guide id to a safe charset before interpolating it into the JSON/XML response (raw-html-format). make test-http-client: 73 requests, 0 failed (clean testdata, healthcheck-gated). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
2c2bb54eff
commit
9bfe2a1a08
@@ -17,6 +17,9 @@ func NewAmazonHandler() http.Handler {
|
||||
// LWA User Profile Endpoint
|
||||
mux.HandleFunc("/user/profile", HandleProfile)
|
||||
|
||||
// Readiness probe (used by the CI compose healthcheck)
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,9 @@ func NewSpotifyHandler() http.Handler {
|
||||
mux.HandleFunc("/v1/me", HandleMe)
|
||||
mux.HandleFunc("/me", HandleMe)
|
||||
|
||||
// Readiness probe (used by the CI compose healthcheck)
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })
|
||||
|
||||
return mux
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,25 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
// unsafeGuideIDChars matches anything outside the TuneIn guide-id charset
|
||||
// (e.g. s166521, p290778, t472593281). Stripping them before the id is
|
||||
// interpolated into the JSON/XML response keeps a caller from injecting markup
|
||||
// or breaking the document (the input is attacker-controlled query data).
|
||||
var unsafeGuideIDChars = regexp.MustCompile(`[^A-Za-z0-9._-]`)
|
||||
|
||||
func safeGuideID(id string) string {
|
||||
return unsafeGuideIDChars.ReplaceAllString(id, "")
|
||||
}
|
||||
|
||||
// NewTuneInHandler returns an http.Handler configured with the mocked TuneIn
|
||||
// OPML endpoints.
|
||||
func NewTuneInHandler() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) })
|
||||
mux.HandleFunc("/Tune.ashx", HandleTune)
|
||||
mux.HandleFunc("/describe.ashx", HandleDescribe)
|
||||
mux.HandleFunc("/", HandleCatchAll)
|
||||
@@ -43,6 +55,8 @@ func HandleTune(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
id = safeGuideID(id)
|
||||
|
||||
body := fmt.Sprintf(`{"head":{"status":"200"},"body":[`+
|
||||
`{"url":"http://192.0.2.20:8000/%s/stream-1.mp3","media_type":"mp3","reliability":99,"bitrate":128,"is_direct":true},`+
|
||||
`{"url":"http://192.0.2.20:8000/%s/stream-2.mp3","media_type":"mp3","reliability":95,"bitrate":128,"is_direct":true}`+
|
||||
@@ -64,6 +78,8 @@ func HandleDescribe(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
id = safeGuideID(id)
|
||||
|
||||
body := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>`+
|
||||
`<opml version="1">`+
|
||||
`<head><title>%s</title><status>200</status></head>`+
|
||||
|
||||
Reference in New Issue
Block a user