Skip to content

Commit

Permalink
fix init and acl 403
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelightning committed Jun 21, 2023
1 parent 8a083bd commit e556165
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 21 deletions.
1 change: 0 additions & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,6 @@ func (a *Agent) Start(ctx context.Context) error {
// Overwrite the configuration.
a.config = c

a.enableDebug = atomic.Bool{}
a.enableDebug.Store(c.EnableDebug)

if err := a.tlsConfigurator.Update(a.config.TLS); err != nil {
Expand Down
2 changes: 0 additions & 2 deletions agent/agent_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"os"
"strconv"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -6009,7 +6008,6 @@ func TestAgent_Monitor(t *testing.T) {
cancelCtx, cancelFunc := context.WithCancel(context.Background())
req = req.WithContext(cancelCtx)

a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

resp := httptest.NewRecorder()
Expand Down
9 changes: 7 additions & 2 deletions agent/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,13 @@ func (s *HTTPHandlers) handler() http.Handler {

wrapper := func(resp http.ResponseWriter, req *http.Request) {

// If enableDebug or ACL enabled, register wrapped pprof handlers
if !s.agent.enableDebug.Load() && s.checkACLDisabled() {
if s.checkACLDisabled() {
resp.WriteHeader(http.StatusForbidden)
return
}

// If enableDebug register wrapped pprof handlers
if !s.agent.enableDebug.Load() {
resp.WriteHeader(http.StatusNotFound)
return
}
Expand Down
3 changes: 0 additions & 3 deletions agent/http_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net/http"
"net/http/httptest"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -145,7 +144,6 @@ func TestHTTPAPI_OptionMethod_OSS(t *testing.T) {
uri := fmt.Sprintf("http://%s%s", a.HTTPAddr(), path)
req, _ := http.NewRequest("OPTIONS", uri, nil)
resp := httptest.NewRecorder()
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req)
allMethods := append([]string{"OPTIONS"}, methods...)
Expand Down Expand Up @@ -193,7 +191,6 @@ func TestHTTPAPI_AllowedNets_OSS(t *testing.T) {
req, _ := http.NewRequest(method, uri, nil)
req.RemoteAddr = "192.168.1.2:5555"
resp := httptest.NewRecorder()
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand Down
11 changes: 0 additions & 11 deletions agent/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"runtime"
"strconv"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -289,7 +288,6 @@ func TestSetupHTTPServer_HTTP2(t *testing.T) {
err = setupHTTPS(httpServer, noopConnState, time.Second)
require.NoError(t, err)

a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

srvHandler := a.srv.handler()
Expand Down Expand Up @@ -487,7 +485,6 @@ func TestHTTPAPI_Ban_Nonprintable_Characters(t *testing.T) {
t.Fatal(err)
}
resp := httptest.NewRecorder()
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand All @@ -513,7 +510,6 @@ func TestHTTPAPI_Allow_Nonprintable_Characters_With_Flag(t *testing.T) {
t.Fatal(err)
}
resp := httptest.NewRecorder()
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand Down Expand Up @@ -655,7 +651,6 @@ func requireHasHeadersSet(t *testing.T, a *TestAgent, path string) {

resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", path, nil)
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand Down Expand Up @@ -719,7 +714,6 @@ func TestAcceptEncodingGzip(t *testing.T) {
// negotiation, but since this call doesn't go through a real
// transport, the header has to be set manually
req.Header["Accept-Encoding"] = []string{"gzip"}
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand All @@ -729,7 +723,6 @@ func TestAcceptEncodingGzip(t *testing.T) {
resp = httptest.NewRecorder()
req, _ = http.NewRequest("GET", "/v1/kv/long", nil)
req.Header["Accept-Encoding"] = []string{"gzip"}
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand Down Expand Up @@ -1087,7 +1080,6 @@ func TestHTTPServer_PProfHandlers_EnableDebug(t *testing.T) {
resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/debug/pprof/profile?seconds=1", nil)

a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)
httpServer := &HTTPHandlers{agent: a.Agent}
httpServer.handler().ServeHTTP(resp, req)
Expand Down Expand Up @@ -1189,7 +1181,6 @@ func TestHTTPServer_PProfHandlers_ACLs(t *testing.T) {
t.Run(fmt.Sprintf("case %d (%#v)", i, c), func(t *testing.T) {
req, _ := http.NewRequest("GET", fmt.Sprintf("%s?token=%s", c.endpoint, c.token), nil)
resp := httptest.NewRecorder()
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand Down Expand Up @@ -1502,7 +1493,6 @@ func TestEnableWebUI(t *testing.T) {

req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder()
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand Down Expand Up @@ -1534,7 +1524,6 @@ func TestEnableWebUI(t *testing.T) {
{
req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder()
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

a.srv.handler().ServeHTTP(resp, req)
Expand Down
1 change: 0 additions & 1 deletion agent/ui_endpoint_oss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestUIEndpoint_MetricsProxy_ACLDeny(t *testing.T) {
`, backendURL))
defer a.Shutdown()

a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

h := a.srv.handler()
Expand Down
1 change: 0 additions & 1 deletion agent/ui_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2620,7 +2620,6 @@ func TestUIEndpoint_MetricsProxy(t *testing.T) {
require.NoError(t, a.Agent.reloadConfigInternal(&cfg))

// Now fetch the API handler to run requests against
a.enableDebug = atomic.Bool{}
a.enableDebug.Store(true)

h := a.srv.handler()
Expand Down

0 comments on commit e556165

Please sign in to comment.