mirror of
https://github.com/gesellix/Bose-SoundTouch.git
synced 2026-08-18 16:46:17 +00:00
Commit history from `7204e619decc48df5dee91d18470934b50e389ac` to `f9b5ad3129831086b02bdf20a197ff4e2d098e2d`: https://github.com/gesellix/Bose-SoundTouch-API/compare/7204e619decc48df5dee91d18470934b50e389ac...f9b5ad3129831086b02bdf20a197ff4e2d098e2d * f9b5ad3 - Tobias Gesellchen, 2026-02-07 : Rename module to gesellix/bose-soundtouch-api and update related files * 5b3dbbb - Tobias Gesellchen, 2026-02-07 : docs: translate PLAN.md to English and fix preferredLanguage typo in marge.go * 696b9c9 - Tobias Gesellchen, 2026-02-07 : feat(discovery): fetch serial number from speaker info if missing in discovery and update datastore tests * 8ed78f0 - Tobias Gesellchen, 2026-02-07 : Consolidate proxy and main service on port 8000 and update related tests and UI * 0e3abbb - Tobias Gesellchen, 2026-02-07 : feat(go): lowercase guessed hostnames for URL consistency * ca1091f - Tobias Gesellchen, 2026-02-07 : feat(health): add health endpoint with VCS build information * a432d53 - Tobias Gesellchen, 2026-02-07 : Rename mock token to soundcork-local-token and add documentation * 3b5ee2f - Tobias Gesellchen, 2026-02-07 : Implement Phase 10: Stats API, Device Event Log, and advanced Marge functions * bc96033 - Tobias Gesellchen, 2026-02-06 : chore * c77864b - Tobias Gesellchen, 2026-02-06 : Document Golang header normalization behavior and ensure generic header casing preservation in proxy * a54e7e7 - Tobias Gesellchen, 2026-02-06 : Ensure ETag header preserves casing (uppercase 'T') for case-sensitive devices * 6265fbe - Tobias Gesellchen, 2026-02-06 : update dockerfile to be in sync with go.mod * 5290bad - Tobias Gesellchen, 2026-02-06 : Implement proxy logging settings UI and complete Phase 8 quick wins (ETags, DataStore initialization) * d7aa7f7 - Tobias Gesellchen, 2026-02-06 : Update PLAN.md with recent features and Phase 8 Upstream Parity tasks * c8ae5e2 - Tobias Gesellchen, 2026-02-06 : Enhance Bose SoundTouch migration with proxying, remote services persistence, and improved diagnostics * c53fa00 - Tobias Gesellchen, 2026-02-06 : Implement remote services persistence check and UI improvements for Bose SoundTouch migration * ea5c348 - Tobias Gesellchen, 2026-02-02 : Ignore soundcork-go/data directory and include recent datastore fixes * d162892 - Tobias Gesellchen, 2026-02-02 : Complete Phase 7: Automated Setup & UI refactoring. Implemented programmatic SSH/migration logic, added device discovery endpoints, created Web UI for speaker management, and refactored UI to use external HTML with Go embed. * b528016 - Tobias Gesellchen, 2026-02-01 : Add GitHub workflow to publish Docker image to GHCR and update Dockerfile * 2ee03da - Tobias Gesellchen, 2026-02-01 : Add GitHub Actions workflow for Go CI and update PLAN.md * 439e2a9 - Tobias Gesellchen, 2026-02-01 : Refactor Go implementation: extract handlers and tests into dedicated files, add comprehensive unit and HTTP tests * c0698fb - Tobias Gesellchen, 2026-02-01 : Add Docker telnet example and update IP consistency in documentation * 028a02e - Tobias Gesellchen, 2026-02-01 : Fix older port number in README * 264829d - Tobias Gesellchen, 2026-02-01 : Add setup-speaker.sh and update documentation to match issue #59 * 64306f9 - Tobias Gesellchen, 2026-02-01 : Implement device presets endpoint in Go * b98a602 - Tobias Gesellchen, 2026-02-01 : Implement Phase 4: Datastore and Marge logic in Go * b6e1bc9 - Tobias Gesellchen, 2026-02-01 : Implement Phase 3: BMX Streaming and Service Registry in Go * f1b3dcf - Tobias Gesellchen, 2026-02-01 : Port core models and constants to Go * 9eae655 - Tobias Gesellchen, 2026-02-01 : Implement static file serving for /media in Go * cc73e50 - Tobias Gesellchen, 2026-02-01 : Fix Go service accessibility and improve Docker configuration * e356bdd - Tobias Gesellchen, 2026-02-01 : Initialize Go migration: Phase 1 infrastructure, proxy-first routing, and root endpoint
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
package proxy
|
|
|
|
import (
|
|
"io"
|
|
"net/http/httptest"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoggingProxy_Redaction(t *testing.T) {
|
|
lp := NewLoggingProxy("http://example.com", true)
|
|
if !lp.Redact {
|
|
t.Error("Expected redact to be true")
|
|
}
|
|
}
|
|
|
|
func TestIsSensitive(t *testing.T) {
|
|
tests := []struct {
|
|
header string
|
|
want bool
|
|
}{
|
|
{"Authorization", true},
|
|
{"authorization", true},
|
|
{"Cookie", true},
|
|
{"X-Bose-Token", true},
|
|
{"Content-Type", false},
|
|
{"Accept", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
if got := isSensitive(tt.header); got != tt.want {
|
|
t.Errorf("isSensitive(%q) = %v, want %v", tt.header, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestShouldLogBody(t *testing.T) {
|
|
tests := []struct {
|
|
contentType string
|
|
want bool
|
|
}{
|
|
{"application/xml", true},
|
|
{"application/json", true},
|
|
{"text/plain", true},
|
|
{"text/html", true},
|
|
{"", true},
|
|
{"audio/mpeg", false},
|
|
{"application/octet-stream", false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
if got := shouldLogBody(tt.contentType); got != tt.want {
|
|
t.Errorf("shouldLogBody(%q) = %v, want %v", tt.contentType, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLoggingProxy_LogRequest(t *testing.T) {
|
|
os.Setenv("LOG_PROXY_BODY", "true")
|
|
defer os.Unsetenv("LOG_PROXY_BODY")
|
|
|
|
lp := NewLoggingProxy("http://example.com", true)
|
|
|
|
body := "test body content"
|
|
req := httptest.NewRequest("POST", "http://example.com/api", strings.NewReader(body))
|
|
req.Header.Set("Content-Type", "text/plain")
|
|
req.Header.Set("Authorization", "bearer secret")
|
|
|
|
lp.LogRequest(req)
|
|
|
|
// Check if body is still readable
|
|
readBody, _ := io.ReadAll(req.Body)
|
|
if string(readBody) != body {
|
|
t.Errorf("Request body was consumed or changed, got %q, want %q", string(readBody), body)
|
|
}
|
|
}
|