fix(proxy): honour monitoring restriction flag

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 23:51:37 +00:00
parent fd6bc01b87
commit fd88492b00
2 changed files with 6 additions and 6 deletions

View file

@ -49,7 +49,7 @@ func TestProxy_allowHTTP_Bad(t *testing.T) {
}
}
func TestProxy_allowHTTP_MethodRestricted_Bad(t *testing.T) {
func TestProxy_allowHTTP_Unrestricted_Good(t *testing.T) {
p := &Proxy{
config: &Config{
HTTP: HTTPConfig{},
@ -57,11 +57,11 @@ func TestProxy_allowHTTP_MethodRestricted_Bad(t *testing.T) {
}
status, ok := p.allowMonitoringRequest(&http.Request{Method: http.MethodPost})
if ok {
t.Fatal("expected non-GET request to be rejected")
if !ok {
t.Fatalf("expected unrestricted request to pass, got status %d", status)
}
if status != http.StatusMethodNotAllowed {
t.Fatalf("expected status %d, got %d", http.StatusMethodNotAllowed, status)
if status != http.StatusOK {
t.Fatalf("expected status %d, got %d", http.StatusOK, status)
}
}

View file

@ -643,7 +643,7 @@ func (p *Proxy) allowMonitoringRequest(r *http.Request) (int, bool) {
if p == nil {
return http.StatusServiceUnavailable, false
}
if r.Method != http.MethodGet {
if p.config != nil && p.config.HTTP.Restricted && r.Method != http.MethodGet {
return http.StatusMethodNotAllowed, false
}
if token := p.config.HTTP.AccessToken; token != "" {