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

Function TestBasicAuthSecretManagerNotFound

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

Source from the content-addressed store, hash-verified

970}
971
972func TestBasicAuthSecretManagerNotFound(t *testing.T) {
973 cfg, _, err := LoadHTTPConfigFile("testdata/http.conf.basic-auth.ref.yaml")
974 require.NoErrorf(t, err, "Error loading HTTP client config: %v", err)
975 manager := secretManager{
976 data: map[string]string{
977 "admin1": "user",
978 "foobar": "pass",
979 },
980 }
981 client, err := NewClientFromConfig(*cfg, "test", WithSecretManager(&manager))
982 require.NoErrorf(t, err, "Error creating HTTP Client: %v", err)
983
984 rt, ok := client.Transport.(*basicAuthRoundTripper)
985 require.Truef(t, ok, "Error casting to basic auth transport, %v", client.Transport)
986
987 if _, err := rt.username.Fetch(context.Background()); !strings.Contains(err.Error(), "unknown secret admin") {
988 t.Errorf("Unexpected error message: %s", err)
989 }
990 if _, err := rt.password.Fetch(context.Background()); !strings.Contains(err.Error(), "unknown secret pass") {
991 t.Errorf("Unexpected error message: %s", err)
992 }
993}
994
995func TestBasicUsernameFile(t *testing.T) {
996 cfg, _, err := LoadHTTPConfigFile("testdata/http.conf.basic-auth.username-file.good.yaml")

Callers

nothing calls this directly

Calls 5

LoadHTTPConfigFileFunction · 0.85
NewClientFromConfigFunction · 0.85
WithSecretManagerFunction · 0.85
ErrorMethod · 0.80
FetchMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…