2018-11-19 12:15:18 -06:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-29 04:18:26 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-01-30 02:18:26 -06:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
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
|
|
|
})
|
|
|
|
}
|
2024-03-22 10:13:22 -05:00
|
|
|
|
|
|
|
func TestHTTPServer_readCertificates(t *testing.T) {
|
|
|
|
ts := &HTTPServer{
|
|
|
|
Cfg: setting.NewCfg(),
|
|
|
|
}
|
|
|
|
t.Run("ReadCertificates should return error when cert files are not configured", func(t *testing.T) {
|
|
|
|
_, err := ts.readCertificates()
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
})
|
|
|
|
}
|