2018-11-19 12:15:18 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2022-03-29 04:18:26 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-11-19 12:15:18 -06:00
|
|
|
)
|
|
|
|
|
2020-08-14 07:43:25 -05:00
|
|
|
func TestHTTPServer_MetricsBasicAuth(t *testing.T) {
|
|
|
|
ts := &HTTPServer{
|
|
|
|
Cfg: setting.NewCfg(),
|
|
|
|
}
|
2018-11-19 12:15:18 -06:00
|
|
|
|
2020-08-14 07:43:25 -05:00
|
|
|
t.Run("enabled", func(t *testing.T) {
|
|
|
|
ts.Cfg.MetricsEndpointBasicAuthUsername = "foo"
|
|
|
|
ts.Cfg.MetricsEndpointBasicAuthPassword = "bar"
|
2018-11-19 12:15:18 -06:00
|
|
|
|
2020-08-14 07:43:25 -05:00
|
|
|
assert.True(t, ts.metricsEndpointBasicAuthEnabled())
|
|
|
|
})
|
2018-11-19 12:15:18 -06:00
|
|
|
|
2020-08-14 07:43:25 -05:00
|
|
|
t.Run("disabled", func(t *testing.T) {
|
|
|
|
ts.Cfg.MetricsEndpointBasicAuthUsername = ""
|
|
|
|
ts.Cfg.MetricsEndpointBasicAuthPassword = ""
|
2018-11-19 12:15:18 -06:00
|
|
|
|
2020-08-14 07:43:25 -05:00
|
|
|
assert.False(t, ts.metricsEndpointBasicAuthEnabled())
|
2018-11-19 12:15:18 -06:00
|
|
|
})
|
|
|
|
}
|