grafana/pkg/api/http_server_test.go
Marcus Efraimsson 9eb2cd537d
Plugins: Make backend plugin metrics endpoints available with optional authentication (#46467)
* add new endpoint without auth+config

* add cfg check

* fit lint issue

* Add basic auth support

Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>

* WIP docs

* Update docs/sources/administration/view-server/internal-metrics.md

Co-authored-by: Dave Henderson <dhenderson@gmail.com>

* update instructions

Co-authored-by: Will Browne <will.browne@grafana.com>
Co-authored-by: Will Browne <wbrowne@users.noreply.github.com>
Co-authored-by: Dave Henderson <dhenderson@gmail.com>
2022-03-29 11:18:26 +02:00

29 lines
616 B
Go

package api
import (
"testing"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/assert"
)
func TestHTTPServer_MetricsBasicAuth(t *testing.T) {
ts := &HTTPServer{
Cfg: setting.NewCfg(),
}
t.Run("enabled", func(t *testing.T) {
ts.Cfg.MetricsEndpointBasicAuthUsername = "foo"
ts.Cfg.MetricsEndpointBasicAuthPassword = "bar"
assert.True(t, ts.metricsEndpointBasicAuthEnabled())
})
t.Run("disabled", func(t *testing.T) {
ts.Cfg.MetricsEndpointBasicAuthUsername = ""
ts.Cfg.MetricsEndpointBasicAuthPassword = ""
assert.False(t, ts.metricsEndpointBasicAuthEnabled())
})
}