feat(api): report upstream hosts in /api/system

Each registry upstream shows its scheme and host only. The endpoint
drops credentials, paths and query strings from the configured URL.
This commit is contained in:
2026-11-24 00:44:26 +00:00
parent 6ddc382d5b
commit a511544d7a
2 changed files with 35 additions and 0 deletions
+20
View File
@@ -3,6 +3,7 @@ package app
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"testing"
@@ -112,6 +113,25 @@ func TestSystemLeaksNoSecrets(t *testing.T) {
}
}
func TestSystemUpstreamsKeepOnlySchemeAndHost(t *testing.T) {
a := newTestApp(t, func(c *config.Config) {
c.Handlers.NPM.UpstreamRegistry = fmt.Sprintf("https://%s:%[email protected]:8443/private/path?token=abc", "deploy", "s3cret")
c.Handlers.PyPI.UpstreamURL = "not a url"
})
out, body := getJSON(t, a, "/api/system")
if got := jsonAt(out, "upstreams", "npm"); got != "https://npm.example.com:8443" {
t.Errorf("npm upstream = %v", got)
}
if got := jsonAt(out, "upstreams", "pypi"); got != "" {
t.Errorf("unparseable upstream = %v, want empty", got)
}
for _, banned := range []string{"s3cret", "deploy", "private/path", "abc"} {
if strings.Contains(body, banned) {
t.Errorf("/api/system exposes %q: %s", banned, body)
}
}
}
func TestSystemRequiresAuthWhenEnabled(t *testing.T) {
a := newTestApp(t, func(c *config.Config) { c.Auth.Enabled = true })
code, _, _ := doRequest(t, a, "/api/system", nil)