MCPcopy Create free account
hub / github.com/prometheus/common / TestBasicAuthSecretManager

Function TestBasicAuthSecretManager

config/http_config_test.go:949–970  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

947}
948
949func TestBasicAuthSecretManager(t *testing.T) {
950 cfg, _, err := LoadHTTPConfigFile("testdata/http.conf.basic-auth.ref.yaml")
951 require.NoErrorf(t, err, "Error loading HTTP client config: %v", err)
952 manager := secretManager{
953 data: map[string]string{
954 "admin": "user",
955 "pass": "foobar",
956 },
957 }
958 client, err := NewClientFromConfig(*cfg, "test", WithSecretManager(&manager))
959 require.NoErrorf(t, err, "Error creating HTTP Client: %v", err)
960
961 rt, ok := client.Transport.(*basicAuthRoundTripper)
962 require.Truef(t, ok, "Error casting to basic auth transport, %v", client.Transport)
963
964 if username, _ := rt.username.Fetch(context.Background()); username != "user" {
965 t.Errorf("Bad HTTP client username: %s", username)
966 }
967 if password, _ := rt.password.Fetch(context.Background()); password != "foobar" {
968 t.Errorf("Bad HTTP client password: %s", password)
969 }
970}
971
972func TestBasicAuthSecretManagerNotFound(t *testing.T) {
973 cfg, _, err := LoadHTTPConfigFile("testdata/http.conf.basic-auth.ref.yaml")

Callers

nothing calls this directly

Calls 4

LoadHTTPConfigFileFunction · 0.85
NewClientFromConfigFunction · 0.85
WithSecretManagerFunction · 0.85
FetchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…